123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #!/usr/bin/env python
- # android-build.py
- # Build android
- import sys
- import os, os.path
- CPP_SAMPLES = ['cpp-empty-test', 'cpp-tests', 'game-controller-test']
- LUA_SAMPLES = ['lua-empty-test', 'lua-tests', 'lua-game-controller-test']
- JS_SAMPLES = ['js-tests']
- ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES + JS_SAMPLES
- def calculate_build_targets(args):
- ''' Calculate build targets from list of targets passed on command line.
- 'all' for all tests
- 'cpp' for all c++ tests
- 'lua' for all lua tests
- 'js' for all javascript tests
- '''
- targets = []
- for arg in args:
- if arg == 'all':
- targets += ALL_SAMPLES
- elif arg == 'cpp':
- targets += CPP_SAMPLES
- elif arg == 'lua':
- targets += LUA_SAMPLES
- elif arg == 'js':
- targets += JS_SAMPLES
- else:
- targets.append(arg)
- # remove duplicates
- targets = set(targets)
- return targets
- def do_build(app_android_root, build_mode, app_abi, platform):
- command = 'cocos compile -p android -s %s --ndk-mode %s --app-abi %s' % (app_android_root, build_mode, app_abi)
- if platform:
- command += ' --ap %s' % platform
- print command
- if os.system(command) != 0:
- raise Exception('Build dynamic library for project [ %s ] failed!' % app_android_root)
- def build_targets(targets, build_mode, app_abi, api_level):
- if api_level:
- platform = 'android-%s' % api_level
- else:
- platform = None
- build_targets = calculate_build_targets(targets)
- app_android_root = ''
- cocos_root = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
- for target in build_targets:
- app_android_root = os.path.join(cocos_root, 'tests', target)
- do_build(app_android_root, build_mode, app_abi, platform)
- def main():
- from argparse import ArgumentParser, RawTextHelpFormatter
- description = '''
- This script is mainly used for building tests built-in with cocos2d-x.
- If you are new to cocos2d-x, we recommend you to start with cpp-empty-test or lua-empty-test.'''
- parser = ArgumentParser(description=description, formatter_class=RawTextHelpFormatter)
- parser.add_argument('-n', '--ndk', dest='app_abi', default='armeabi-v7a',
- help='specifies Android ABI')
- parser.add_argument('-p', '--platform', dest='api_level',
- help='specifies Android API Level')
- parser.add_argument('-b', '--build', dest='build_mode', metavar='BUILD_MODE', default='debug', choices=['debug', 'release'],
- help='the build mode for java project, debug (default) or release. ' +
- 'To get more information, please refer to ' +
- 'http://developer.android.com/tools/building/building-cmdline.html')
- parser.add_argument('targets', nargs='+', metavar='targets',
- help='targets to build. A target is one of [cpp-empty-test|cpp-tests|lua-empty-test|lua-tests|js-tests|cpp|lua|js|all]',
- choices=['cpp-empty-test', 'cpp-tests', 'lua-empty-test', 'lua-tests', 'js-tests', 'cpp', 'lua', 'js', 'all'])
- args = parser.parse_args()
- try:
- build_targets(args.targets, args.build_mode, args.app_abi, args.api_level)
- except Exception as e:
- print e
- sys.exit(1)
- if __name__ == '__main__':
- main()
|