From a1e8dec3840b3042054f04b3197da81412b29cae Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 30 Dec 2014 16:24:16 +0800 Subject: [PATCH 1/5] use cocos console in build_native.py and android-build.py --- build/android-build.py | 206 ++---------------- .../proj.android/build_native.py | 128 +---------- 2 files changed, 30 insertions(+), 304 deletions(-) diff --git a/build/android-build.py b/build/android-build.py index 58640879da..021dc795a2 100755 --- a/build/android-build.py +++ b/build/android-build.py @@ -11,78 +11,6 @@ CPP_SAMPLES = ['cpp-empty-test', 'cpp-tests', 'game-controller-test'] LUA_SAMPLES = ['lua-empty-test', 'lua-tests', 'lua-game-controller-test'] ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES -class BUILD_CONSTANT: - SDK_ROOT = None - COCOS_ROOT = None - NDK_BUILD_COMMAND = None - -def initBuildConstant(ndk_build_param, build_mode): - ''' Checking the environment NDK_ROOT, which will be used for building - ''' - try: - ndk_root = os.environ['NDK_ROOT'] - ndk_build_path = os.path.join(ndk_root, "ndk-build") - except Exception: - print "NDK_ROOT not defined. Please define NDK_ROOT in your environment" - sys.exit(1) - - toolchainVersion = '4.8' - try: - versionFile = open(os.path.join(ndk_root, "RELEASE.TXT")) - firstLine = versionFile.readline() - if firstLine : - ndkVersion = firstLine[firstLine.index('r') : firstLine.index(' ')] - ndkVersionValue = int(filter(str.isdigit,ndkVersion)) - if ndkVersionValue < 10 or cmp(ndkVersion,'r10c') < 0 : - print '''Please use NDK r10c above. -If you do not,your application may crash or freeze on Android L(5.0) when use BMFont and HttpClient. -For More information: - https://github.com/cocos2d/cocos2d-x/issues/9114 - https://github.com/cocos2d/cocos2d-x/issues/9138\n''' - else: - toolchainVersion = '4.9' - versionFile.close() - except Exception: - print "Can not be determined your NDK version" - - if toolchainVersion == '4.8': - print 'NDK_TOOLCHAIN_VERSION is 4.8,your application may crash on Androud when use c++ 11 regular\n' - - current_dir = os.path.dirname(os.path.realpath(__file__)) - cocos_root = os.path.join(current_dir, "..") - BUILD_CONSTANT.COCOS_ROOT = cocos_root - - # windows should use ";" to seperate module paths - platform = sys.platform - if platform == 'win32': - ndk_module_path = 'NDK_MODULE_PATH=%s;%s/external;%s/cocos' % (cocos_root, cocos_root, cocos_root) - else: - ndk_module_path = 'NDK_MODULE_PATH=%s:%s/external:%s/cocos' % (cocos_root, cocos_root, cocos_root) - - ''' The build process can be accelerated by running multiple concurrent job processes using the -j-option. - ''' - try: - import multiprocessing - num_of_cpu = multiprocessing.cpu_count() - except Exception: - print "Can't know cpuinfo, use default 1 cpu" - num_of_cpu = 1 - - if ndk_build_param == None: - BUILD_CONSTANT.NDK_BUILD_COMMAND = '%s -j%d NDK_DEBUG=%d %s NDK_TOOLCHAIN_VERSION=%s' % (ndk_build_path, num_of_cpu, build_mode=='debug', ndk_module_path, toolchainVersion) - else: - BUILD_CONSTANT.NDK_BUILD_COMMAND = '%s -j%d NDK_DEBUG=%d %s %s NDK_TOOLCHAIN_VERSION=%s' % (ndk_build_path, num_of_cpu, build_mode=='debug', ndk_build_param, ndk_module_path, toolchainVersion) - -def check_environment_variables_sdk(): - ''' Checking the environment ANDROID_SDK_ROOT, which will be used for building - ''' - - try: - BUILD_CONSTANT.SDK_ROOT = os.environ['ANDROID_SDK_ROOT'] - except Exception: - print "ANDROID_SDK_ROOT not defined. Please define ANDROID_SDK_ROOT in your environment" - sys.exit(1) - def caculate_built_samples(args): ''' Compute the sampels to be built 'cpp' for short of all cpp tests @@ -107,137 +35,44 @@ def caculate_built_samples(args): targets = set(targets) return list(targets) -def do_build(app_android_root, android_platform, build_mode): - command = '%s -C %s' % (BUILD_CONSTANT.NDK_BUILD_COMMAND, app_android_root) +def do_build(app_android_root, build_mode): + + command = 'cocos compile -p android -s %s -m %s' % (app_android_root, build_mode) print command + if os.system(command) != 0: raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") - elif android_platform is not None: - sdk_tool_path = os.path.join(BUILD_CONSTANT.SDK_ROOT, "tools/android") - cocoslib_path = os.path.join(BUILD_CONSTANT.COCOS_ROOT, "cocos/platform/android/java") - command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path) - if os.system(command) != 0: - raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!") - command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root) - if os.system(command) != 0: - raise Exception("update project [ " + app_android_root + " ] fails!") - buildfile_path = os.path.join(app_android_root, "build.xml") - command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,BUILD_CONSTANT.SDK_ROOT) - os.system(command) -def copy_files(src, dst): - - for item in os.listdir(src): - path = os.path.join(src, item) - # Android can not package the file that ends with ".gz" - if not item.startswith('.') and not item.endswith('.gz') and os.path.isfile(path): - shutil.copy(path, dst) - if os.path.isdir(path): - new_dst = os.path.join(dst, item) - os.mkdir(new_dst) - copy_files(path, new_dst) - -def copy_file(src_file, dst): - if not src_file.startswith('.') and not src_file.endswith('.gz') and os.path.isfile(src_file): - shutil.copy(src_file, dst) - -def copy_resources(target, app_android_root): - - # remove app_android_root/assets if it exists - assets_dir = os.path.join(app_android_root, "assets") - if os.path.isdir(assets_dir): - shutil.rmtree(assets_dir) - - os.mkdir(assets_dir) - - # copy resources(cpp samples) - if target in CPP_SAMPLES: - resources_dir = os.path.join(app_android_root, "../Resources") - if os.path.isdir(resources_dir): - copy_files(resources_dir, assets_dir) - - - # lua samples should copy lua script - if target in LUA_SAMPLES: - resources_dir = os.path.join(app_android_root, "../../res") - assets_res_dir = os.path.join(assets_dir, "res") - os.mkdir(assets_res_dir) - - if target != "lua-tests": - copy_files(resources_dir, assets_res_dir) - - src_dir = os.path.join(app_android_root, "../../src") - assets_src_dir = os.path.join(assets_dir, "src") - os.mkdir(assets_src_dir) - copy_files(src_dir, assets_src_dir) - - common_script_dir = os.path.join(app_android_root, "../../../../cocos/scripting/lua-bindings/script/") - cocos_src_dir = os.path.join(assets_src_dir,"cocos") - if os.path.exists(cocos_src_dir): - shutil.rmtree(cocos_src_dir) - os.mkdir(cocos_src_dir) - copy_files(common_script_dir, cocos_src_dir) - - luasocket_script_dir = os.path.join(app_android_root, "../../../../external/lua/luasocket") - for root, dirs, files in os.walk(luasocket_script_dir): - for f in files: - if os.path.splitext(f)[1] == '.lua': - fall = os.path.join(root, f) - shutil.copy(fall, assets_dir) - - # lua-tests shared resources with cpp-tests - if target == "lua-tests": - resources_cocosbuilder_res_dir = os.path.join(resources_dir, "cocosbuilderRes") - assets_cocosbuilder_res_dir = os.path.join(assets_res_dir, "cocosbuilderRes") - os.mkdir(assets_cocosbuilder_res_dir) - copy_files(resources_cocosbuilder_res_dir, assets_cocosbuilder_res_dir) - - resources_dir = os.path.join(app_android_root, "../../../cpp-tests/Resources") - copy_files(resources_dir, assets_res_dir) - if target == "lua-game-controller-test": - print("coming generator game controller") - resources_dir = os.path.join(app_android_root, "../../../game-controller-test/Resources") - copy_files(resources_dir, assets_res_dir) - -def build_samples(target,ndk_build_param,android_platform,build_mode): +def build_samples(target, build_mode): if build_mode is None: build_mode = 'debug' elif build_mode != 'release': build_mode = 'debug' - - initBuildConstant(ndk_build_param, build_mode) build_targets = caculate_built_samples(target) - - if android_platform is not None: - check_environment_variables_sdk() - if android_platform.isdigit(): - android_platform = 'android-'+android_platform - else: - print 'please use vaild android platform' - exit(1) app_android_root = '' target_proj_path_map = { - "cpp-empty-test": "tests/cpp-empty-test/proj.android", - "game-controller-test": "tests/game-controller-test/proj.android", - "cpp-tests": "tests/cpp-tests/proj.android", - "lua-empty-test": "tests/lua-empty-test/project/proj.android", - "lua-tests": "tests/lua-tests/project/proj.android", - "lua-game-controller-test": "tests/lua-game-controller-test/project/proj.android" + "cpp-empty-test": "tests/cpp-empty-test", + "game-controller-test": "tests/game-controller-test", + "cpp-tests": "tests/cpp-tests", + "lua-empty-test": "tests/lua-empty-test", + "lua-tests": "tests/lua-tests", + "lua-game-controller-test": "tests/lua-game-controller-test" } + cocos_root = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") + for target in build_targets: if target in target_proj_path_map: - app_android_root = os.path.join(BUILD_CONSTANT.COCOS_ROOT, target_proj_path_map[target]) + app_android_root = os.path.join(cocos_root, target_proj_path_map[target]) else: print 'unknown target: %s' % target continue - copy_resources(target, app_android_root) - do_build(app_android_root, android_platform, build_mode) + do_build(app_android_root, build_mode) # -------------- main -------------- if __name__ == '__main__': @@ -252,28 +87,25 @@ if __name__ == '__main__': You can combine these targets like this: - python android-build.py -p 10 cpp-empty-test lua-empty-test + python android-build.py cpp-empty-test lua-empty-test - - Note: You should install ant to generate apk while building the andriod tests. But it is optional. You can generate apk with eclipse. """ parser = OptionParser(usage=usage) parser.add_option("-n", "--ndk", dest="ndk_build_param", - help='Parameter for ndk-build') + help='It is not used anymore, because cocos console does not support it.') parser.add_option("-p", "--platform", dest="android_platform", - help='Parameter for android-update. Without the parameter,the script just build dynamic library for the projects. Valid android-platform are:[10|11|12|13|14|15|16|17|18|19]') + help='This parameter is not used any more, just keep compatible.') parser.add_option("-b", "--build", dest="build_mode", help='The build mode for java project,debug[default] or release. Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html') (opts, args) = parser.parse_args() - print "We will use cocos console to build tests built-in with cocos2d-x and remove this script next version.\n" if len(args) == 0: parser.print_help() sys.exit(1) else: try: - build_samples(args, opts.ndk_build_param,opts.android_platform,opts.build_mode) + build_samples(args, opts.build_mode) except Exception as e: print e sys.exit(1) diff --git a/templates/cpp-template-default/proj.android/build_native.py b/templates/cpp-template-default/proj.android/build_native.py index fdcdf9b0ac..4c4026544a 100755 --- a/templates/cpp-template-default/proj.android/build_native.py +++ b/templates/cpp-template-default/proj.android/build_native.py @@ -1,6 +1,8 @@ #!/usr/bin/python # build_native.py # Build native codes +# +# Please use cocos console instead import sys @@ -8,142 +10,34 @@ import os, os.path import shutil from optparse import OptionParser -def get_num_of_cpu(): - ''' The build process can be accelerated by running multiple concurrent job processes using the -j-option. - ''' - try: - import multiprocessing - return multiprocessing.cpu_count() - except Exception: - print "Can't know cpuinfo, use default 1 cpu" - return 1 +def build(build_mode): -def check_environment_variables_sdk(): - ''' Checking the environment ANDROID_SDK_ROOT, which will be used for building - ''' - - try: - SDK_ROOT = os.environ['ANDROID_SDK_ROOT'] - except Exception: - print "ANDROID_SDK_ROOT not defined. Please define ANDROID_SDK_ROOT in your environment" - sys.exit(1) - - return SDK_ROOT - -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 - -def select_toolchain_version(): - - ndk_root = check_environment_variables() - if os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.9")): - os.environ['NDK_TOOLCHAIN_VERSION'] = '4.9' - print "The Selected NDK toolchain version was 4.9 !" - elif os.path.isdir(os.path.join(ndk_root,"toolchains/arm-linux-androideabi-4.8")): - os.environ['NDK_TOOLCHAIN_VERSION'] = '4.8' - print "The Selected NDK toolchain version was 4.8 !" - else: - print "Couldn't find the gcc toolchain." - exit(1) - -def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode): - - ndk_path = os.path.join(ndk_root, "ndk-build") - - num_of_cpu = get_num_of_cpu() - - app_android_root = app_android_root.replace(' ', '\\ ') - if ndk_build_param == None: - command = '%s -j%d -C %s NDK_DEBUG=%d' % (ndk_path, num_of_cpu, app_android_root, build_mode=='debug') - else: - command = '%s -j%d -C %s NDK_DEBUG=%d %s' % (ndk_path, num_of_cpu, app_android_root, build_mode=='debug', ' '.join(str(e) for e in ndk_build_param)) - if os.system(command) != 0: - raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") - elif android_platform is not None: - sdk_tool_path = os.path.join(sdk_root, "tools/android") - cocoslib_path = os.path.join(cocos_root, "cocos/platform/android/java") - command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path) - if os.system(command) != 0: - raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!") - command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root) - if os.system(command) != 0: - raise Exception("update project [ " + app_android_root + " ] fails!") - buildfile_path = os.path.join(app_android_root, "build.xml") - command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,sdk_root) - os.system(command) - -def copy_files(src, dst): - - for item in os.listdir(src): - path = os.path.join(src, item) - # Android can not package the file that ends with ".gz" - if not item.startswith('.') and not item.endswith('.gz') and os.path.isfile(path): - shutil.copy(path, dst) - if os.path.isdir(path): - new_dst = os.path.join(dst, item) - os.mkdir(new_dst) - copy_files(path, new_dst) - -def copy_resources(app_android_root): - - # remove app_android_root/assets if it exists - assets_dir = os.path.join(app_android_root, "assets") - if os.path.isdir(assets_dir): - shutil.rmtree(assets_dir) - - # copy resources - os.mkdir(assets_dir) - resources_dir = os.path.join(app_android_root, "../Resources") - if os.path.isdir(resources_dir): - copy_files(resources_dir, assets_dir) - -def build(ndk_build_param,android_platform,build_mode): - - ndk_root = check_environment_variables() - sdk_root = None - select_toolchain_version() current_dir = os.path.dirname(os.path.realpath(__file__)) cocos_root = os.path.join(current_dir, "../cocos2d") - app_android_root = current_dir - copy_resources(app_android_root) - - if android_platform is not None: - sdk_root = check_environment_variables_sdk() - if android_platform.isdigit(): - android_platform = 'android-'+android_platform - else: - print 'please use vaild android platform' - exit(1) + app_android_root = os.path.join(current_dir, "../") if build_mode is None: build_mode = 'debug' elif build_mode != 'release': build_mode = 'debug' - do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode) + command = 'cocos compile -p android -s %s -m %s' % (app_android_root, build_mode) + if os.system(command) != 0: + raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") # -------------- main -------------- if __name__ == '__main__': parser = OptionParser() - parser.add_option("-n", "--ndk", dest="ndk_build_param", help='parameter for ndk-build', action="append") + parser.add_option("-n", "--ndk", dest="ndk_build_param", help='it is not used', action="append") parser.add_option("-p", "--platform", dest="android_platform", - help='parameter for android-update.Without the parameter,the script just build dynamic library for project. Valid android-platform are:[10|11|12|13|14|15|16|17|18|19]') + help='it is not used') parser.add_option("-b", "--build", dest="build_mode", help='the build mode for java project,debug[default] or release.Get more information,please refer to http://developer.android.com/tools/building/building-cmdline.html') (opts, args) = parser.parse_args() - print "We will remove this script next version,you should use cocos console to build android project.\n" + print "Please use cocos console instead.\n" - build(opts.ndk_build_param,opts.android_platform,opts.build_mode) + build(opts.build_mode) From bcbfc91bcd2085d0d70f6a9a4fe86e9851f1502c Mon Sep 17 00:00:00 2001 From: Wenhai Lin Date: Wed, 28 Jan 2015 17:37:31 +0800 Subject: [PATCH 2/5] Fixed game controller test can't compile by cocos command --- tests/game-controller-test/.cocos-project.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/game-controller-test/.cocos-project.json diff --git a/tests/game-controller-test/.cocos-project.json b/tests/game-controller-test/.cocos-project.json new file mode 100644 index 0000000000..91621fd443 --- /dev/null +++ b/tests/game-controller-test/.cocos-project.json @@ -0,0 +1,12 @@ +{ + "ios_cfg": { + "project_path": "../../build", + "project_file": "cocos2d_tests.xcodeproj", + "target_name": "game-controller-test IOS" + }, + "project_type": "cpp", + "android_cfg": { + "project_path": "proj.android" + }, + "engine_dir": "../../" +} From b8e50da05ebfb114f2f36f170febcef9ab1424f8 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 29 Jan 2015 14:01:11 +0800 Subject: [PATCH 3/5] only build c++ codes --- build/android-build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/android-build.py b/build/android-build.py index 021dc795a2..47ffe5930e 100755 --- a/build/android-build.py +++ b/build/android-build.py @@ -37,7 +37,7 @@ def caculate_built_samples(args): def do_build(app_android_root, build_mode): - command = 'cocos compile -p android -s %s -m %s' % (app_android_root, build_mode) + command = 'cocos compile -p android -s %s --ndk-mode %s' % (app_android_root, build_mode) print command if os.system(command) != 0: From d2836a62af19ecb1829e37a73f8e1e39ad095786 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 13 Feb 2015 18:06:14 +0800 Subject: [PATCH 4/5] revert submodule --- tests/cpp-tests/Resources/ccs-res | 2 +- tools/bindings-generator | 2 +- tools/cocos2d-console | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cpp-tests/Resources/ccs-res b/tests/cpp-tests/Resources/ccs-res index 3a3364d79f..ce5606d4e5 160000 --- a/tests/cpp-tests/Resources/ccs-res +++ b/tests/cpp-tests/Resources/ccs-res @@ -1 +1 @@ -Subproject commit 3a3364d79fe4c8fa6487b65edf7a2104a496903e +Subproject commit ce5606d4e520d2671a678b0ba3d5a0b84fdb5ab9 diff --git a/tools/bindings-generator b/tools/bindings-generator index 3b956b46cc..d20bd95b52 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 3b956b46cc683f81d69811b3016810c1a93ad5f1 +Subproject commit d20bd95b520374565d2c12b37f9fefc732f41891 diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 9e918bb278..cd05722966 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 9e918bb2785d470b1a661b889b8c1715220c9561 +Subproject commit cd05722966edde6116a6096b810a7a5598fe7c0a From 1a7ae32088e5b7cdcdc01279b3837fa67a90c3ca Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 13 Feb 2015 18:08:03 +0800 Subject: [PATCH 5/5] rever submodule --- plugin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin b/plugin index d62bf51849..dc25546289 160000 --- a/plugin +++ b/plugin @@ -1 +1 @@ -Subproject commit d62bf5184903f3f8b442190d477f7c8571682b7e +Subproject commit dc25546289ab18dd273199124dada948638eb5e1