From 4be97c1ed85b469136f923cf957cf01510c5d55f Mon Sep 17 00:00:00 2001 From: lihex Date: Mon, 10 Feb 2014 10:36:37 +0800 Subject: [PATCH 1/7] issue #3781, use python script instead. --- tools/tojs/README.mdown | 44 ++++++++- tools/tojs/genbindings-win32.bat | 116 ----------------------- tools/tojs/genbindings.py | 148 ++++++++++++++++++++++++++++++ tools/tojs/genbindings.sh | 144 ----------------------------- tools/tolua/README.mdown | 43 ++++++++- tools/tolua/genbindings-win32.bat | 117 ----------------------- tools/tolua/genbindings.py | 148 ++++++++++++++++++++++++++++++ tools/tolua/genbindings.sh | 144 ----------------------------- 8 files changed, 377 insertions(+), 527 deletions(-) delete mode 100644 tools/tojs/genbindings-win32.bat create mode 100644 tools/tojs/genbindings.py delete mode 100755 tools/tojs/genbindings.sh delete mode 100644 tools/tolua/genbindings-win32.bat create mode 100644 tools/tolua/genbindings.py delete mode 100755 tools/tolua/genbindings.sh diff --git a/tools/tojs/README.mdown b/tools/tojs/README.mdown index ca2d722fa6..9b31226156 100644 --- a/tools/tojs/README.mdown +++ b/tools/tojs/README.mdown @@ -9,11 +9,49 @@ On Windows: * Add the installed path of python (e.g. C:\Python27) to windows environment variable named 'PATH'. * Download pyyaml from http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and install it. * Download pyCheetah from https://raw.github.com/dumganhar/cocos2d-x/download/downloads/Cheetah.zip, unzip it to "C:\Python27\Lib\site-packages" -* Set environment variables (`PYTHON_ROOT` and `NDK_ROOT`) or just modify variables (`PYTHON_ROOT` and `NDK_ROOT`) in `genbindings-win32.bat`. -* Go to "cocos2d-x/tools/tojs" folder, and run "genbindings-win32.bat". The generated codes will be under "cocos\scripting\auto-generated\js-bindings". +* Set environment variables (`NDK_ROOT`) +* Go to "cocos2d-x/tools/tojs" folder, and run "genbindings.py". The generated codes will be under "cocos\scripting\auto-generated\js-bindings". + On MAC: ---------- -* Please refer to https://github.com/cocos2d/bindings-generator/blob/develop/README.md +* The OSX 10.9 has a built-in python2.7 and if your os don't have python2.7 then use [Homebrew](http://brew.sh/) to install the python and use pip install the python dependencies. +
+	brew install python
+
+* Install python dependices by pip. +
+    sudo easy_install pip
+    sudo pip install PyYAML
+	sudo pip install Cheetah
+
+ +* Download [64bit ndk-r9b-x86_64](http://dl.google.com/android/ndk/android-ndk-r9b-darwin-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) +* Run +
+	export NDK_ROOT=/path/to/android-ndk-r9b
+    ./genbindings.py
+
+ + +On Ubuntu Linux 12.04 64bit +------------ + +* Install python +
+	sudo apt-get install python2.7
+
+* Install python dependices by pip. +
+	sudo apt-get install python-pip
+	sudo pip install PyYAML
+	sudo pip install Cheetah
+
+* Download [64bit ndk-r9b-x86_64]( https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) +* Go to "cocos2d-x/tools/tojs", Run +
+	export NDK_ROOT=/path/to/android-ndk-r9b
+    ./genbindings.py
+
diff --git a/tools/tojs/genbindings-win32.bat b/tools/tojs/genbindings-win32.bat deleted file mode 100644 index 2eed6dd76e..0000000000 --- a/tools/tojs/genbindings-win32.bat +++ /dev/null @@ -1,116 +0,0 @@ -@echo off - -:: This script is used to generate jsbinding glue codes. -:: Android ndk version must be ndk-r9b. - -setlocal -:: You should modify PYTHON_ROOT and NDK_ROOT to work under your environment. -:: or just uncomment the follow 2 lines and set them. - -:: set PYTHON_ROOT=C:/Python27 -:: set NDK_ROOT=G:/android/android-ndk-r9b - -setlocal ENABLEEXTENSIONS -if %errorlevel% neq 0 ( - echo Unable to enable extensions - exit /b 1 - ) - -if defined PYTHON_ROOT (echo PYTHON_ROOT is defined.) else ( - echo PYTHON_ROOT is NOT defined! - exit /b 1 - ) - -if defined NDK_ROOT (echo NDK_ROOT is defined.) else ( - echo NDK_ROOT is NOT defined! - exit /b 1 - ) - -:: Check use 32-bit or 64-bit -:: Assume 64-bit -set TEMP=windows-x86_64 -if not exist "%NDK_ROOT%/toolchains/llvm-3.3/prebuilt/%TEMP%" set TEMP= -:: Otherwise fall back to 32-bit make -if "%TEMP%"=="" set TEMP=windows - -set NDK_LLVM_ROOT=%NDK_ROOT%/toolchains/llvm-3.3/prebuilt/%TEMP% - -set COCOS2DX_ROOT=%cd%/../.. -set "COCOS2DX_ROOT=%COCOS2DX_ROOT:\=/%" -set CXX_GENERATOR_ROOT=%COCOS2DX_ROOT%/tools/bindings-generator -set TO_JS_ROOT=%COCOS2DX_ROOT%/tools/tojs -set "CXX_GENERATOR_ROOT=%CXX_GENERATOR_ROOT:\=/%" -set OUTPUT_DIR=%COCOS2DX_ROOT%/cocos/scripting/auto-generated/js-bindings -set "OUTPUT_DIR=%OUTPUT_DIR:/=\%" - -set PATH=%PATH%;%CXX_GENERATOR_ROOT%/libclang;%CXX_GENERATOR_ROOT%/tools/win32;%PYTHON_ROOT% - -:: write userconf.ini - -set _CONF_INI_FILE=%cd%\userconf.ini -if exist %_CONF_INI_FILE% del /Q %_CONF_INI_FILE% - - -echo -echo generating userconf.ini... -echo --- -echo [DEFAULT] > %_CONF_INI_FILE% -echo androidndkdir=%NDK_ROOT% >> %_CONF_INI_FILE% -echo clangllvmdir=%NDK_LLVM_ROOT% >> %_CONF_INI_FILE% -echo cocosdir=%COCOS2DX_ROOT% >> %_CONF_INI_FILE% -echo cxxgeneratordir=%CXX_GENERATOR_ROOT% >> %_CONF_INI_FILE% -:: fixme: to fix parse error, we must difine __WCHAR_MAX__ and undefine __MINGW32__ . -echo extra_flags=-D__WCHAR_MAX__=0x7fffffff -U__MINGW32__ >> %_CONF_INI_FILE% -echo --- - - - -:: Generate bindings for cocos2dx -echo Generating bindings for cocos2dx... -python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx.ini -s cocos2d-x -t spidermonkey -o %OUTPUT_DIR% -n js_cocos2dx_auto -if %errorlevel% neq 0 goto ERROR - -echo "Generating bindings for cocos2dx_extension..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx_extension.ini -s cocos2dx_extension -t spidermonkey -o %OUTPUT_DIR% -n js_cocos2dx_extension_auto -if %errorlevel% neq 0 goto ERROR - -echo "Generating bindings for cocos2dx_builder..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx_builder.ini -s cocos2dx_builder -t spidermonkey -o %OUTPUT_DIR% -n jsb_cocos2dx_builder_auto -if %errorlevel% neq 0 goto ERROR - -echo "Generating bindings for cocos2dx_gui..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx_gui.ini -s cocos2dx_gui -t spidermonkey -o %OUTPUT_DIR% -n js_cocos2dx_gui_auto -if %errorlevel% neq 0 goto ERROR - - -echo "Generating bindings for cocos2dx_studio..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx_studio.ini -s cocos2dx_studio -t spidermonkey -o %OUTPUT_DIR% -n js_cocos2dx_studio_auto -if %errorlevel% neq 0 goto ERROR - - -echo "Generating bindings for cocos2dx_spine..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_JS_ROOT%/cocos2dx_spine.ini -s cocos2dx_spine -t spidermonkey -o %OUTPUT_DIR% -n js_cocos2dx_spine_auto -if %errorlevel% neq 0 goto ERROR - - -:: Change the generated file format from DOS to UNIX. -pushd "%OUTPUT_DIR%" -dos2unix * -popd - -goto PASS - -:PASS -echo --------------------------------- -echo Generating bindings succeeds. -echo --------------------------------- -endlocal -exit /b 0 - -:ERROR -echo --------------------------------- -echo Generating bindings fails. -echo --------------------------------- -endlocal -exit /b 1 - diff --git a/tools/tojs/genbindings.py b/tools/tojs/genbindings.py new file mode 100644 index 0000000000..699a3f8b75 --- /dev/null +++ b/tools/tojs/genbindings.py @@ -0,0 +1,148 @@ +#!/usr/bin/python + +# This script is used to generate luabinding glue codes. +# Android ndk version must be ndk-r9b. + + +import sys +import os, os.path +import shutil +import ConfigParser +import subprocess +import re +from contextlib import contextmanager + + +def _check_environment_variables(): + ''' Checking the environment NDK_ROOT, which will be used for building + ''' + + try: + NDK_ROOT = os.environ['NDK_ROOT'] + except Exception: + print "NDK_ROOT not defined. Please define NDK_ROOT in your environment" + sys.exit(1) + + return NDK_ROOT + +class CmdError(Exception): + pass + + +@contextmanager +def _pushd(newDir): + previousDir = os.getcwd() + os.chdir(newDir) + yield + os.chdir(previousDir) + +def _run_cmd(command): + ret = subprocess.call(command, shell=True) + if ret != 0: + message = "Error running command" + raise CmdError(message) + +def main(): + + cur_platform= '??' + llvm_path = '??' + ndk_root = _check_environment_variables() + # del the " in the path + ndk_root = re.sub(r"\"", "", ndk_root) + + platform = sys.platform + if platform == 'win32': + cur_platform = 'windows' + elif platform == 'darwin': + cur_platform = platform + elif 'linux' in platform: + cur_platform = 'linux' + else: + print 'Your platform is not supported!' + sys.exit(1) + + x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86'))) + x64_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86_64'))) + + if os.path.isdir(x86_llvm_path): + llvm_path = x86_llvm_path + elif os.path.isdir(x64_llvm_path): + llvm_path = x64_llvm_path + else: + print 'llvm toochain not found!' + print 'path: %s or path: %s are not valid! ' % (x86_llvm_path, x64_llvm_path) + sys.exit(1) + + cocos_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) + cxx_generator_root = os.path.abspath(os.path.join(cocos_root, 'tools/bindings-generator')) + + # save config to file + config = ConfigParser.ConfigParser() + config.set('DEFAULT', 'androidndkdir', ndk_root) + config.set('DEFAULT', 'clangllvmdir', llvm_path) + config.set('DEFAULT', 'cocosdir', cocos_root) + config.set('DEFAULT', 'cxxgeneratordir', cxx_generator_root) + config.set('DEFAULT', 'extra_flags', '') + + # To fix parse error on windows, we must difine __WCHAR_MAX__ and undefine __MINGW32__ . + if platform == 'win32': + config.set('DEFAULT', 'extra_flags', '-D__WCHAR_MAX__=0x7fffffff -U__MINGW32__') + + conf_ini_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'userconf.ini')) + + print 'generating userconf.ini...' + with open(conf_ini_file, 'w') as configfile: + config.write(configfile) + + + # set proper environment variables + if 'linux' in platform or platform == 'darwin': + os.putenv('LD_LIBRARY_PATH', '%s/libclang' % cxx_generator_root) + if platform == 'win32': + path_env = os.environ['PATH'] + os.putenv('PATH', r'%s;%s\libclang;%s\tools\win32;' % (path_env, cxx_generator_root, cxx_generator_root)) + + + try: + + tojs_root = '%s/tools/tojs' % cocos_root + output_dir = '%s/cocos/scripting/auto-generated/js-bindings' % cocos_root + + cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'jsb_cocos2dx_auto'), \ + 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'jsb_cocos2dx_extension_auto'), \ + 'cocos2dx_builder.ini' : ('cocos2dx_builder', 'jsb_cocos2dx_builder_auto'), \ + 'cocos2dx_gui.ini' : ('cocos2dx_gui', 'jsb_cocos2dx_gui_auto'), \ + 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'jsb_cocos2dx_studio_auto'), \ + 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'jsb_cocos2dx_spine_auto'), \ + } + target = 'spidermonkey' + python_bin = sys.executable + generator_py = '%s/generator.py' % cxx_generator_root + for key in cmd_args.keys(): + args = cmd_args[key] + cfg = '%s/%s' % (tojs_root, key) + print 'Generating bindings for %s...' % (key[:-4]) + command = '%s %s %s -s %s -t %s -o %s -n %s' % (python_bin, generator_py, cfg, args[0], target, output_dir, args[1]) + _run_cmd(command) + + if platform == 'win32': + with _pushd(output_dir): + _run_cmd('dos2unix *') + + print '---------------------------------' + print 'Generating bindings succeeds.' + print '---------------------------------' + + except Exception as e: + if e.__class__.__name__ == 'CmdError': + print '---------------------------------' + print 'Generating bindings fails.' + print '---------------------------------' + sys.exit(1) + else: + raise + + +# -------------- main -------------- +if __name__ == '__main__': + main() diff --git a/tools/tojs/genbindings.sh b/tools/tojs/genbindings.sh deleted file mode 100755 index aa95a4e28b..0000000000 --- a/tools/tojs/genbindings.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/bash -# -# Usage: -# export NDK_ROOT=/path/to/ndk-r9b -# ./genbindings.sh -# - -# exit this script if any commmand fails -set -e - -# read user.cfg if it exists and is readable - -_CFG_FILE=$(dirname "$0")"/user.cfg" -if [ -f "$_CFG_FILE" ]; -then - if [ ! -r "$_CFG_FILE" ]; then - echo "Fatal Error: $_CFG_FILE exists but is unreadable" - exit 1 - fi -fi - -# paths - -if [ -z "${NDK_ROOT+aaa}" ]; then -# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk" - NDK_ROOT="$HOME/bin/android-ndk" -fi - -if [ -z "${PYTHON_BIN+aaa}" ]; then -# ... if PYTHON_BIN is not set, use "/usr/bin/python2.7" - PYTHON_BIN="/usr/bin/python2.7" -fi - -# find current dir -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# paths with defaults hardcoded to relative paths - -if [ -z "${COCOS2DX_ROOT+aaa}" ]; then - COCOS2DX_ROOT="$DIR/../.." -fi - -if [ -z "${CXX_GENERATOR_ROOT+aaa}" ]; then - CXX_GENERATOR_ROOT="$COCOS2DX_ROOT/tools/bindings-generator" -fi - -if [ -z "${TOJS_ROOT+aaa}" ]; then - TOJS_ROOT="$COCOS2DX_ROOT/tools/tojs" -fi - -# set output dir -OUTPUT_DIR=${COCOS2DX_ROOT}/cocos/scripting/auto-generated/js-bindings - -echo "Paths" -echo " NDK_ROOT: $NDK_ROOT" -echo " PYTHON_BIN: $PYTHON_BIN" -echo " COCOS2DX_ROOT: $COCOS2DX_ROOT" -echo " CXX_GENERATOR_ROOT: $CXX_GENERATOR_ROOT" -echo " TOJS_ROOT: $TOJS_ROOT" - -# check NDK version, must be r9b -if ! grep -q r9b $NDK_ROOT/RELEASE.TXT -then - echo " Fatal Error: NDK r9b must be required!" - exit 1 -fi - -# check clang include path -OS_NAME=$('uname') -NDK_LLVM_ROOT=$NDK_ROOT/toolchains/llvm-3.3/prebuilt -case "$OS_NAME" in - Darwin | darwin) - echo "in darwin" - if [ -d "$NDK_LLVM_ROOT/darwin-x86_64" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/darwin-x86_64 - elif [ -d "$NDK_LLVM_ROOT/darwin-x86" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/darwin-x86 - else - echo $NDK_LLVM_ROOT - echo " Fatal Error: $NDK_LLVM_ROOT doesn't contains prebuilt llvm 3.3" - exit 1 - fi - ;; - Linux | linux) - echo "in linux" - if [ -d "$NDK_LLVM_ROOT/linux-x86_64" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/linux-x86_64 - elif [ -d "$NDK_LLVM_ROOT/linux-x86" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/linux-x86 - else - echo " Fatal Error: $NDK_LLVM_ROOT doesn't contains prebuilt llvm 3.3" - exit 1 - fi - ;; - *) - echo " Fatal Error: Please run this script in linux or mac osx." - exit 1 - ;; -esac - - -# write userconf.ini - -_CONF_INI_FILE="$PWD/userconf.ini" -if [ -f "$_CONF_INI_FILE" ] -then - rm "$_CONF_INI_FILE" -fi - -_CONTENTS="" -_CONTENTS+="[DEFAULT]"'\n' -_CONTENTS+="androidndkdir=$NDK_ROOT"'\n' -_CONTENTS+="clangllvmdir=$NDK_LLVM_ROOT"'\n' -_CONTENTS+="cocosdir=$COCOS2DX_ROOT"'\n' -_CONTENTS+="cxxgeneratordir=$CXX_GENERATOR_ROOT"'\n' -_CONTENTS+="extra_flags="'\n' - -echo -echo "generating userconf.ini..." -echo --- -echo -e "$_CONTENTS" -echo -e "$_CONTENTS" > "$_CONF_INI_FILE" -echo --- - -# Generate bindings for cocos2dx -echo "Generating bindings for cocos2dx..." -set -x -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOJS_ROOT}/cocos2dx.ini -s cocos2d-x -t spidermonkey -o ${OUTPUT_DIR} -n jsb_cocos2dx_auto - -echo "Generating bindings for cocos2dx_extension..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOJS_ROOT}/cocos2dx_extension.ini -s cocos2dx_extension -t spidermonkey -o ${OUTPUT_DIR} -n jsb_cocos2dx_extension_auto - -echo "Generating bindings for cocos2dx_builder..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOJS_ROOT}/cocos2dx_builder.ini -s cocos2dx_builder -t spidermonkey -o ${OUTPUT_DIR} -n jsb_cocos2dx_builder_auto - -echo "Generating bindings for cocos2dx_gui..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOJS_ROOT}/cocos2dx_gui.ini -s cocos2dx_gui -t spidermonkey -o ${OUTPUT_DIR} -n jsb_cocos2dx_gui_auto - -echo "Generating bindings for cocos2dx_studio..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOJS_ROOT}/cocos2dx_studio.ini -s cocos2dx_studio -t spidermonkey -o ${OUTPUT_DIR} -n jsb_cocos2dx_studio_auto - -echo "Generating bindings for cocos2dx_spine..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOJS_ROOT}/cocos2dx_spine.ini -s cocos2dx_spine -t spidermonkey -o ${OUTPUT_DIR} -n jsb_cocos2dx_spine_auto - diff --git a/tools/tolua/README.mdown b/tools/tolua/README.mdown index f6f34fddd4..614d934a6b 100644 --- a/tools/tolua/README.mdown +++ b/tools/tolua/README.mdown @@ -9,12 +9,49 @@ On Windows: * Add the installed path of python (e.g. C:\Python27) to windows environment variable named 'PATH'. * Download pyyaml from http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe and install it. * Download pyCheetah from https://raw.github.com/dumganhar/cocos2d-x/download/downloads/Cheetah.zip, unzip it to "C:\Python27\Lib\site-packages" -* Set environment variables (`PYTHON_ROOT` and `NDK_ROOT`) or just modify variables (`PYTHON_ROOT` and `NDK_ROOT`) in `genbindings-win32.bat`. -* Go to "cocos2d-x/tools/tolua" folder, and run "genbindings-win32.bat". The generated codes will be under "cocos\scripting\auto-generated\lua-bindings". +* Set environment variables (`NDK_ROOT`) +* Go to "cocos2d-x/tools/tolua" folder, and run "genbindings.py". The generated codes will be under "cocos\scripting\auto-generated\js-bindings". + On MAC: ---------- -* Please refer to https://github.com/cocos2d/bindings-generator/blob/develop/README.md +* The OSX 10.9 has a built-in python2.7 and if your os don't have python2.7 then use [Homebrew](http://brew.sh/) to install the python and use pip install the python dependencies. +
+	brew install python
+
+ +* Install python dependices by pip. +
+    sudo easy_install pip
+    sudo pip install PyYAML
+	sudo pip install Cheetah
+
+ +* Download [64bit ndk-r9b-x86_64](http://dl.google.com/android/ndk/android-ndk-r9b-darwin-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) +* Run +
+	export NDK_ROOT=/path/to/android-ndk-r9b
+    ./genbindings.py
+
+On Ubuntu Linux 12.04 64bit +------------ + +* Install python +
+	sudo apt-get install python2.7
+
+* Install python dependices by pip. +
+	sudo apt-get install python-pip
+	sudo pip install PyYAML
+	sudo pip install Cheetah
+
+* Download [64bit ndk-r9b-x86_64]( https://dl.google.com/android/ndk/android-ndk-r9b-linux-x86_64.tar.bz2) from [google](http://developer.android.com/tools/sdk/ndk/index.html) +* Go to "cocos2d-x/tools/tolua", Run +
+	export NDK_ROOT=/path/to/android-ndk-r9b
+    ./genbindings.py
+
diff --git a/tools/tolua/genbindings-win32.bat b/tools/tolua/genbindings-win32.bat deleted file mode 100644 index 672d63bd2f..0000000000 --- a/tools/tolua/genbindings-win32.bat +++ /dev/null @@ -1,117 +0,0 @@ -@echo off - -:: This script is used to generate jsbinding glue codes. -:: Android ndk version must be ndk-r9b. - -setlocal -:: You should modify PYTHON_ROOT and NDK_ROOT to work under your environment. -:: or just uncomment the follow 2 lines and set them. - -:: set PYTHON_ROOT=C:/Python27 -:: set NDK_ROOT=G:/android/android-ndk-r9b - -setlocal ENABLEEXTENSIONS -if %errorlevel% neq 0 ( - echo Unable to enable extensions - exit /b 1 - ) - -if defined PYTHON_ROOT (echo PYTHON_ROOT is defined.) else ( - echo PYTHON_ROOT is NOT defined! - exit /b 1 - ) - -if defined NDK_ROOT (echo NDK_ROOT is defined.) else ( - echo NDK_ROOT is NOT defined! - exit /b 1 - ) - -:: Check use 32-bit or 64-bit -:: Assume 64-bit -set TEMP=windows-x86_64 -if not exist "%NDK_ROOT%/toolchains/llvm-3.3/prebuilt/%TEMP%" set TEMP= -:: Otherwise fall back to 32-bit make -if "%TEMP%"=="" set TEMP=windows - -set NDK_LLVM_ROOT=%NDK_ROOT%/toolchains/llvm-3.3/prebuilt/%TEMP% - -set COCOS2DX_ROOT=%cd%/../.. -set "COCOS2DX_ROOT=%COCOS2DX_ROOT:\=/%" -set CXX_GENERATOR_ROOT=%COCOS2DX_ROOT%/tools/bindings-generator -set TO_LUA_ROOT=%COCOS2DX_ROOT%/tools/tolua -set "CXX_GENERATOR_ROOT=%CXX_GENERATOR_ROOT:\=/%" -set OUTPUT_DIR=%COCOS2DX_ROOT%/cocos/scripting/auto-generated/lua-bindings -set "OUTPUT_DIR=%OUTPUT_DIR:/=\%" - -set PATH=%PATH%;%CXX_GENERATOR_ROOT%/libclang;%CXX_GENERATOR_ROOT%/tools/win32;%PYTHON_ROOT% - -:: write userconf.ini - -set _CONF_INI_FILE=%cd%\userconf.ini -if exist %_CONF_INI_FILE% del /Q %_CONF_INI_FILE% - - -echo -echo generating userconf.ini... -echo --- -echo [DEFAULT] > %_CONF_INI_FILE% -echo androidndkdir=%NDK_ROOT% >> %_CONF_INI_FILE% -echo clangllvmdir=%NDK_LLVM_ROOT% >> %_CONF_INI_FILE% -echo cocosdir=%COCOS2DX_ROOT% >> %_CONF_INI_FILE% -echo cxxgeneratordir=%CXX_GENERATOR_ROOT% >> %_CONF_INI_FILE% -:: fixme: to fix parse error, we must difine __WCHAR_MAX__ and undefine __MINGW32__ . -echo extra_flags=-D__WCHAR_MAX__=0x7fffffff -U__MINGW32__ >> %_CONF_INI_FILE% -echo --- - - - -:: Generate bindings for cocos2dx -echo Generating bindings for cocos2dx... -python %CXX_GENERATOR_ROOT%/generator.py %TO_LUA_ROOT%/cocos2dx.ini -s cocos2d-x -t lua -o %OUTPUT_DIR% -n lua_cocos2dx_auto -if %errorlevel% neq 0 goto ERROR - -echo "Generating bindings for cocos2dx_extension..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_LUA_ROOT%/cocos2dx_extension.ini -s cocos2dx_extension -t lua -o %OUTPUT_DIR% -n lua_cocos2dx_extension_auto -if %errorlevel% neq 0 goto ERROR - -echo "Generating bindings for cocos2dx_gui..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_LUA_ROOT%/cocos2dx_gui.ini -s cocos2dx_gui -t lua -o %OUTPUT_DIR% -n lua_cocos2dx_gui_auto -if %errorlevel% neq 0 goto ERROR - - -echo "Generating bindings for cocos2dx_studio..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_LUA_ROOT%/cocos2dx_studio.ini -s cocos2dx_studio -t lua -o %OUTPUT_DIR% -n lua_cocos2dx_studio_auto -if %errorlevel% neq 0 goto ERROR - - -echo "Generating bindings for cocos2dx_spine..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_LUA_ROOT%/cocos2dx_spine.ini -s cocos2dx_spine -t lua -o %OUTPUT_DIR% -n lua_cocos2dx_spine_auto -if %errorlevel% neq 0 goto ERROR - - -echo "Generating bindings for cocos2dx_physics..." -python %CXX_GENERATOR_ROOT%/generator.py %TO_LUA_ROOT%/cocos2dx_physics.ini -s cocos2dx_physics -t lua -o %OUTPUT_DIR% -n lua_cocos2dx_physics_auto -if %errorlevel% neq 0 goto ERROR - - -:: Change the generated file format from DOS to UNIX. -pushd "%OUTPUT_DIR%" -dos2unix * -popd - -goto PASS - -:PASS -echo --------------------------------- -echo Generating bindings succeeds. -echo --------------------------------- -endlocal -exit /b 0 - -:ERROR -echo --------------------------------- -echo Generating bindings fails. -echo --------------------------------- -endlocal -exit /b 1 - diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py new file mode 100644 index 0000000000..7496cba4de --- /dev/null +++ b/tools/tolua/genbindings.py @@ -0,0 +1,148 @@ +#!/usr/bin/python + +# This script is used to generate luabinding glue codes. +# Android ndk version must be ndk-r9b. + + +import sys +import os, os.path +import shutil +import ConfigParser +import subprocess +import re +from contextlib import contextmanager + + +def _check_environment_variables(): + ''' Checking the environment NDK_ROOT, which will be used for building + ''' + + try: + NDK_ROOT = os.environ['NDK_ROOT'] + except Exception: + print "NDK_ROOT not defined. Please define NDK_ROOT in your environment" + sys.exit(1) + + return NDK_ROOT + +class CmdError(Exception): + pass + + +@contextmanager +def _pushd(newDir): + previousDir = os.getcwd() + os.chdir(newDir) + yield + os.chdir(previousDir) + +def _run_cmd(command): + ret = subprocess.call(command, shell=True) + if ret != 0: + message = "Error running command" + raise CmdError(message) + +def main(): + + cur_platform= '??' + llvm_path = '??' + ndk_root = _check_environment_variables() + # del the " in the path + ndk_root = re.sub(r"\"", "", ndk_root) + + platform = sys.platform + if platform == 'win32': + cur_platform = 'windows' + elif platform == 'darwin': + cur_platform = platform + elif 'linux' in platform: + cur_platform = 'linux' + else: + print 'Your platform is not supported!' + sys.exit(1) + + x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86'))) + x64_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86_64'))) + + if os.path.isdir(x86_llvm_path): + llvm_path = x86_llvm_path + elif os.path.isdir(x64_llvm_path): + llvm_path = x64_llvm_path + else: + print 'llvm toochain not found!' + print 'path: %s or path: %s are not valid! ' % (x86_llvm_path, x64_llvm_path) + sys.exit(1) + + cocos_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) + cxx_generator_root = os.path.abspath(os.path.join(cocos_root, 'tools/bindings-generator')) + + # save config to file + config = ConfigParser.ConfigParser() + config.set('DEFAULT', 'androidndkdir', ndk_root) + config.set('DEFAULT', 'clangllvmdir', llvm_path) + config.set('DEFAULT', 'cocosdir', cocos_root) + config.set('DEFAULT', 'cxxgeneratordir', cxx_generator_root) + config.set('DEFAULT', 'extra_flags', '') + + # To fix parse error on windows, we must difine __WCHAR_MAX__ and undefine __MINGW32__ . + if platform == 'win32': + config.set('DEFAULT', 'extra_flags', '-D__WCHAR_MAX__=0x7fffffff -U__MINGW32__') + + conf_ini_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'userconf.ini')) + + print 'generating userconf.ini...' + with open(conf_ini_file, 'w') as configfile: + config.write(configfile) + + + # set proper environment variables + if 'linux' in platform or platform == 'darwin': + os.putenv('LD_LIBRARY_PATH', '%s/libclang' % cxx_generator_root) + if platform == 'win32': + path_env = os.environ['PATH'] + os.putenv('PATH', r'%s;%s\libclang;%s\tools\win32;' % (path_env, cxx_generator_root, cxx_generator_root)) + + + try: + + tolua_root = '%s/tools/tolua' % cocos_root + output_dir = '%s/cocos/scripting/auto-generated/lua-bindings' % cocos_root + + cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'lua_cocos2dx_auto'), \ + 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'lua_cocos2dx_extension_auto'), \ + 'cocos2dx_gui.ini' : ('cocos2dx_gui', 'lua_cocos2dx_gui_auto'), \ + 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'lua_cocos2dx_studio_auto'), \ + 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'lua_cocos2dx_spine_auto'), \ + 'cocos2dx_physics.ini' : ('cocos2dx_physics', 'lua_cocos2dx_physics_auto'), \ + } + target = 'lua' + python_bin = sys.executable + generator_py = '%s/generator.py' % cxx_generator_root + for key in cmd_args.keys(): + args = cmd_args[key] + cfg = '%s/%s' % (tolua_root, key) + print 'Generating bindings for %s...' % (key[:-4]) + command = '%s %s %s -s %s -t %s -o %s -n %s' % (python_bin, generator_py, cfg, args[0], target, output_dir, args[1]) + _run_cmd(command) + + if platform == 'win32': + with _pushd(output_dir): + _run_cmd('dos2unix *') + + print '---------------------------------' + print 'Generating bindings succeeds.' + print '---------------------------------' + + except Exception as e: + if e.__class__.__name__ == 'CmdError': + print '---------------------------------' + print 'Generating bindings fails.' + print '---------------------------------' + sys.exit(1) + else: + raise + + +# -------------- main -------------- +if __name__ == '__main__': + main() diff --git a/tools/tolua/genbindings.sh b/tools/tolua/genbindings.sh deleted file mode 100755 index e15de46b1a..0000000000 --- a/tools/tolua/genbindings.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/bash -# -# Usage: -# export NDK_ROOT=/path/to/ndk-r9b -# ./genbindings.sh -# - -# exit this script if any commmand fails -set -e - -# read user.cfg if it exists and is readable - -_CFG_FILE=$(dirname "$0")"/user.cfg" -if [ -f "$_CFG_FILE" ]; -then - if [ ! -r "$_CFG_FILE" ]; then - echo "Fatal Error: $_CFG_FILE exists but is unreadable" - exit 1 - fi -fi - -# paths - -if [ -z "${NDK_ROOT+aaa}" ]; then -# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk" - NDK_ROOT="$HOME/bin/android-ndk" -fi - -if [ -z "${PYTHON_BIN+aaa}" ]; then -# ... if PYTHON_BIN is not set, use "/usr/bin/python2.7" - PYTHON_BIN="/usr/bin/python2.7" -fi - -# find current dir -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# paths with defaults hardcoded to relative paths - -if [ -z "${COCOS2DX_ROOT+aaa}" ]; then - COCOS2DX_ROOT="$DIR/../.." -fi - -if [ -z "${CXX_GENERATOR_ROOT+aaa}" ]; then - CXX_GENERATOR_ROOT="$COCOS2DX_ROOT/tools/bindings-generator" -fi - -if [ -z "${TOLUA_ROOT+aaa}" ]; then - TOLUA_ROOT="$COCOS2DX_ROOT/tools/tolua" -fi - -# set output dir -OUTPUT_DIR=${COCOS2DX_ROOT}/cocos/scripting/auto-generated/lua-bindings - -echo "Paths" -echo " NDK_ROOT: $NDK_ROOT" -echo " PYTHON_BIN: $PYTHON_BIN" -echo " COCOS2DX_ROOT: $COCOS2DX_ROOT" -echo " CXX_GENERATOR_ROOT: $CXX_GENERATOR_ROOT" -echo " TOLUA_ROOT: $TOLUA_ROOT" - -# check NDK version, must be r9b -if ! grep -q r9b $NDK_ROOT/RELEASE.TXT -then - echo " Fatal Error: NDK r9b must be required!" - exit 1 -fi - -# check clang include path -OS_NAME=$('uname') -NDK_LLVM_ROOT=$NDK_ROOT/toolchains/llvm-3.3/prebuilt -case "$OS_NAME" in - Darwin | darwin) - echo "in darwin" - if [ -d "$NDK_LLVM_ROOT/darwin-x86_64" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/darwin-x86_64 - elif [ -d "$NDK_LLVM_ROOT/darwin-x86" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/darwin-x86 - else - echo $NDK_LLVM_ROOT - echo " Fatal Error: $NDK_LLVM_ROOT doesn't contains prebuilt llvm 3.3" - exit 1 - fi - ;; - Linux | linux) - echo "in linux" - if [ -d "$NDK_LLVM_ROOT/linux-x86_64" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/linux-x86_64 - elif [ -d "$NDK_LLVM_ROOT/linux-x86" ]; then - NDK_LLVM_ROOT=$NDK_LLVM_ROOT/linux-x86 - else - echo " Fatal Error: $NDK_LLVM_ROOT doesn't contains prebuilt llvm 3.3" - exit 1 - fi - ;; - *) - echo " Fatal Error: Please run this script in linux or mac osx." - exit 1 - ;; -esac - - -# write userconf.ini - -_CONF_INI_FILE="$PWD/userconf.ini" -if [ -f "$_CONF_INI_FILE" ] -then - rm "$_CONF_INI_FILE" -fi - -_CONTENTS="" -_CONTENTS+="[DEFAULT]"'\n' -_CONTENTS+="androidndkdir=$NDK_ROOT"'\n' -_CONTENTS+="clangllvmdir=$NDK_LLVM_ROOT"'\n' -_CONTENTS+="cocosdir=$COCOS2DX_ROOT"'\n' -_CONTENTS+="cxxgeneratordir=$CXX_GENERATOR_ROOT"'\n' -_CONTENTS+="extra_flags="'\n' - -echo -echo "generating userconf.ini..." -echo --- -echo -e "$_CONTENTS" -echo -e "$_CONTENTS" > "$_CONF_INI_FILE" -echo --- - -# Generate bindings for cocos2dx -echo "Generating bindings for cocos2dx..." -set -x -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOLUA_ROOT}/cocos2dx.ini -s cocos2d-x -t lua -o ${OUTPUT_DIR} -n lua_cocos2dx_auto - -echo "Generating bindings for cocos2dx_extension..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOLUA_ROOT}/cocos2dx_extension.ini -s cocos2dx_extension -t lua -o ${OUTPUT_DIR} -n lua_cocos2dx_extension_auto - -echo "Generating bindings for cocos2dx_gui..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOLUA_ROOT}/cocos2dx_gui.ini -s cocos2dx_gui -t lua -o ${OUTPUT_DIR} -n lua_cocos2dx_gui_auto - -echo "Generating bindings for cocos2dx_studio..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOLUA_ROOT}/cocos2dx_studio.ini -s cocos2dx_studio -t lua -o ${OUTPUT_DIR} -n lua_cocos2dx_studio_auto - -echo "Generating bindings for cocos2dx_spine..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOLUA_ROOT}/cocos2dx_spine.ini -s cocos2dx_spine -t lua -o ${OUTPUT_DIR} -n lua_cocos2dx_spine_auto - -echo "Generating bindings for cocos2dx_physics..." -LD_LIBRARY_PATH=${CXX_GENERATOR_ROOT}/libclang $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TOLUA_ROOT}/cocos2dx_physics.ini -s cocos2dx_physics -t lua -o ${OUTPUT_DIR} -n lua_cocos2dx_physics_auto - From b06d54f70663ed1512146b6eb44c436ae63bf7fa Mon Sep 17 00:00:00 2001 From: lihex Date: Mon, 10 Feb 2014 12:50:23 +0800 Subject: [PATCH 2/7] issue #3781, use custom python executeable if PYTHON_BIN defined --- tools/tojs/genbindings.py | 21 +++++++++++++++++---- tools/tolua/genbindings.py | 21 +++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/tools/tojs/genbindings.py b/tools/tojs/genbindings.py index 699a3f8b75..885d4277a1 100644 --- a/tools/tojs/genbindings.py +++ b/tools/tojs/genbindings.py @@ -13,18 +13,31 @@ import re from contextlib import contextmanager -def _check_environment_variables(): +def _check_ndk_root_env(): ''' Checking the environment NDK_ROOT, which will be used for building ''' try: NDK_ROOT = os.environ['NDK_ROOT'] except Exception: - print "NDK_ROOT not defined. Please define NDK_ROOT in your environment" + print "NDK_ROOT not defined. Please define NDK_ROOT in your environment." sys.exit(1) return NDK_ROOT +def _check_python_bin_env(): + ''' Checking the environment PYTHON_BIN, which will be used for building + ''' + + try: + PYTHON_BIN = os.environ['PYTHON_BIN'] + except Exception: + print "PYTHON_BIN not defined, use current python." + PYTHON_BIN = sys.executable + + return PYTHON_BIN + + class CmdError(Exception): pass @@ -46,9 +59,10 @@ def main(): cur_platform= '??' llvm_path = '??' - ndk_root = _check_environment_variables() + ndk_root = _check_ndk_root_env() # del the " in the path ndk_root = re.sub(r"\"", "", ndk_root) + python_bin = _check_python_bin_env() platform = sys.platform if platform == 'win32': @@ -116,7 +130,6 @@ def main(): 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'jsb_cocos2dx_spine_auto'), \ } target = 'spidermonkey' - python_bin = sys.executable generator_py = '%s/generator.py' % cxx_generator_root for key in cmd_args.keys(): args = cmd_args[key] diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index 7496cba4de..5c7f5af234 100644 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -13,18 +13,31 @@ import re from contextlib import contextmanager -def _check_environment_variables(): +def _check_ndk_root_env(): ''' Checking the environment NDK_ROOT, which will be used for building ''' try: NDK_ROOT = os.environ['NDK_ROOT'] except Exception: - print "NDK_ROOT not defined. Please define NDK_ROOT in your environment" + print "NDK_ROOT not defined. Please define NDK_ROOT in your environment." sys.exit(1) return NDK_ROOT +def _check_python_bin_env(): + ''' Checking the environment PYTHON_BIN, which will be used for building + ''' + + try: + PYTHON_BIN = os.environ['PYTHON_BIN'] + except Exception: + print "PYTHON_BIN not defined, use current python." + PYTHON_BIN = sys.executable + + return PYTHON_BIN + + class CmdError(Exception): pass @@ -46,9 +59,10 @@ def main(): cur_platform= '??' llvm_path = '??' - ndk_root = _check_environment_variables() + ndk_root = _check_ndk_root_env() # del the " in the path ndk_root = re.sub(r"\"", "", ndk_root) + python_bin = _check_python_bin_env() platform = sys.platform if platform == 'win32': @@ -116,7 +130,6 @@ def main(): 'cocos2dx_physics.ini' : ('cocos2dx_physics', 'lua_cocos2dx_physics_auto'), \ } target = 'lua' - python_bin = sys.executable generator_py = '%s/generator.py' % cxx_generator_root for key in cmd_args.keys(): args = cmd_args[key] From c97b6cb197dfa076332bb1e816388edf0049c9dd Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 10 Feb 2014 18:30:22 +0800 Subject: [PATCH 3/7] Uses genbindings.py instead of genbindings.sh and genbindings.bat. --- tools/tojs/genbindings.py | 0 tools/tolua/genbindings.py | 0 tools/travis-scripts/generate-jsbindings.sh | 6 +++--- 3 files changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 tools/tojs/genbindings.py mode change 100644 => 100755 tools/tolua/genbindings.py diff --git a/tools/tojs/genbindings.py b/tools/tojs/genbindings.py old mode 100644 new mode 100755 diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py old mode 100644 new mode 100755 diff --git a/tools/travis-scripts/generate-jsbindings.sh b/tools/travis-scripts/generate-jsbindings.sh index cd7f897e20..a8d3f3ab9f 100755 --- a/tools/travis-scripts/generate-jsbindings.sh +++ b/tools/travis-scripts/generate-jsbindings.sh @@ -8,7 +8,7 @@ # Dependencies # # For bindings generator: -# (see ../../../tojs/genbindings.sh and ../../../tolua/genbindings.sh +# (see ../../../tojs/genbindings.py and ../../../tolua/genbindings.py # ... for the defaults used if the environment is not customized) # # * $PYTHON_BIN @@ -47,12 +47,12 @@ generate_bindings_glue_codes() { echo "Create auto-generated jsbinding glue codes." pushd "$TOJS_ROOT" - ./genbindings.sh + ./genbindings.py popd echo "Create auto-generated luabinding glue codes." pushd "$TOLUA_ROOT" - ./genbindings.sh + ./genbindings.py popd } From d844f4f2514c904d8e1f0e9a21d8ec666126780c Mon Sep 17 00:00:00 2001 From: lm Date: Mon, 10 Feb 2014 19:18:27 +0800 Subject: [PATCH 4/7] [Jenkins] use python script instead for auto generating binding --- tools/jenkins-scripts/gen_jsb.py | 9 +++ tools/jenkins-scripts/gen_jsb.sh | 58 ------------------- tools/jenkins-scripts/gen_jsb_win32.bat | 36 ------------ tools/jenkins-scripts/pull-request-builder.py | 8 +-- 4 files changed, 10 insertions(+), 101 deletions(-) create mode 100644 tools/jenkins-scripts/gen_jsb.py delete mode 100755 tools/jenkins-scripts/gen_jsb.sh delete mode 100644 tools/jenkins-scripts/gen_jsb_win32.bat diff --git a/tools/jenkins-scripts/gen_jsb.py b/tools/jenkins-scripts/gen_jsb.py new file mode 100644 index 0000000000..9a43ce0747 --- /dev/null +++ b/tools/jenkins-scripts/gen_jsb.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +import os + +genbindings_dirs = ['tojs', 'tolua'] +for item in genbindings_dirs: + os.chdir("tools/" + item) + os.system('python genbindings.py') + os.chdir("../..") diff --git a/tools/jenkins-scripts/gen_jsb.sh b/tools/jenkins-scripts/gen_jsb.sh deleted file mode 100755 index 1e8fc1b084..0000000000 --- a/tools/jenkins-scripts/gen_jsb.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Generate JS and Lua 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 and ../../../tolua/genbindings.sh -# ... for the defaults used if the environment is not customized) -# -# * $PYTHON_BIN -# * $CLANG_ROOT -# * $NDK_ROOT -# -echo "[test]start generate js binding..." -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -COCOS2DX_ROOT="$DIR"/../.. -TOJS_ROOT=$COCOS2DX_ROOT/tools/tojs -TOLUA_ROOT=$COCOS2DX_ROOT/tools/tolua -GENERATED_WORKTREE="$COCOS2DX_ROOT"/cocos/scripting/auto-generated - - -# Exit on error -set -e - -generate_bindings_glue_codes() -{ - echo "Create auto-generated jsbinding glue codes." - pushd "$TOJS_ROOT" - ./genbindings.sh - popd - - echo "Create auto-generated luabinding glue codes." - pushd "$TOLUA_ROOT" - ./genbindings.sh - popd -} - -# Update submodule of auto-gen Binding repo. -pushd "$GENERATED_WORKTREE" - -echo "Delete all directories and files except '.git' and 'README.md'." -ls -a | grep -E -v ^\[.\]\{1,2\}$ | grep -E -v ^\.git$ | grep -E -v ^README\.md$ | xargs -I{} rm -rf {} -popd - - - -# 1. Generate JS bindings -generate_bindings_glue_codes - -echo -echo Bindings generated successfully -echo - - diff --git a/tools/jenkins-scripts/gen_jsb_win32.bat b/tools/jenkins-scripts/gen_jsb_win32.bat deleted file mode 100644 index 872ad9a4c4..0000000000 --- a/tools/jenkins-scripts/gen_jsb_win32.bat +++ /dev/null @@ -1,36 +0,0 @@ -@echo off - -::!/bin/bash - -:: Generate JS and Lua 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 and ../../../tolua/genbindings-win32.bat -:: ... for the defaults used if the environment is not customized) -:: -:: * $PYTHON_BIN -:: * $CLANG_ROOT -:: * $NDK_ROOT -:: -echo "[test]start generate js binding..." -set COCOS2DX_ROOT=%cd%/../.. -set "COCOS2DX_ROOT=%COCOS2DX_ROOT:\=/%" -set TO_JS_ROOT=%COCOS2DX_ROOT%/tools/tojs -set TO_LUA_ROOT=%COCOS2DX_ROOT%/tools/tolua -set GENERATED_WORKTREE=%COCOS2DX_ROOT%/cocos/scripting/auto-generated -set "GENERATED_WORKTREE=%GENERATED_WORKTREE:/=\%" - -:: Run to_js genbindings -call %TO_JS_ROOT%/genbindings-win32.bat - -:: Run to_lua genbindings -call %TO_LUA_ROOT%/genbindings-win32.bat - -echo -echo Bindings generated successfully -echo \ No newline at end of file diff --git a/tools/jenkins-scripts/pull-request-builder.py b/tools/jenkins-scripts/pull-request-builder.py index a6fb9aa65c..0337d6e33f 100755 --- a/tools/jenkins-scripts/pull-request-builder.py +++ b/tools/jenkins-scripts/pull-request-builder.py @@ -93,13 +93,7 @@ def main(): os.system(git_update_submodule) # Generate binding glue codes - if(branch == 'develop'): - if(platform.system() == 'Darwin'): - os.system("tools/jenkins-scripts/gen_jsb.sh") - elif(platform.system() == 'Windows'): - os.chdir("tools/jenkins-scripts") - os.system("gen_jsb_win32.bat") - os.chdir("../..") + os.system("python tools/jenkins-scripts/gen_jsb.py") #make temp dir print "current dir is" + os.environ['WORKSPACE'] From 69bc32a21d07e1b151a971886a0b02a9f5625c9d Mon Sep 17 00:00:00 2001 From: lihex Date: Tue, 11 Feb 2014 10:02:59 +0800 Subject: [PATCH 5/7] Fix path on use 32bit windows ndk --- tools/tojs/genbindings.py | 5 ++++- tools/tolua/genbindings.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/tojs/genbindings.py b/tools/tojs/genbindings.py index 885d4277a1..3008534cd4 100755 --- a/tools/tojs/genbindings.py +++ b/tools/tojs/genbindings.py @@ -75,7 +75,10 @@ def main(): print 'Your platform is not supported!' sys.exit(1) - x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86'))) + if platform == 'win32': + x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s' % cur_platform)) + else: + x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86'))) x64_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86_64'))) if os.path.isdir(x86_llvm_path): diff --git a/tools/tolua/genbindings.py b/tools/tolua/genbindings.py index 5c7f5af234..cc7d0dacea 100755 --- a/tools/tolua/genbindings.py +++ b/tools/tolua/genbindings.py @@ -75,7 +75,10 @@ def main(): print 'Your platform is not supported!' sys.exit(1) - x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86'))) + if platform == 'win32': + x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s' % cur_platform)) + else: + x86_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86'))) x64_llvm_path = os.path.abspath(os.path.join(ndk_root, 'toolchains/llvm-3.3/prebuilt', '%s-%s' % (cur_platform, 'x86_64'))) if os.path.isdir(x86_llvm_path): From d8f89b80454671e4b028e1613f24c47e789266de Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 11 Feb 2014 14:02:34 +0800 Subject: [PATCH 6/7] Exports PYTHON_BIN variable. --- tools/travis-scripts/run-script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh index d7c938d702..534bfcfc0f 100755 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -27,6 +27,7 @@ if [ "$GEN_JSB"x = "YES"x ]; then exit 0 fi export NDK_ROOT=$HOME/bin/android-ndk + export PYTHON_BIN=/usr/bin/python cd $COCOS2DX_ROOT/tools/travis-scripts ./generate-jsbindings.sh elif [ "$PLATFORM"x = "android"x ]; then From d779aaa967b1eef7a4fbe0e52c0952e950a40589 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 11 Feb 2014 14:12:13 +0800 Subject: [PATCH 7/7] Defines NDK_ROOT and PYTHON_BIN in top level. --- tools/travis-scripts/run-script.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh index 534bfcfc0f..af628c3160 100755 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -5,6 +5,9 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" COCOS2DX_ROOT="$DIR"/../.. +export NDK_ROOT=$HOME/bin/android-ndk +export PYTHON_BIN=/usr/bin/python + if [ "$GEN_JSB"x = "YES"x ]; then # 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 @@ -26,8 +29,7 @@ if [ "$GEN_JSB"x = "YES"x ]; then echo "GH_USER not set" exit 0 fi - export NDK_ROOT=$HOME/bin/android-ndk - export PYTHON_BIN=/usr/bin/python + cd $COCOS2DX_ROOT/tools/travis-scripts ./generate-jsbindings.sh elif [ "$PLATFORM"x = "android"x ]; then