diff --git a/.travis.yml b/.travis.yml index 60d4bc1562..9915beddd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,37 +1,22 @@ language: cpp script: - - if [ $PLATFORM = android ]; then export NDK_ROOT=$PWD/android-ndk; fi - - if [ $PLATFORM = android ]; then cd samples/$SAMPLE_LANG/$APPNAME/proj.android; fi - - if [ $PLATFORM = android ]; then ./build_native.sh; fi - - if [ $PLATFORM != android ]; then export NACL_SDK_ROOT=$PWD/nacl_sdk/pepper_canary; fi - - if [ $PLATFORM != android ]; then export PATH=$PATH:$NACL_SDK_ROOT/toolchain/linux_x86_newlib/bin; fi - - if [ $PLATFORM != android ]; then make -j4; fi + - export NACL_SDK_ROOT=$HOME/bin/nacl_sdk/pepper_canary + - export PATH=$PATH:$NACL_SDK_ROOT/toolchain/linux_x86_newlib/bin + - export NDK_ROOT=$HOME/bin/android-ndk + - ./tools/travis-scripts/run-script.sh before_install: - - if [ $PLATFORM = linux ]; then ./install-deps-linux.sh; fi - - if [ $PLATFORM = nacl ]; then sudo apt-get update; fi - - if [ $PLATFORM = nacl ]; then sudo apt-get install libc6:i386; fi - - if [ $PLATFORM = nacl ]; then wget http://storage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk/nacl_sdk.zip; fi - - if [ $PLATFORM = nacl ]; then unzip nacl_sdk.zip; fi - - if [ $PLATFORM = nacl ]; then nacl_sdk/naclsdk update --force pepper_canary; fi - - if [ $PLATFORM = android ]; then curl -O http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2; fi - - if [ $PLATFORM = android ]; then tar xjf android-ndk-r8e-linux-x86_64.tar.bz2; fi - - if [ $PLATFORM = android ]; then mv android-ndk-r8e android-ndk; fi + - ./tools/travis-scripts/before-install.sh env: - - PLATFORM=nacl DEBUG=1 - - PLATFORM=nacl DEBUG=0 - - PLATFORM=linux DEBUG=1 - - PLATFORM=linux DEBUG=0 - - PLATFORM=android SAMPLE_LANG=Cpp APPNAME=HelloCpp - - PLATFORM=android SAMPLE_LANG=Cpp APPNAME=TestCpp - - PLATFORM=android SAMPLE_LANG=Cpp APPNAME=SimpleGame - - PLATFORM=android SAMPLE_LANG=Cpp APPNAME=AssetsManagerTest - - PLATFORM=android SAMPLE_LANG=Javascript APPNAME=CocosDragonJS - - PLATFORM=android SAMPLE_LANG=Javascript APPNAME=CrystalCraze - - PLATFORM=android SAMPLE_LANG=Javascript APPNAME=MoonWarriors - - PLATFORM=android SAMPLE_LANG=Javascript APPNAME=TestJavascript - - PLATFORM=android SAMPLE_LANG=Javascript APPNAME=WatermelonWithMe - - PLATFORM=android SAMPLE_LANG=Lua APPNAME=HelloLua - - PLATFORM=android SAMPLE_LANG=Lua APPNAME=TestLua + global: + - secure: "XvKfZu6ePLYH6nWwF6YrDMQLCfABOtyzac0JDwgYr7m1f5WH1nYQ7Hgv+pjq\nnJs+A5wdXJ6f6jRvgrgQ1T9UvY0ckR9HIXYmGtg2bd+IjJmDh0gwZMz+OFq4\nQ+Wsj9wxu9LsEAt/CosQvk3r2AoMpIY98a864b0EquZH+zzdzgA=" + - secure: "iEFKwSz4IlQ9EfAL8c/1MwU6Ti1IrNtG0YUi3TWdf6sCMglXaRICSJTCY9Hz\nXLYYvp5lPo5FQsqxpMBhkm2Zpitd4zZq+r62P9e2b4P9svAxapOQdYRh9Cjc\nN3eUyQTslMVPE9zsWIJmQbIlDk18X246Izo353UI7mmJ8WRAoNE=" + matrix: + # - GEN_JSB=YES + - PLATFORM=linux DEBUG=1 + - PLATFORM=nacl DEBUG=1 + - PLATFORM=android SAMPLE_LANG=Cpp APPNAME=HelloCpp + - PLATFORM=android SAMPLE_LANG=Javascript APPNAME=TestJavascript + - PLATFORM=android SAMPLE_LANG=Lua APPNAME=TestLua branches: only: - master diff --git a/tools/travis-scripts/before-install.sh b/tools/travis-scripts/before-install.sh new file mode 100755 index 0000000000..cdec1fcf84 --- /dev/null +++ b/tools/travis-scripts/before-install.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# exit this script if any commmand fails +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +COCOS2DX_ROOT="$DIR"/../.. + +mkdir -p $HOME/bin +pushd $HOME/bin + + +install_android_ndk() +{ + # Download android ndk + echo "Download android ndk ..." + curl -O http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2 + echo "Decompress android-ndk-r8e-linux-x86_64.tar.bz2 ..." + tar xjf android-ndk-r8e-linux-x86_64.tar.bz2 + # Rename ndk + mv android-ndk-r8e android-ndk +} + +if [ "$GEN_JSB"x = "YES"x ]; then + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + exit 0 + fi + install_android_ndk + # Download llvm3.1 + echo "Download llvm3.1 ..." + curl -O http://llvm.org/releases/3.1/clang+llvm-3.1-x86_64-linux-ubuntu_12.04.tar.gz + echo "Decompress android-ndk-r8e-linux-x86_64.tar.bz2 ..." + tar xzf clang+llvm-3.1-x86_64-linux-ubuntu_12.04.tar.gz + # Rename llvm + mv clang+llvm-3.1-x86_64-linux-ubuntu_12.04 clang+llvm-3.1 +fi + +if [ "$PLATFORM"x = "linux"x ]; then + bash $COCOS2DX_ROOT/install-deps-linux.sh +fi + +if [ "$PLATFORM"x = "nacl"x ]; then + sudo apt-get update + sudo apt-get install libc6:i386 + echo "Download nacl_sdk ..." + wget http://storage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk/nacl_sdk.zip + echo "Decompress nacl_sdk.zip" + unzip nacl_sdk.zip + nacl_sdk/naclsdk update --force pepper_canary +fi + +if [ "$PLATFORM"x = "android"x ]; then + install_android_ndk +fi + + + +popd diff --git a/tools/travis-scripts/generate-jsbindings.sh b/tools/travis-scripts/generate-jsbindings.sh new file mode 100755 index 0000000000..88afac162d --- /dev/null +++ b/tools/travis-scripts/generate-jsbindings.sh @@ -0,0 +1,198 @@ +#!/bin/bash + +# Generate JS bindings for Cocos2D-X +# ... using Android NDK system headers +# ... and automatically update submodule references +# ... and push these changes to remote repos + +# Dependencies +# +# For bindings generator: +# (see ../../../tojs/genbindings.sh +# ... for the defaults used if the environment is not customized) +# +# * $PYTHON_BIN +# * $CLANG_ROOT +# * $NDK_ROOT +# +# For automatically pushing changes: +# +# * REMOTE_AUTOGEN_BINDINGS_REPOSITORY +# * REMOTE_COCOS2DX_REPOSITORY +# * Note : Ensure you have commit access to above repositories +# * COCOS2DX_PULL_BASE +# * hub +# * see http://defunkt.io/hub/ +# * Ensure that hub has an OAuth token to REMOTE_COCOS2DX_REPOSITORY +# * see http://defunkt.io/hub/hub.1.html#CONFIGURATION + +#Set git user +git config --global user.email "CocosRobot@gmail.com" +git config --global user.name "CocosRobot" + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +COCOS2DX_ROOT="$DIR"/../.. +TOJS_ROOT=$COCOS2DX_ROOT/tools/tojs +GENERATED_WORKTREE="$COCOS2DX_ROOT"/scripting/javascript/bindings/generated +REMOTE_AUTOGEN_BINDINGS_REPOSITORY="https://github.com/angeltown/cocos2dx-autogen-bindings.git" +REMOTE_COCOS2DX_REPOSITORY="https://github.com/angeltown/cocos2d-x.git" +COCOS2DX_PULL_BASE="dumganhar/cocos2d-x:travis" + +sudo apt-get --force-yes --yes install python-yaml python-cheetah + +# Update cocos2d-x repo +# It needs to be updated in Jenkins command before executing this script. +#pushd "$COCOS2DX_ROOT" + +#git checkout -f +#git checkout gles20 +#git pull upstream gles20 +#rm -rf "$GENERATED_WORKTREE" +#git submodule update --init + +#popd + +# Update submodule of auto-gen JSBinding repo. +pushd "$GENERATED_WORKTREE" + +git checkout -B master +#Set remotes +git remote add upstream https://${GH_TOKEN}@github.com/angeltown/cocos2dx-autogen-bindings.git 2> /dev/null > /dev/null + +echo "Delete all directories and files except '.git' and 'README'." +ls -a | grep -E -v ^\[.\]\{1,2\}$ | grep -E -v ^\.git$ | grep -E -v ^README$ | xargs -I{} rm -rf {} +echo "Show files in scripting/javascript/bindings/generated folder." +ls -a +popd + +# Exit on error +set -e + +# 1. Generate JS bindings +pushd "$TOJS_ROOT" +./genbindings.sh +popd + +echo +echo Bindings generated successfully +echo + +if [ -z "${REMOTE_AUTOGEN_BINDINGS_REPOSITORY+aaa}" ]; then + echo + echo Environment variable must be set REMOTE_AUTOGEN_BINDINGS_REPOSITORY + echo This script expects to automatically push changes + echo to this repo + echo example + echo REMOTE_AUTOGEN_BINDINGS_REPOSITORY=\"git@github.com:folecr/cocos2dx-autogen-bindings.git\" + echo REMOTE_AUTOGEN_BINDINGS_REPOSITORY=\"\$HOME/test/cocos2dx-autogen-bindings\" + echo + echo Exiting with failure. + echo + exit 1 +fi + +if [ -z "${COMMITTAG+aaa}" ]; then +# ... if COMMITTAG is not set, use this machine's hostname + COMMITTAG=`hostname -s` +fi + +echo +echo Using "'$COMMITTAG'" in the commit messages +echo + +ELAPSEDSECS=`date +%s` +echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness + +GENERATED_BRANCH=autogeneratedbindings_"$ELAPSEDSECS" + + +# 2. In JSBindings repo, Check if there are any files that are different from the index + +pushd "$GENERATED_WORKTREE" + +# Run status to record the output in the log +git status + +echo +echo Comparing with HEAD ... +echo + +# Don't exit on non-zero return value +set +e +git diff --stat --exit-code + +DIFF_RETVAL=$? +if [ $DIFF_RETVAL -eq 0 ] +then + echo + echo "No differences in generated files" + echo "Exiting with success." + echo + exit 0 +else + echo + echo "Generated files differ from HEAD. Continuing." + echo +fi + +# Exit on error +set -e + +# 3. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it +git checkout -b "$GENERATED_BRANCH" +git add --verbose . +git add --verbose -u . +git commit --verbose -m "$COMMITTAG : autogenerated bindings" + +# 4. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository +git push -fq upstream "$GENERATED_BRANCH":master 2> /dev/null + +popd + +if [ -z "${REMOTE_COCOS2DX_REPOSITORY+aaa}" ]; then + echo + echo Environment variable is not set REMOTE_COCOS2DX_REPOSITORY + echo This script will NOT automatically push changes + echo unless this variable is set. + echo example + echo REMOTE_COCOS2DX_REPOSITORY=\"git@github.com:cocos2d/cocos2d-x.git\" + echo REMOTE_COCOS2DX_REPOSITORY=\"\$HOME/test/cocos2d-x\" + echo + echo Exiting with success. + echo + exit 0 +fi + +COCOS_BRANCH=updategeneratedsubmodule_"$ELAPSEDSECS" + +pushd "${DIR}" + +# 5. In Cocos2D-X repo, Checkout a branch named "updategeneratedsubmodule" Update the submodule reference to point to the commit with generated bindings +cd "${COCOS2DX_ROOT}" +git add scripting/javascript/bindings/generated +git checkout -b "$COCOS_BRANCH" +git commit -m "$COMMITTAG : updating submodule reference to latest autogenerated bindings" +#Set remotes +git remote add upstream https://${GH_TOKEN}@github.com/angeltown/cocos2d-x.git 2> /dev/null > /dev/null +# 6. In Cocos2D-X repo, Push the commit with updated submodule to "master" of the cocos2d-x repository +git push -fq upstream "$COCOS_BRANCH" 2> /dev/null + +if [ -z "${COCOS2DX_PULL_BASE+aaa}" ]; then + echo + echo Environment variable is not set COCOS2DX_PULL_BASE + echo This script will NOT automatically generate pull requests + echo unless this variable is set. + echo example + echo COCOS2DX_PULL_BASE=\"cocos2d/cocos2d-x:master\" + echo COCOS2DX_PULL_BASE=\"username/repository:branch\" + echo + echo Exiting with success. + echo + exit 0 +fi + +# 7. +curl --user "angeltown:$GH_PASSWORD" --request POST --data "{ \"title\": \"$COMMITTAG : updating submodule reference to latest autogenerated bindings\", \"body\": \"\", \"head\": \"angeltown:${COCOS_BRANCH}\", \"base\": \"travis\"}" https://api.github.com/repos/dumganhar/cocos2d-x/pulls 2> /dev/null > /dev/null +# ${HUB} pull-request "$COMMITTAG : updating submodule reference to latest autogenerated bindings" -b "$COCOS2DX_PULL_BASE" -h "$COCOS_BRANCH" + +popd diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh new file mode 100755 index 0000000000..030a99bbac --- /dev/null +++ b/tools/travis-scripts/run-script.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# exit this script if any commmand fails +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +COCOS2DX_ROOT="$DIR"/../.. + +if [ "$GEN_JSB"x = "YES"x ]; then + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + exit 0 + fi + cd $COCOS2DX_ROOT/tools/travis-scripts + ./generate-jsbindings.sh +fi + +if [ "$PLATFORM"x = "android"x ]; then + cd $COCOS2DX_ROOT/samples/$SAMPLE_LANG/$APPNAME/proj.android + ./build_native.sh +fi + +if [ "$PLATFORM"x = "nacl"x ]; then + cd $COCOS2DX_ROOT + make -j4 +fi + +if [ "$PLATFORM"x = "linux"x ]; then + cd $COCOS2DX_ROOT + make -j4 +fi +