2013-05-13 15:18:18 +08:00
#!/bin/bash
2016-09-01 16:25:47 +08:00
2013-05-13 15:18:18 +08:00
# exit this script if any commmand fails
set -e
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2021-05-18 16:40:30 +08:00
ADXE_ROOT = " $DIR " /../..
COCOSFILE_PATH = " $ADXE_ROOT /templates/cocos2dx_files.json "
2017-01-19 13:55:14 +08:00
CPU_CORES = 4
2013-05-13 15:18:18 +08:00
2018-10-19 18:10:54 +08:00
function do_retry( )
{
cmd = $@
retry_times = 5
retry_wait = 3
c = 0
while [ $c -lt $(( retry_times+1)) ] ; do
c = $(( c+1))
echo " Executing \" $cmd \", try $c "
$cmd && return $?
if [ ! $c -eq $retry_times ] ; then
echo " Command failed, will retry in $retry_wait secs "
sleep $retry_wait
else
echo "Command failed, giving up."
return 1
fi
done
}
2016-09-01 16:25:47 +08:00
function build_linux( )
{
echo "Building tests ..."
2021-05-15 01:00:20 +08:00
# source ../environment.sh
2021-05-18 16:40:30 +08:00
cd $ADXE_ROOT
2019-11-29 10:02:03 +08:00
set -x
2020-08-24 16:26:12 +08:00
cmake . -G "Unix Makefiles" -Bbuild -DCMAKE_BUILD_TYPE= Release
2020-09-25 11:07:56 +08:00
cmake --build build --target cpp-tests -- -j ` nproc`
2019-11-29 10:02:03 +08:00
set +x
2016-09-01 16:25:47 +08:00
}
2020-09-25 11:07:56 +08:00
function build_osx( )
2018-07-29 23:23:40 +08:00
{
2018-09-25 11:16:04 +08:00
NUM_OF_CORES = ` getconf _NPROCESSORS_ONLN`
2019-11-15 10:24:38 +08:00
2021-05-18 16:40:30 +08:00
# pushd $ADXE_ROOT
# python -u tools/console/bin/adxe.py --agreement n new -l cpp -p my.pack.qqqq cocos_new_test
2018-09-25 11:16:04 +08:00
# popd
2021-05-18 16:40:30 +08:00
# cd $ADXE_ROOT/cocos_new_test
cd $ADXE_ROOT
2020-08-24 16:26:12 +08:00
mkdir -p build
2021-07-09 10:35:57 +08:00
cmake -S . -B build -GXcode -DBUILD_EXTENSION_IMGUIEXT= ON -DBUILD_DEP_ALSOFT= ON
2020-09-21 22:10:50 +08:00
cmake --build build --config Release --target cpp-tests -- -quiet
2021-05-18 16:40:30 +08:00
#xcodebuild -project adxe.xcodeproj -alltargets -jobs $NUM_OF_CORES build | xcpretty
2019-11-29 10:02:03 +08:00
##the following commands must not be removed
2021-05-18 16:40:30 +08:00
#xcodebuild -project adxe.xcodeproj -alltargets -jobs $NUM_OF_CORES build
2018-07-29 23:23:40 +08:00
exit 0
}
2020-09-25 11:07:56 +08:00
function build_ios( )
2018-07-29 23:23:40 +08:00
{
2018-09-25 11:16:04 +08:00
NUM_OF_CORES = ` getconf _NPROCESSORS_ONLN`
2021-05-18 16:40:30 +08:00
# pushd $ADXE_ROOT
# python -u tools/console/bin/adxe.py --agreement n new -l cpp -p my.pack.qqqq cocos_new_test
2018-09-25 11:16:04 +08:00
# popd
2021-05-18 16:40:30 +08:00
# cd $ADXE_ROOT/cocos_new_test
cd $ADXE_ROOT
2020-08-24 16:26:12 +08:00
# mkdir -p build
2021-07-09 10:35:57 +08:00
cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE= cmake/ios.mini.cmake -DCMAKE_OSX_ARCHITECTURES= x86_64 -DBUILD_DEP_ALSOFT= ON
2020-02-07 20:59:22 +08:00
# cmake .. -GXcode -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.toolchain.cmake -DCMAKE_SYSTEM_NAME=iOS -DPLATFORM=OS -DENABLE_ARC=0 # too much logs on console when "cmake --build ."
2020-08-24 16:26:12 +08:00
cmake --build build --config Release --target cpp-tests -- -quiet -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)"
2019-11-29 10:02:03 +08:00
2021-05-18 16:40:30 +08:00
#xcodebuild -project adxe.xcodeproj -alltargets -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty
2019-11-29 10:02:03 +08:00
##the following commands must not be removed
2021-05-18 16:40:30 +08:00
#xcodebuild -project adxe.xcodeproj -alltargets -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build
2018-07-29 23:23:40 +08:00
exit 0
}
2020-09-25 11:07:56 +08:00
function build_android( )
2018-09-17 11:54:39 +08:00
{
# Build all samples
echo "Building Android samples ..."
source ../environment.sh
# build cpp-tests
2021-05-18 16:40:30 +08:00
pushd $ADXE_ROOT /tests/cpp-tests/proj.android
2020-11-09 17:53:23 +08:00
2021-06-05 01:22:33 +08:00
do_retry ./gradlew assembleRelease -PPROP_BUILD_TYPE= cmake -PPROP_APP_ABI= $BUILD_ARCH --parallel --info
2018-09-17 11:54:39 +08:00
popd
}
2020-09-25 11:07:56 +08:00
function build_android_lua( )
2018-09-17 11:54:39 +08:00
{
# Build all samples
echo "Building Android samples lua ..."
source ../environment.sh
# build lua-tests
2021-05-18 16:40:30 +08:00
pushd $ADXE_ROOT /tests/lua-tests/project/proj.android
2020-10-26 11:12:55 +08:00
do_retry ./gradlew assembleDebug -PPROP_BUILD_TYPE= cmake -PPROP_APP_ABI= arm64-v8a --parallel --info
2018-03-15 09:36:27 +08:00
popd
}
2016-09-01 16:25:47 +08:00
function genernate_binding_codes( )
{
2017-12-07 13:34:12 +08:00
if [ $TRAVIS_OS_NAME = = "linux" ] ; then
# print some log for libstdc++6
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBC
ls -l /usr/lib/x86_64-linux-gnu/libstdc++*
dpkg-query -W libstdc++6
2021-05-18 16:40:30 +08:00
ldd $ADXE_ROOT /tools/bindings-generator/libclang/libclang.so
2017-12-07 13:34:12 +08:00
fi
2018-03-15 09:36:27 +08:00
source ../environment.sh
2014-02-11 14:12:13 +08:00
2016-09-01 16:25:47 +08:00
# Generate binding glue codes
echo "Create auto-generated luabinding glue codes."
2021-05-18 16:40:30 +08:00
pushd " $ADXE_ROOT /tools/tolua "
2019-11-25 20:32:43 +08:00
# python ./genbindings.py
2016-09-01 16:25:47 +08:00
popd
}
2018-09-25 11:16:04 +08:00
# generate cocos_files.json and check diff
function update_cocos_files( )
{
# Don't exit on non-zero return value
set +e
echo "Updates cocos_files.json"
2021-05-18 16:40:30 +08:00
$ADXE_ROOT /tools/travis-scripts/generate-template-files.py
2018-09-25 11:16:04 +08:00
git diff FETCH_HEAD --stat --exit-code " $COCOSFILE_PATH "
COCOSFILE_DIFF_RETVAL = $?
2019-05-24 15:00:51 +08:00
echo $COCOSFILE_DIFF_RETVAL
2018-09-25 11:16:04 +08:00
# Exit on error
set -e
}
2016-09-01 16:25:47 +08:00
function generate_pull_request_for_binding_codes_and_cocosfiles( )
{
2021-05-18 16:40:30 +08:00
local COCOS_ROBOT_REMOTE = " https:// ${ GH_USER } : ${ GH_PASSWORD } @github.com/ ${ GH_USER } /adxe.git "
local LUA_AUTO_GENERATE_SCRIPT_PATH = " $ADXE_ROOT /extensions/scripting/lua-bindings/auto "
2019-05-24 15:00:51 +08:00
local ELAPSEDSECS = ` date +%s`
local COCOS_BRANCH = " update_lua_bindings_ $ELAPSEDSECS "
local COMMITTAG = "[ci skip][AUTO]: updating luabinding & cocos_file.json automatically"
local PULL_REQUEST_REPO = "https://api.github.com/repos/cocos2d/cocos2d-x/pulls"
2016-09-01 16:25:47 +08:00
2021-05-18 16:40:30 +08:00
pushd " $ADXE_ROOT "
2016-09-01 16:25:47 +08:00
#Set git user for cocos2d-lua repo
2019-11-25 19:48:31 +08:00
# git config user.email ${GH_EMAIL}
# git config user.name ${GH_USER}#Set remotes
# git remote add upstream "$COCOS_ROBOT_REMOTE" 2> /dev/null > /dev/null
2016-09-01 16:25:47 +08:00
# Run status to record the output in the log
git status
echo
echo Comparing with origin HEAD ...
echo
git fetch origin " $TRAVIS_BRANCH "
# Don't exit on non-zero return value
set +e
git diff FETCH_HEAD --stat --exit-code " $LUA_AUTO_GENERATE_SCRIPT_PATH "
2019-05-24 15:00:51 +08:00
local lua_binding_codes_diff = $?
2016-09-01 16:25:47 +08:00
# generate cocos_files.json and check diff
2019-05-24 15:00:51 +08:00
local cocos_file_diff = $( update_cocos_files)
if [ $lua_binding_codes_diff -eq 0 ] && [ $cocos_file_diff -eq 0 ] ; then
echo "lua binding codes and cocos file are not differences"
exit 0
fi
2016-09-01 16:25:47 +08:00
# Exit on error
set -e
2019-11-25 19:48:31 +08:00
# git add -f --all "$LUA_AUTO_GENERATE_SCRIPT_PATH"
# git add -f --all "$COCOSFILE_PATH"
# git checkout -b "$COCOS_BRANCH"
# git commit -m "$COMMITTAG"
2016-09-01 16:25:47 +08:00
echo "Pushing to Robot's repo ..."
2019-11-25 19:48:31 +08:00
# git fetch --unshallow origin
# git push -f upstream "$COCOS_BRANCH"
2016-09-01 16:25:47 +08:00
echo "Sending Pull Request to base repo ..."
2019-11-25 19:48:31 +08:00
# curl --user "${GH_USER}:${GH_PASSWORD}" --request POST --data "{ \"title\": \"$COMMITTAG\", \"body\": \"\", \"head\": \"${GH_USER}:${COCOS_BRANCH}\", \"base\": \"${TRAVIS_BRANCH}\"}" "${PULL_REQUEST_REPO}" 2> /dev/null > /dev/null
2016-09-01 16:25:47 +08:00
popd
}
2021-07-09 10:35:57 +08:00
function run_build( )
2016-09-01 16:25:47 +08:00
{
2021-07-09 10:35:57 +08:00
echo "Building..."
2017-12-07 13:34:12 +08:00
2019-03-25 10:08:49 +08:00
if [ " $BUILD_TARGET " = = "android_cocos_new_test" ] ; then
source ../environment.sh
2021-05-18 16:40:30 +08:00
pushd $ADXE_ROOT
2019-03-25 10:08:49 +08:00
update_cocos_files
2021-05-18 16:40:30 +08:00
python -u tools/console/bin/adxe.py --agreement n new -l cpp -p my.pack.qqqq cocos_new_test
2019-03-25 10:08:49 +08:00
popd
2021-05-18 16:40:30 +08:00
pushd $ADXE_ROOT /cocos_new_test/proj.android
2019-03-25 10:08:49 +08:00
do_retry ./gradlew build
popd
exit 0
fi
if [ " $BUILD_TARGET " = = "linux_cocos_new_test" ] ; then
2021-05-18 16:40:30 +08:00
export PATH = $PATH :$ADXE_ROOT /tools/console/bin
2019-03-25 10:08:49 +08:00
genernate_binding_codes
2021-05-18 16:40:30 +08:00
pushd $ADXE_ROOT
2019-03-25 10:08:49 +08:00
update_cocos_files
2021-05-18 16:40:30 +08:00
python -u tools/console/bin/adxe.py --agreement n new -l lua -p my.pack.qqqq cocos_new_test
2019-03-25 10:08:49 +08:00
popd
echo "Building tests ..."
2019-11-29 10:02:03 +08:00
set -x
2021-05-18 16:40:30 +08:00
cd $ADXE_ROOT /cocos_new_test
2019-03-25 10:08:49 +08:00
mkdir -p linux-build
cd linux-build
2019-11-29 10:02:03 +08:00
cmake .. -G"Unix Makefiles"
cmake --build . -- -j ` nproc`
exit 0
fi
if [ " $BUILD_TARGET " = = "ios_cocos_new_lua_test" ] ; then
2021-05-18 16:40:30 +08:00
export PATH = $PATH :$ADXE_ROOT /tools/console/bin
2019-11-29 10:02:03 +08:00
#NUM_OF_CORES=`getconf _NPROCESSORS_ONLN`
genernate_binding_codes
2021-05-18 16:40:30 +08:00
pushd $ADXE_ROOT
2019-11-29 10:02:03 +08:00
echo "Creating tests ..."
set -x
cocos --agreement n new -l lua ios_new_lua_proj
cd ios_new_lua_proj
mkdir build
cd build
cmake .. -GXcode -DCMAKE_SYSTEM_NAME= iOS -DCMAKE_OSX_SYSROOT= iphonesimulator
cmake --build . --config Release -- -quiet
popd
exit 0
fi
if [ " $BUILD_TARGET " = = "ios_cocos_new_cpp_test" ] ; then
2021-05-18 16:40:30 +08:00
export PATH = $PATH :$ADXE_ROOT /tools/console/bin
2019-11-29 10:02:03 +08:00
#NUM_OF_CORES=`getconf _NPROCESSORS_ONLN`
genernate_binding_codes
2021-05-18 16:40:30 +08:00
pushd $ADXE_ROOT
2019-11-29 10:02:03 +08:00
echo "Creating tests ..."
set -x
cocos --agreement n new -l cpp ios_new_cpp_proj
cd ios_new_cpp_proj
mkdir build
cd build
echo "Building tests ..."
cmake .. -GXcode -DCMAKE_SYSTEM_NAME= iOS -DCMAKE_OSX_SYSROOT= iphonesimulator
cmake --build . --config Release -- -quiet
popd
2019-03-25 10:08:49 +08:00
exit 0
fi
2020-09-25 11:07:56 +08:00
if [ $BUILD_TARGET = = 'osx' ] ; then
# genernate_binding_codes
2019-11-29 10:02:03 +08:00
set -x
2020-09-25 11:07:56 +08:00
build_osx
2019-03-25 10:08:49 +08:00
exit 0
fi
2020-09-25 11:07:56 +08:00
if [ $BUILD_TARGET = = 'ios' ] ; then
# genernate_binding_codes
2019-11-29 10:02:03 +08:00
set -x
2020-09-25 11:07:56 +08:00
build_ios
2019-03-25 10:08:49 +08:00
exit 0
fi
2016-09-01 16:25:47 +08:00
# linux
if [ $BUILD_TARGET = = 'linux' ] ; then
2020-09-25 11:07:56 +08:00
# genernate_binding_codes
2016-09-01 16:25:47 +08:00
build_linux
2014-03-10 18:13:39 +08:00
fi
2016-09-01 16:25:47 +08:00
2018-09-17 11:54:39 +08:00
# android
2020-09-25 11:07:56 +08:00
if [ $BUILD_TARGET = = 'android' ] ; then
build_android
2018-09-17 11:54:39 +08:00
fi
2018-03-15 09:36:27 +08:00
# android_lua
2020-09-25 11:07:56 +08:00
if [ $BUILD_TARGET = = 'android_lua' ] ; then
2019-03-25 10:08:49 +08:00
genernate_binding_codes
2020-09-25 11:07:56 +08:00
build_android_lua
2018-03-15 09:36:27 +08:00
fi
2016-09-01 16:25:47 +08:00
}
function run_after_merge( )
{
2017-12-07 13:34:12 +08:00
echo "Building merge commit ..."
2016-09-01 16:25:47 +08:00
# Re-generation of the javascript bindings can perform push of the new
# version back to github. We don't do this for pull requests, or if
# GH_USER/GH_EMAIL/GH_PASSWORD environment variables are not set correctly
# by the encoded variables in the .travis.yml file. (e.g. if cloned repo's
# want to use travis).
2019-11-25 19:48:31 +08:00
# if [ -z "${GH_EMAIL}" ]; then
# echo "GH_EMAIL not set"
# exit 1
# fi
# if [ -z "${GH_USER}" ]; then
# echo "GH_USER not set"
# exit 1
# fi
# if [ -z "${GH_PASSWORD}" ]; then
# echo "GH_USER not set"
# exit 1
# fi
2014-02-13 11:33:11 +08:00
2016-09-01 16:25:47 +08:00
genernate_binding_codes
generate_pull_request_for_binding_codes_and_cocosfiles
}
2013-06-25 01:41:48 +08:00
2021-07-09 10:35:57 +08:00
run_build
2016-09-01 16:25:47 +08:00
# build pull request
2021-07-09 10:35:57 +08:00
# if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
# run_pull_request
# fi
2014-05-12 21:55:11 +08:00
2016-09-01 16:25:47 +08:00
# run after merging
# - make cocos robot to send PR to cocos2d-x for new binding codes
# - generate cocos_files.json for template
2021-07-09 10:35:57 +08:00
# if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
# # only one job need to send PR, linux virtual machine has better performance
# if [ $TRAVIS_OS_NAME == "linux" ] && [ x$GEN_BINDING_AND_COCOSFILE == x"true" ]; then
# run_after_merge
# fi
# fi