forked from cocos2d/cocos2d-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
android-build.py
executable file
·117 lines (90 loc) · 3.57 KB
/
android-build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
# android-build.py
# Build android
import sys
import os, os.path
from optparse import OptionParser
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 caculate_built_samples(args):
''' Compute the sampels to be built
'cpp' for short of all cpp tests
'lua' for short of all lua tests
'''
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')
if 'js' in args:
targets += JS_SAMPLES
args.remove('js')
targets += args
# remove duplicate elements, for example
# python android-build.py cpp hellocpp
targets = set(targets)
return list(targets)
def do_build(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:
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
def build_samples(target, build_mode):
if build_mode is None:
build_mode = 'debug'
elif build_mode != 'release':
build_mode = 'debug'
build_targets = caculate_built_samples(target)
app_android_root = ''
target_proj_path_map = {
"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",
"js-tests": "tests/js-tests"
}
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(cocos_root, target_proj_path_map[target])
else:
print 'unknown target: %s' % target
continue
do_build(app_android_root, build_mode)
# -------------- main --------------
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|js-tests|cpp|lua|all]
If you are new to cocos2d-x, I recommend you start with cpp-empty-test, lua-empty-test.
You can combine these targets like this:
python android-build.py cpp-empty-test lua-empty-test
"""
parser = OptionParser(usage=usage)
parser.add_option("-n", "--ndk", dest="ndk_build_param",
help='It is not used anymore, because cocos console does not support it.')
parser.add_option("-p", "--platform", dest="android_platform",
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()
if len(args) == 0:
parser.print_help()
sys.exit(1)
else:
try:
build_samples(args, opts.build_mode)
except Exception as e:
print e
sys.exit(1)