forked from tidev/titanium-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
239 lines (200 loc) · 7.29 KB
/
SConstruct
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env python
#
# Top level scons script
#
import os, shutil, platform, os.path as path, sys
import package
import SCons.Variables
import SCons.Environment
import subprocess
from SCons.Script import *
# read version from the build folder
# this is used by other python scripts too
cwd = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
sys.path.append(path.join(cwd,"build"))
sys.path.append(path.join(cwd,"support","android"))
import titanium_version, ant
from androidsdk import AndroidSDK
version = titanium_version.version
module_apiversion = titanium_version.module_apiversion
# allow it to be overriden on command line or in env
if os.environ.has_key('PRODUCT_VERSION'):
version = os.environ['PRODUCT_VERSION']
elif ARGUMENTS.get('PRODUCT_VERSION', 0):
version = ARGUMENTS.get('PRODUCT_VERSION')
# get the githash for the build so we can always pull this build from a specific
# commit. We're getting it here so we can pass it to android's ant build
# in order to get it into build.properties
gitCmd = "git"
if platform.system() == "Windows":
gitCmd += ".cmd"
p = subprocess.Popen([gitCmd, "rev-parse", "HEAD"], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = p.communicate()
if err:
print >>sys.stderr, err
print >>sys.stderr, "Error executing git rev-parse, is git in your PATH?"
sys.exit(1)
githash = out.strip()[:7]
print "Building MobileSDK version %s, githash %s" % (version, githash)
#
# this is messy, but i don't care, scons makes it too
# hard to include python after an external SConscript
#
build_dirs = []
if not ARGUMENTS.get('iphone',0):
build_dirs.append('android/titanium')
if platform.system() == "Darwin" and not ARGUMENTS.get('android',0):
build_dirs.append('iphone')
flags = ''
only_package = False
if ARGUMENTS.get("package",0):
only_package = True
install = "install" in COMMAND_LINE_TARGETS or ARGUMENTS.get("install", 0)
clean = "clean" in COMMAND_LINE_TARGETS or ARGUMENTS.get("clean", 0)
run_drillbit = "drillbit" in COMMAND_LINE_TARGETS or ARGUMENTS.get("drillbit",0)
if clean and os.path.exists('iphone/iphone/build'):
shutil.rmtree('iphone/iphone/build')
build_type = 'full'
build_dirs = ['iphone', 'android', 'mobileweb', 'blackberry', 'tizen', 'ivi']
force_iphone = False
if ARGUMENTS.get('iphone',0):
build_type='iphone'
build_dirs=['iphone']
if ARGUMENTS.get('android',0):
build_type='android'
build_dirs=['android']
if ARGUMENTS.get('ipad',0):
build_type='ipad'
build_dirs=['ipad']
if ARGUMENTS.get('mobileweb',0):
build_type='mobileweb'
build_dirs=['mobileweb']
if ARGUMENTS.get('blackberry',0):
build_type='blackberry'
build_dirs=['blackberry']
if ARGUMENTS.get('tizen',0):
build_type='tizen'
build_dirs=['tizen']
if ARGUMENTS.get('ivi',0):
build_type='ivi'
build_dirs=['ivi']
if ARGUMENTS.get('force_iphone',0):
force_iphone = True
if ARGUMENTS.get('COMPILER_FLAGS', 0):
flags = ARGUMENTS.get('COMPILER_FLAGS')
node_appc_branch = False
if ARGUMENTS.get('node-appc-branch', 0):
node_appc_branch = ARGUMENTS.get('node-appc-branch')
env = Environment()
Export("env cwd version")
if build_type in ['full', 'android'] and not only_package:
d = os.getcwd()
os.chdir('android')
try:
sdk = AndroidSDK(ARGUMENTS.get("android_sdk", None), 17)
build_x86 = int(ARGUMENTS.get('build_x86', 1))
# TODO re-enable javadoc targets = ["full.build", "build.titanium.javadoc"]
targets = ["full.build"]
if clean: targets = ["clean"]
elif "ant_targets" in ARGUMENTS: targets = ARGUMENTS["ant_targets"].split(",")
javah_path = os.path.join(os.path.dirname(ant.get_java()), "javah")
ant.build(targets=targets, properties={"build.version": version, "build.githash": githash,
"android.sdk": sdk.get_android_sdk(), "android.platform": sdk.get_platform_dir(), "google.apis": sdk.get_google_apis_dir(),
"ndk.build.args": "JAVAH=%s" % javah_path, "kroll.v8.build.x86": build_x86 })
finally:
os.chdir(d)
if build_type in ['full', 'iphone', 'ipad'] and not only_package \
and (platform.system() == "Darwin" or force_iphone):
d = os.getcwd()
os.chdir('iphone')
try:
#output = 0
if clean: build_type = "clean"
output = os.system("scons PRODUCT_VERSION=%s COMPILER_FLAGS='%s' BUILD_TYPE='%s'" % (version,flags,build_type))
if output!=0:
sys.stderr.write("BUILD FAILED!!!!\n")
# beep, please
if platform.system() == "Darwin":
os.system("say 'OH NO...the build failed!!!'")
os.system("printf \"\a\"")
os.system("printf \"\a\"")
os.system("printf \"\a\"")
sys.exit(output)
finally:
os.chdir(d)
if build_type in ['full', 'mobileweb'] and not only_package:
d = os.getcwd()
os.chdir('mobileweb')
try:
if clean: build_type = "clean"
# nothing to do... yet
finally:
os.chdir(d)
if build_type in ['full', 'blackberry'] and not only_package:
d = os.getcwd()
if os.path.exists('blackberry'):
os.chdir('blackberry')
try:
if clean: build_type = "clean"
# nothing to do... yet
finally:
os.chdir(d)
if build_type in ['full', 'tizen'] and not only_package:
d = os.getcwd()
if os.path.exists('tizen'):
os.chdir('tizen')
try:
if clean: build_type = "clean"
# nothing to do... yet
finally:
os.chdir(d)
if build_type in ['full', 'ivi'] and not only_package:
d = os.getcwd()
if os.path.exists('ivi'):
os.chdir('ivi')
try:
if clean: build_type = "clean"
# nothing to do... yet
finally:
os.chdir(d)
def install_mobilesdk(version_tag):
if (platform.system() == "Darwin"):
os_names = { "Windows":"win32", "Linux":"linux", "Darwin":"osx" }
os_name = os_names[platform.system()]
mobilesdk_zipfile = os.path.join(os.path.abspath('dist'), 'mobilesdk-%s-%s.zip' % (version_tag, os_name))
print "Installing %s..." % mobilesdk_zipfile
installation_directory = os.path.expanduser('~/Library/Application Support/Titanium')
os.system('/usr/bin/unzip -q -o -d "%s" "%s"' % (installation_directory, mobilesdk_zipfile))
def package_sdk(target, source, env):
android = build_type in ['full', 'android']
iphone = build_type in ['full', 'iphone']
ipad = build_type in ['full', 'ipad']
mobileweb = build_type in ['full', 'mobileweb']
blackberry = build_type in ['full', 'blackberry']
tizen = build_type in ['full', 'tizen']
ivi = build_type in ['full', 'ivi']
package_all = ARGUMENTS.get('package_all', 0)
version_tag = ARGUMENTS.get('version_tag', version)
build_jsca = int(ARGUMENTS.get('build_jsca', 1))
print "Packaging MobileSDK (%s)..." % version_tag
packager = package.Packager(build_jsca=build_jsca)
if package_all:
packager.build_all_platforms(os.path.abspath('dist'), version, module_apiversion, android, iphone, ipad, mobileweb, blackberry, tizen, ivi, version_tag, node_appc_branch)
else:
packager.build(os.path.abspath('dist'), version, module_apiversion, android, iphone, ipad, mobileweb, blackberry, tizen, ivi, version_tag, node_appc_branch)
if install and not clean:
install_mobilesdk(version_tag)
def drillbit_builder(target, source, env):
sys.path.append("drillbit")
import drillbit
drillbit.build_and_run(android_sdk=sdk.get_android_sdk())
if run_drillbit:
drillbit = Builder(action = drillbit_builder)
env.Append(BUILDERS = {'BuildAndRunDrillbit': drillbit})
env.BuildAndRunDrillbit('#dummy-drillbit-target', [])
package_builder = Builder(action = package_sdk)
env.Append(BUILDERS = {'PackageMobileSDK': package_builder})
env.PackageMobileSDK("#dummy-sdk-target", [])
if clean:
# don't error
Exit(0)