2012-09-25 07:16:14 +08:00
#!/bin/bash
# Generate JS bindings for Cocos2D-X
# ... using Android NDK system headers
2012-10-10 03:20:40 +08:00
# ... and automatically update submodule references
# ... and push these changes to remote repos
2012-09-25 07:16:14 +08:00
2012-10-10 03:20:40 +08:00
# Dependencies
#
# For bindings generator:
# (see ../../../tojs/genbindings.sh
2012-09-26 04:55:06 +08:00
# ... for the defaults used if the environment is not customized)
#
2012-09-25 07:16:14 +08:00
# * $PYTHON_BIN
# * $CLANG_ROOT
# * $NDK_ROOT
2012-10-10 03:20:40 +08:00
#
# For automatically pushing changes:
#
# * REMOTE_COCOS2DX_REPOSITORY
# * REMOTE_AUTOGEN_BINDINGS_REPOSITORY
# * Ensure you have ssh access to above repositories
2012-09-25 07:16:14 +08:00
2012-10-10 23:08:52 +08:00
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
COCOS2DX_ROOT = " $DIR " /../../../..
# 1. Generate JS bindings
COCOS2DX_ROOT = " $COCOS2DX_ROOT " /bin/bash ../../../tojs/genbindings.sh
echo
echo Bindings generated successfully
echo
2012-10-10 03:20:40 +08:00
if [ -z " ${ REMOTE_AUTOGEN_BINDINGS_REPOSITORY +aaa } " ] ; then
2012-10-10 23:08:52 +08:00
echo
2012-10-10 03:20:40 +08:00
echo Environment variable must be set REMOTE_AUTOGEN_BINDINGS_REPOSITORY
2012-10-10 23:08:52 +08:00
echo This script expects to automatically push changes
echo to this repo
echo
echo Exiting with failure.
echo
2012-10-10 03:20:40 +08:00
# example
2012-10-10 12:36:32 +08:00
# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="git@github.com:folecr/cocos2dx-autogen-bindings.git"
# REMOTE_AUTOGEN_BINDINGS_REPOSITORY="$HOME/test/cocos2dx-autogen-bindings"
2012-09-25 07:16:14 +08:00
exit 1
fi
2012-10-10 03:20:40 +08:00
if [ -z " ${ COMMITTAG +aaa } " ] ; then
# ... if COMMITTAG is not set, use this machine's hostname
COMMITTAG = ` hostname -s`
fi
2012-10-15 13:13:21 +08:00
echo
2012-10-10 03:20:40 +08:00
echo Using " ' $COMMITTAG ' " in the commit messages
2012-10-15 13:13:21 +08:00
echo
2012-10-10 03:20:40 +08:00
ELAPSEDSECS = ` date +%s`
echo Using " $ELAPSEDSECS " in the branch names for pseudo-uniqueness
GENERATED_BRANCH = autogeneratedbindings_" $ELAPSEDSECS "
2012-10-15 13:12:24 +08:00
GENERATED_GITDIR = " $COCOS2DX_ROOT " /.git/modules/scripting/javascript/bindings/generated
2012-10-10 03:20:40 +08:00
GENERATED_WORKTREE = " $COCOS2DX_ROOT " /scripting/javascript/bindings/generated
# git command shortcut
gitcmd_GEN = " git --git-dir= $GENERATED_GITDIR --work-tree= $GENERATED_WORKTREE "
2012-10-15 13:13:21 +08:00
# 2. In JSBindings repo, Check if there are any files that are different from the index
# Run status to record the output in the log
2012-10-10 03:20:40 +08:00
${ gitcmd_GEN } status
2012-10-15 13:13:21 +08:00
echo
2012-10-16 04:23:44 +08:00
echo Comparing with origin/master ...
2012-10-15 13:13:21 +08:00
echo
2012-10-16 04:23:44 +08:00
${ gitcmd_GEN } diff --stat --exit-code origin/master
2012-10-15 13:13:21 +08:00
DIFF_RETVAL = $?
if [ $DIFF_RETVAL -eq 0 ]
then
echo
echo "No differences in generated files"
echo "Exiting with success."
echo
exit 0
else
echo
2012-10-16 04:23:44 +08:00
echo "Generated files differ from origin/master. Continuing."
2012-10-15 13:13:21 +08:00
echo
fi
# 3. In JSBindings repo, Check out a branch named "autogeneratedbindings" and commit the auto generated bindings to it
${ gitcmd_GEN } add --verbose README cocos2dx.cpp cocos2dx.hpp cocos2dxapi.js
2012-10-10 03:20:40 +08:00
${ gitcmd_GEN } checkout origin/master -b " $GENERATED_BRANCH "
2012-10-15 13:13:21 +08:00
${ gitcmd_GEN } commit --verbose -m " $COMMITTAG : autogenerated bindings "
2012-10-10 03:20:40 +08:00
2012-10-15 13:13:21 +08:00
# 4. In JSBindings repo, Push the commit with generated bindings to "master" of the auto generated bindings repository
${ gitcmd_GEN } push --verbose " $REMOTE_AUTOGEN_BINDINGS_REPOSITORY " " $GENERATED_BRANCH " :master
2012-10-10 03:20:40 +08:00
2012-10-10 12:36:32 +08:00
if [ -z " ${ REMOTE_COCOS2DX_REPOSITORY +aaa } " ] ; then
2012-10-10 23:08:52 +08:00
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
echo Exiting with success.
echo
2012-10-10 12:36:32 +08:00
# example
# REMOTE_COCOS2DX_REPOSITORY="git@github.com:cocos2d/cocos2d-x.git"
# REMOTE_COCOS2DX_REPOSITORY="$HOME/test/cocos2d-x"
2012-10-10 23:08:52 +08:00
exit 0
2012-10-10 12:36:32 +08:00
fi
2012-10-10 23:08:52 +08:00
COCOS_BRANCH = updategeneratedsubmodule_" $ELAPSEDSECS "
2012-10-10 03:20:40 +08:00
pushd " ${ DIR } "
2012-10-15 13:13:21 +08:00
# 5. In Cocos2D-X repo, Checkout a branch named "updategeneratedsubmodule" Update the submodule reference to point to the commit with generated bindings
2012-10-10 03:20:40 +08:00
cd " ${ COCOS2DX_ROOT } "
git add scripting/javascript/bindings/generated
git checkout origin/gles20 -b " $COCOS_BRANCH "
git commit -m " $COMMITTAG : updating submodule reference to latest autogenerated bindings "
2012-10-15 13:13:21 +08:00
# 6. In Cocos2D-X repo, Push the commit with updated submodule to "gles20" of the cocos2d-x repository
2012-10-10 03:20:40 +08:00
git push " $REMOTE_COCOS2DX_REPOSITORY " " $COCOS_BRANCH " :gles20
popd