2013-10-30 14:19:07 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
# android-build.py
|
2014-03-14 12:52:24 +08:00
|
|
|
# Build android
|
2013-10-30 14:19:07 +08:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os, os.path
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
2014-06-30 03:25:49 +08:00
|
|
|
CPP_SAMPLES = ['cpp-empty-test', 'cpp-tests', 'game-controller-test']
|
2014-07-09 18:05:02 +08:00
|
|
|
LUA_SAMPLES = ['lua-empty-test', 'lua-tests', 'lua-game-controller-test']
|
2015-05-25 16:37:08 +08:00
|
|
|
JS_SAMPLES = ['js-tests']
|
|
|
|
ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES + JS_SAMPLES
|
2014-03-10 11:54:26 +08:00
|
|
|
|
|
|
|
def caculate_built_samples(args):
|
|
|
|
''' Compute the sampels to be built
|
|
|
|
'cpp' for short of all cpp tests
|
2014-03-14 12:52:24 +08:00
|
|
|
'lua' for short of all lua tests
|
2014-03-10 11:54:26 +08:00
|
|
|
'''
|
|
|
|
|
|
|
|
if 'all' in args:
|
|
|
|
return ALL_SAMPLES
|
|
|
|
|
|
|
|
targets = []
|
|
|
|
if 'cpp' in args:
|
|
|
|
targets += CPP_SAMPLES
|
|
|
|
args.remove('cpp')
|
|
|
|
if 'lua' in args:
|
|
|
|
targets += LUA_SAMPLES
|
|
|
|
args.remove('lua')
|
2015-05-25 16:37:08 +08:00
|
|
|
if 'js' in args:
|
|
|
|
targets += JS_SAMPLES
|
|
|
|
args.remove('js')
|
2014-03-10 11:54:26 +08:00
|
|
|
|
|
|
|
targets += args
|
|
|
|
|
|
|
|
# remove duplicate elements, for example
|
|
|
|
# python android-build.py cpp hellocpp
|
|
|
|
targets = set(targets)
|
|
|
|
return list(targets)
|
|
|
|
|
2014-12-30 16:24:16 +08:00
|
|
|
def do_build(app_android_root, build_mode):
|
2015-05-25 16:37:08 +08:00
|
|
|
|
|
|
|
command = 'cocos compile -p android -s %s --ndk-mode %s' % (app_android_root, build_mode)
|
2014-01-20 10:37:01 +08:00
|
|
|
print command
|
2014-12-30 16:24:16 +08:00
|
|
|
|
2013-11-09 21:05:17 +08:00
|
|
|
if os.system(command) != 0:
|
2013-11-26 11:58:01 +08:00
|
|
|
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
|
2013-10-30 18:27:56 +08:00
|
|
|
|
2014-12-30 16:24:16 +08:00
|
|
|
def build_samples(target, build_mode):
|
2013-10-30 14:19:07 +08:00
|
|
|
|
2014-11-27 13:56:15 +08:00
|
|
|
if build_mode is None:
|
|
|
|
build_mode = 'debug'
|
|
|
|
elif build_mode != 'release':
|
|
|
|
build_mode = 'debug'
|
2015-05-25 16:37:08 +08:00
|
|
|
|
2014-03-10 11:54:26 +08:00
|
|
|
build_targets = caculate_built_samples(target)
|
2014-03-14 12:52:24 +08:00
|
|
|
|
2014-03-10 11:54:26 +08:00
|
|
|
app_android_root = ''
|
2014-03-11 16:10:02 +08:00
|
|
|
|
|
|
|
target_proj_path_map = {
|
2014-12-30 16:24:16 +08:00
|
|
|
"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",
|
2015-05-25 16:37:08 +08:00
|
|
|
"lua-game-controller-test": "tests/lua-game-controller-test",
|
|
|
|
"js-tests": "tests/js-tests"
|
2014-03-11 16:10:02 +08:00
|
|
|
}
|
|
|
|
|
2014-12-30 16:24:16 +08:00
|
|
|
cocos_root = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
|
|
|
|
|
2014-03-10 11:54:26 +08:00
|
|
|
for target in build_targets:
|
2014-03-11 16:10:02 +08:00
|
|
|
if target in target_proj_path_map:
|
2014-12-30 16:24:16 +08:00
|
|
|
app_android_root = os.path.join(cocos_root, target_proj_path_map[target])
|
2014-03-10 11:54:26 +08:00
|
|
|
else:
|
|
|
|
print 'unknown target: %s' % target
|
|
|
|
continue
|
2013-10-30 14:19:07 +08:00
|
|
|
|
2014-12-30 16:24:16 +08:00
|
|
|
do_build(app_android_root, build_mode)
|
2013-10-30 14:19:07 +08:00
|
|
|
|
|
|
|
# -------------- main --------------
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
#parse the params
|
2014-01-26 16:09:28 +08:00
|
|
|
usage = """
|
2014-02-01 06:09:28 +08:00
|
|
|
This script is mainy used for building tests built-in with cocos2d-x.
|
2014-03-14 12:52:24 +08:00
|
|
|
|
2015-05-25 16:37:08 +08:00
|
|
|
Usage: %prog [options] [cpp-empty-test|cpp-tests|lua-empty-test|lua-tests|js-tests|cpp|lua|all]
|
2014-01-26 16:09:28 +08:00
|
|
|
|
2014-03-11 16:10:02 +08:00
|
|
|
If you are new to cocos2d-x, I recommend you start with cpp-empty-test, lua-empty-test.
|
2014-01-26 16:09:28 +08:00
|
|
|
|
|
|
|
You can combine these targets like this:
|
|
|
|
|
2014-12-30 16:24:16 +08:00
|
|
|
python android-build.py cpp-empty-test lua-empty-test
|
2014-01-26 16:09:28 +08:00
|
|
|
|
|
|
|
"""
|
2013-12-22 17:48:35 +08:00
|
|
|
|
|
|
|
parser = OptionParser(usage=usage)
|
2014-03-14 12:52:24 +08:00
|
|
|
parser.add_option("-n", "--ndk", dest="ndk_build_param",
|
2015-05-25 16:37:08 +08:00
|
|
|
help='It is not used anymore, because cocos console does not support it.')
|
2014-03-14 12:52:24 +08:00
|
|
|
parser.add_option("-p", "--platform", dest="android_platform",
|
2015-05-25 16:37:08 +08:00
|
|
|
help='This parameter is not used any more, just keep compatible.')
|
2014-03-14 12:52:24 +08:00
|
|
|
parser.add_option("-b", "--build", dest="build_mode",
|
2015-05-25 16:37:08 +08:00
|
|
|
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')
|
2013-10-30 14:19:07 +08:00
|
|
|
(opts, args) = parser.parse_args()
|
2015-05-25 16:37:08 +08:00
|
|
|
|
2014-03-10 11:54:26 +08:00
|
|
|
if len(args) == 0:
|
2013-12-22 17:48:35 +08:00
|
|
|
parser.print_help()
|
2014-03-14 12:52:24 +08:00
|
|
|
sys.exit(1)
|
2013-10-30 14:19:07 +08:00
|
|
|
else:
|
2013-11-09 21:05:17 +08:00
|
|
|
try:
|
2014-12-30 16:24:16 +08:00
|
|
|
build_samples(args, opts.build_mode)
|
2013-11-09 21:05:17 +08:00
|
|
|
except Exception as e:
|
|
|
|
print e
|
|
|
|
sys.exit(1)
|