mirror of https://github.com/axmolengine/axmol.git
Some fixes for android-build.py.
This commit is contained in:
parent
a7fea5bdb7
commit
b893ca3378
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
# android-build.py
|
||||
# Build android
|
||||
# Build android
|
||||
|
||||
import sys
|
||||
import os, os.path
|
||||
|
@ -12,21 +12,21 @@ LUA_SAMPLES = ['lua-empty-test', 'lua-tests']
|
|||
ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES
|
||||
|
||||
def get_num_of_cpu():
|
||||
''' The build process can be accelerated by running multiple concurrent job processes using the -j-option.
|
||||
'''
|
||||
try:
|
||||
platform = sys.platform
|
||||
if platform == 'win32':
|
||||
if 'NUMBER_OF_PROCESSORS' in os.environ:
|
||||
return int(os.environ['NUMBER_OF_PROCESSORS'])
|
||||
else:
|
||||
return 1
|
||||
else:
|
||||
from numpy.distutils import cpuinfo
|
||||
return cpuinfo.cpu._getNCPUs()
|
||||
except Exception:
|
||||
print "Can't know cpuinfo, use default 1 cpu"
|
||||
return 1
|
||||
''' The build process can be accelerated by running multiple concurrent job processes using the -j-option.
|
||||
'''
|
||||
try:
|
||||
platform = sys.platform
|
||||
if platform == 'win32':
|
||||
if 'NUMBER_OF_PROCESSORS' in os.environ:
|
||||
return int(os.environ['NUMBER_OF_PROCESSORS'])
|
||||
else:
|
||||
return 1
|
||||
else:
|
||||
from numpy.distutils import cpuinfo
|
||||
return cpuinfo.cpu._getNCPUs()
|
||||
except Exception:
|
||||
print "Can't know cpuinfo, use default 1 cpu"
|
||||
return 1
|
||||
|
||||
def check_environment_variables():
|
||||
''' Checking the environment NDK_ROOT, which will be used for building
|
||||
|
@ -39,7 +39,7 @@ def check_environment_variables():
|
|||
sys.exit(1)
|
||||
|
||||
return NDK_ROOT
|
||||
|
||||
|
||||
def check_environment_variables_sdk():
|
||||
''' Checking the environment ANDROID_SDK_ROOT, which will be used for building
|
||||
'''
|
||||
|
@ -74,7 +74,7 @@ def select_toolchain_version():
|
|||
def caculate_built_samples(args):
|
||||
''' Compute the sampels to be built
|
||||
'cpp' for short of all cpp tests
|
||||
'lua' for short of all lua tests
|
||||
'lua' for short of all lua tests
|
||||
'''
|
||||
|
||||
if 'all' in args:
|
||||
|
@ -115,17 +115,17 @@ def do_build(cocos_root, ndk_root, app_android_root, ndk_build_param,sdk_root,an
|
|||
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/2d/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)
|
||||
sdk_tool_path = os.path.join(sdk_root, "tools/android")
|
||||
cocoslib_path = os.path.join(cocos_root, "cocos/2d/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):
|
||||
|
||||
|
@ -166,7 +166,7 @@ def copy_resources(target, app_android_root):
|
|||
assets_src_dir = os.path.join(assets_dir, "src");
|
||||
os.mkdir(assets_src_dir)
|
||||
copy_files(resources_dir, assets_src_dir)
|
||||
|
||||
|
||||
resources_dir = os.path.join(app_android_root, "../../../../cocos/scripting/lua-bindings/script")
|
||||
copy_files(resources_dir, assets_dir)
|
||||
|
||||
|
@ -184,20 +184,20 @@ def build_samples(target,ndk_build_param,android_platform,build_mode):
|
|||
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
cocos_root = os.path.join(current_dir, "..")
|
||||
|
||||
|
||||
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)
|
||||
|
||||
sdk_root = check_environment_variables_sdk()
|
||||
if android_platform.isdigit():
|
||||
android_platform = 'android-'+android_platform
|
||||
else:
|
||||
print 'please use vaild android platform'
|
||||
exit(1)
|
||||
|
||||
if build_mode is None:
|
||||
build_mode = 'debug'
|
||||
build_mode = 'debug'
|
||||
elif build_mode != 'release':
|
||||
build_mode = 'debug'
|
||||
|
||||
|
||||
app_android_root = ''
|
||||
|
||||
target_proj_path_map = {
|
||||
|
@ -214,8 +214,8 @@ def build_samples(target,ndk_build_param,android_platform,build_mode):
|
|||
print 'unknown target: %s' % target
|
||||
continue
|
||||
|
||||
copy_resources(target, app_android_root)
|
||||
do_build(cocos_root, ndk_root, app_android_root, ndk_build_param,sdk_root,android_platform,build_mode)
|
||||
copy_resources(target, app_android_root)
|
||||
do_build(cocos_root, ndk_root, app_android_root, ndk_build_param,sdk_root,android_platform,build_mode)
|
||||
|
||||
# -------------- main --------------
|
||||
if __name__ == '__main__':
|
||||
|
@ -223,8 +223,8 @@ if __name__ == '__main__':
|
|||
#parse the params
|
||||
usage = """
|
||||
This script is mainy used for building tests built-in with cocos2d-x.
|
||||
|
||||
Usage: %prog [options] [cpp-empty-test|cpp-tests|lua-empty-test|lua-tests]
|
||||
|
||||
Usage: %prog [options] [cpp-empty-test|cpp-tests|lua-empty-test|lua-tests|cpp|lua|all]
|
||||
|
||||
If you are new to cocos2d-x, I recommend you start with cpp-empty-test, lua-empty-test.
|
||||
|
||||
|
@ -237,16 +237,17 @@ if __name__ == '__main__':
|
|||
"""
|
||||
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("-n", "--ndk", dest="ndk_build_param",
|
||||
parser.add_option("-n", "--ndk", dest="ndk_build_param",
|
||||
help='Parameter for ndk-build')
|
||||
parser.add_option("-p", "--platform", dest="android_platform",
|
||||
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]')
|
||||
parser.add_option("-b", "--build", dest="build_mode",
|
||||
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()
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue