2013-05-13 15:18:18 +08:00
#!/bin/bash
2013-08-27 16:05:48 +08:00
# Generate JS and Lua bindings for Cocos2D-X
2013-05-13 15:18:18 +08:00
# ... using Android NDK system headers
# ... and automatically update submodule references
# ... and push these changes to remote repos
# Dependencies
#
# For bindings generator:
2014-02-10 18:30:22 +08:00
# (see ../../../tojs/genbindings.py and ../../../tolua/genbindings.py
2013-05-13 15:18:18 +08:00
# ... for the defaults used if the environment is not customized)
#
# * $PYTHON_BIN
# * $CLANG_ROOT
# * $NDK_ROOT
#
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
COCOS2DX_ROOT = " $DIR " /../..
TOJS_ROOT = $COCOS2DX_ROOT /tools/tojs
2013-08-27 16:05:48 +08:00
TOLUA_ROOT = $COCOS2DX_ROOT /tools/tolua
2013-11-01 11:46:02 +08:00
GENERATED_WORKTREE = " $COCOS2DX_ROOT " /cocos/scripting/auto-generated
2013-05-21 14:23:34 +08:00
COMMITTAG = "[AUTO]"
2013-05-13 15:18:18 +08:00
2013-05-21 16:13:47 +08:00
# Exit on error
set -e
if [ " $PLATFORM " x = "ios" x ] ; then
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
2014-02-12 22:01:46 +08:00
elif [ $( command -v apt-get) ] ; then
2013-05-21 16:13:47 +08:00
sudo apt-get --force-yes --yes install python-yaml python-cheetah
fi
2013-08-27 16:05:48 +08:00
generate_bindings_glue_codes( )
{
echo "Create auto-generated jsbinding glue codes."
2013-05-21 16:13:47 +08:00
pushd " $TOJS_ROOT "
2014-02-10 18:30:22 +08:00
./genbindings.py
2013-05-21 16:13:47 +08:00
popd
2013-08-27 16:05:48 +08:00
echo "Create auto-generated luabinding glue codes."
pushd " $TOLUA_ROOT "
2014-02-10 18:30:22 +08:00
./genbindings.py
2013-08-27 16:05:48 +08:00
popd
}
if [ " $GEN_JSB " x != "YES" x ] ; then
generate_bindings_glue_codes
2013-05-21 16:13:47 +08:00
exit 0
fi
2013-05-13 15:18:18 +08:00
2013-06-26 16:57:08 +08:00
pushd " $COCOS2DX_ROOT "
#Set git user for cocos2d-x repo
git config user.email ${ GH_EMAIL }
git config user.name ${ GH_USER }
popd
2013-08-27 16:05:48 +08:00
# Update submodule of auto-gen Binding repo.
2013-05-13 15:18:18 +08:00
pushd " $GENERATED_WORKTREE "
git checkout -B master
2013-08-27 16:05:48 +08:00
echo " Set git user for the submodule of ${ GENERATED_WORKTREE } "
2013-06-25 01:41:48 +08:00
git config user.email ${ GH_EMAIL }
git config user.name ${ GH_USER }
2013-05-13 15:18:18 +08:00
#Set remotes
2013-11-01 11:46:02 +08:00
git remote add upstream https://${ GH_USER } :${ GH_PASSWORD } @github.com/cocos2d-x/bindings-auto-generated.git 2> /dev/null > /dev/null
2013-05-13 15:18:18 +08:00
2013-11-01 11:46:02 +08:00
echo "Delete all directories and files except '.git' and 'README.md'."
2013-11-01 11:50:43 +08:00
ls -a | grep -E -v ^\[ .\] \{ 1,2\} $ | grep -E -v ^\. git$ | grep -E -v ^README\. md$ | xargs -I{ } rm -rf { }
2013-08-27 16:05:48 +08:00
echo " Show files in ${ GENERATED_WORKTREE } folder. "
2013-05-13 15:18:18 +08:00
ls -a
popd
2013-05-21 16:13:47 +08:00
2013-05-13 15:18:18 +08:00
# 1. Generate JS bindings
2013-08-27 16:05:48 +08:00
generate_bindings_glue_codes
2013-05-13 15:18:18 +08:00
echo
echo Bindings generated successfully
echo
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 "
2013-08-27 16:05:48 +08:00
# 2. In Bindings repo, Check if there are any files that are different from the index
2013-05-13 15:18:18 +08:00
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
2013-08-27 16:05:48 +08:00
# 3. In Bindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it
2013-05-13 15:18:18 +08:00
git checkout -b " $GENERATED_BRANCH "
git add --verbose .
git add --verbose -u .
git commit --verbose -m " $COMMITTAG : autogenerated bindings "
2013-08-27 16:05:48 +08:00
# 4. In Bindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository
2013-06-04 14:17:28 +08:00
git push -fq upstream " $GENERATED_BRANCH " :${ TRAVIS_BRANCH } _${ ELAPSEDSECS } 2> /dev/null
2013-05-13 15:18:18 +08:00
popd
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 } "
2013-08-27 16:05:48 +08:00
git add ${ GENERATED_WORKTREE }
2013-05-13 15:18:18 +08:00
git checkout -b " $COCOS_BRANCH "
git commit -m " $COMMITTAG : updating submodule reference to latest autogenerated bindings "
#Set remotes
2013-05-21 13:45:56 +08:00
git remote add upstream https://${ GH_USER } :${ GH_PASSWORD } @github.com/${ GH_USER } /cocos2d-x.git 2> /dev/null > /dev/null
2013-05-13 15:18:18 +08:00
# 6. In Cocos2D-X repo, Push the commit with updated submodule to "master" of the cocos2d-x repository
2013-07-08 15:27:49 +08:00
echo "Pushing to Robot's repo ..."
2013-05-13 15:18:18 +08:00
git push -fq upstream " $COCOS_BRANCH " 2> /dev/null
# 7.
2013-07-08 15:27:49 +08:00
echo "Sending Pull Request to base repo ..."
2013-05-24 16:53:42 +08:00
curl --user " ${ GH_USER } : ${ GH_PASSWORD } " --request POST --data " { \"title\": \" $COMMITTAG : updating submodule reference to latest autogenerated bindings\", \"body\": \"\", \"head\": \" ${ GH_USER } : ${ COCOS_BRANCH } \", \"base\": \" ${ TRAVIS_BRANCH } \"} " https://api.github.com/repos/cocos2d/cocos2d-x/pulls 2> /dev/null > /dev/null
2013-05-13 15:18:18 +08:00
popd