2014-03-10 18:13:39 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Generate Lua bindings for Cocos2D-X
|
|
|
|
# ... using Android NDK system headers
|
|
|
|
# ... and push these changes to remote repos
|
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
#
|
|
|
|
# For bindings generator:
|
|
|
|
# (see tools/tolua/genbindings.py for the defaults used if the environment is not customized)
|
|
|
|
#
|
|
|
|
# * $PYTHON_BIN
|
|
|
|
# * $CLANG_ROOT
|
|
|
|
# * $NDK_ROOT
|
|
|
|
#
|
|
|
|
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
PROJECT_ROOT="$DIR/../.."
|
|
|
|
TOLUA_ROOT="$PROJECT_ROOT/tools/tolua"
|
2015-05-05 11:52:52 +08:00
|
|
|
TOJS_ROOT="$PROJECT_ROOT/tools/tojs"
|
|
|
|
LUA_AUTO_GENERATED_DIR="$PROJECT_ROOT/cocos/scripting/lua-bindings/auto"
|
|
|
|
JS_AUTO_GENERATED_DIR="$PROJECT_ROOT/cocos/scripting/js-bindings/auto"
|
2015-05-29 13:47:28 +08:00
|
|
|
COMMITTAG="[ci skip][AUTO]: updating luabinding & jsbinding automatically"
|
2014-03-10 18:13:39 +08:00
|
|
|
ELAPSEDSECS=`date +%s`
|
|
|
|
COCOS_BRANCH="update_lua_bindings_$ELAPSEDSECS"
|
|
|
|
COCOS_ROBOT_REMOTE="https://${GH_USER}:${GH_PASSWORD}@github.com/${GH_USER}/cocos2d-x.git"
|
|
|
|
PULL_REQUEST_REPO="https://api.github.com/repos/cocos2d/cocos2d-x/pulls"
|
2015-07-25 13:31:52 +08:00
|
|
|
FETCH_REMOTE_BRANCH="v3.7.1"
|
2015-05-05 11:52:52 +08:00
|
|
|
LUA_COMMIT_PATH="cocos/scripting/lua-bindings/auto"
|
|
|
|
JS_COMMIT_PATH="cocos/scripting/js-bindings/auto"
|
2014-03-10 18:13:39 +08:00
|
|
|
|
|
|
|
# Exit on error
|
|
|
|
set -e
|
|
|
|
|
2014-05-12 21:55:11 +08:00
|
|
|
if [ "$PLATFORM"x = "mac-ios"x ]; then
|
2014-03-10 18:13:39 +08:00
|
|
|
mkdir -p $HOME/bin
|
|
|
|
pushd $HOME/bin
|
|
|
|
curl -O http://pyyaml.org/download/pyyaml/PyYAML-3.10.zip
|
|
|
|
unzip PyYAML-3.10.zip 2> /dev/null > /dev/null
|
|
|
|
cd PyYAML-3.10
|
|
|
|
sudo python setup.py install 2> /dev/null > /dev/null
|
|
|
|
cd ..
|
|
|
|
curl -O https://pypi.python.org/packages/source/C/Cheetah/Cheetah-2.4.4.tar.gz
|
|
|
|
tar xzf Cheetah-2.4.4.tar.gz
|
|
|
|
cd Cheetah-2.4.4
|
|
|
|
sudo python setup.py install 2> /dev/null > /dev/null
|
|
|
|
popd
|
|
|
|
elif [ $(command -v apt-get) ]; then
|
|
|
|
sudo apt-get --force-yes --yes install python-yaml python-cheetah
|
|
|
|
fi
|
|
|
|
|
|
|
|
generate_bindings_glue_codes()
|
|
|
|
{
|
|
|
|
echo "Create auto-generated luabinding glue codes."
|
|
|
|
pushd "$TOLUA_ROOT"
|
|
|
|
./genbindings.py
|
|
|
|
popd
|
2015-05-05 11:52:52 +08:00
|
|
|
|
|
|
|
echo "Create auto-generated jsbinding glue codes."
|
|
|
|
pushd "$TOJS_ROOT"
|
|
|
|
./genbindings.py
|
|
|
|
popd
|
2014-03-10 18:13:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$GEN_BINDING"x != "YES"x ]; then
|
|
|
|
generate_bindings_glue_codes
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
pushd "$PROJECT_ROOT"
|
|
|
|
#Set git user for cocos2d-lua repo
|
|
|
|
git config user.email ${GH_EMAIL}
|
|
|
|
git config user.name ${GH_USER}
|
|
|
|
popd
|
|
|
|
|
2015-05-05 11:52:52 +08:00
|
|
|
rm -rf "$LUA_AUTO_GENERATED_DIR"
|
|
|
|
mkdir "$LUA_AUTO_GENERATED_DIR"
|
|
|
|
|
|
|
|
rm -rf "$JS_AUTO_GENERATED_DIR"
|
|
|
|
mkdir "$JS_AUTO_GENERATED_DIR"
|
2014-03-10 18:13:39 +08:00
|
|
|
|
|
|
|
# 1. Generate LUA bindings
|
|
|
|
generate_bindings_glue_codes
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo Bindings generated successfully
|
|
|
|
echo
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo Using "'$COMMITTAG'" in the commit messages
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
|
|
echo Using "$ELAPSEDSECS" in the branch names for pseudo-uniqueness
|
|
|
|
|
|
|
|
# 2. In Bindings repo, Check if there are any files that are different from the index
|
|
|
|
|
|
|
|
pushd "$PROJECT_ROOT"
|
|
|
|
|
|
|
|
# Run status to record the output in the log
|
|
|
|
git status
|
|
|
|
|
|
|
|
echo
|
2014-03-25 16:24:08 +08:00
|
|
|
echo Comparing with origin HEAD ...
|
2014-03-10 18:13:39 +08:00
|
|
|
echo
|
|
|
|
|
2014-03-25 16:24:08 +08:00
|
|
|
git fetch origin ${FETCH_REMOTE_BRANCH}
|
|
|
|
|
2014-03-10 18:13:39 +08:00
|
|
|
# Don't exit on non-zero return value
|
|
|
|
set +e
|
2015-05-05 11:52:52 +08:00
|
|
|
git diff FETCH_HEAD --stat --exit-code ${LUA_COMMIT_PATH}
|
|
|
|
|
|
|
|
LUA_DIFF_RETVAL=$?
|
|
|
|
|
|
|
|
git diff FETCH_HEAD --stat --exit-code ${JS_COMMIT_PATH}
|
2014-03-10 18:13:39 +08:00
|
|
|
|
2015-05-05 11:52:52 +08:00
|
|
|
JS_DIFF_RETVAL=$?
|
|
|
|
if [ $LUA_DIFF_RETVAL -eq 0 -a $JS_DIFF_RETVAL -eq 0 ]
|
2014-03-10 18:13:39 +08:00
|
|
|
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
|
|
|
|
|
2015-05-05 11:52:52 +08:00
|
|
|
git add -f --all "$LUA_AUTO_GENERATED_DIR"
|
|
|
|
git add -f --all "$JS_AUTO_GENERATED_DIR"
|
2014-03-10 18:13:39 +08:00
|
|
|
git checkout -b "$COCOS_BRANCH"
|
|
|
|
git commit -m "$COMMITTAG"
|
|
|
|
|
|
|
|
#Set remotes
|
2014-03-10 18:20:51 +08:00
|
|
|
git remote add upstream "$COCOS_ROBOT_REMOTE" 2> /dev/null > /dev/null
|
2014-03-10 18:13:39 +08:00
|
|
|
|
|
|
|
echo "Pushing to Robot's repo ..."
|
|
|
|
git push -fq upstream "$COCOS_BRANCH" 2> /dev/null
|
|
|
|
|
2014-05-12 21:55:11 +08:00
|
|
|
# 7.
|
2014-03-10 18:13:39 +08:00
|
|
|
echo "Sending Pull Request to base repo ..."
|
|
|
|
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
|
|
|
|
|
|
|
|
popd
|