-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
build.xml
552 lines (466 loc) Β· 18.9 KB
/
build.xml
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
<!--
The default target is "dist", assuming the module creator didn't change
the build.xml in her module root folder.
The "dist" target compiles the module and places it in the zip file
for distribution. The chain of target dependencies looks like this:
dist
- pre.dist
- compile
- process.annotations
- init
- generate.bindings
- generate.rhino.bindings
- generate.v8.bindings
- pre.compile
- js.compile
- ndk.build
- ndk.build.local
"compile" and its dependencies are the interesting part.
Compilation occurs as follows:
(1) (process.annotations) javac creates the Java .class files while also invoking
our custom annotation processor KrollJSONGenerator (see https://github.com/appcelerator/titanium_mobile/blob/master/android/kroll-apt/src/java/org/appcelerator/kroll/annotations/generator/KrollJSONGenerator.java.)
KrollJSONGenerator processes the @Kroll.module, etc., annotations in the
module's classes and produces JSON files with loads of metadata about
the module, proxies, methods, etc. That metadata ends up down in the
build/generated/org/appcelerator/titanium/bindings/[module_name].json
file and is later packaged in the module jar as well as being used
by subsequent steps in this compilation process.
(2) (generate.bindings and its rhino & v8 dependencies) This step
uses the KrollBindingGenerator stand-alone java program to create
the binding layer and bootstraps for the module. (see https://github.com/appcelerator/titanium_mobile/blob/master/android/kroll-apt/src/java/org/appcelerator/kroll/annotations/generator/KrollBindingGenerator.java.)
It takes the JSON file created in step (1) above and, using the metadata therein,
produces .cpp and .h files (for V8) down in build/generated/jni, and [Proxy/Module]Prototype.java
(for rhino) down in build/generated/java.
It then uses bootstrap.py (see https://github.com/appcelerator/titanium_mobile/blob/master/support/module/android/bootstrap.py) to produce [Name]Bootstrap.java, [Name]Bootstrap.cpp,
bootstrap.js and KrollGeneratedBindings.gperf.
(3) (js.compile) If the file assets/[moduleid].js is located, then
this "native module" that is being built is actually just carrying around
a CommonJS module. So if that file is found, it goes through our
jspacker.py and gets encrypted and placed into a Java class file just
like we do for JS files in production mode when compiling a normal Titanium
Android project.
(4) (ndk.build) This step runs the stock Android NDK ndk-build command
after setting up the appropriate environment for it. It copies the
template Application.mk to build/generated, the template Android.mk
to build/generated/jni and replaces the tokens therein with correct
values. For those template files see:
https://github.com/appcelerator/titanium_mobile/blob/master/support/module/android/generated/Application.mk
and
https://github.com/appcelerator/titanium_mobile/blob/master/support/module/android/generated/Android.mk
It then launches the stock ndk-build script from the Android NDK
directory.
(5) (ndk.build.local) This step runs only if the module developer
has their own jni code (in a jni/ directory off of the module root
directory) to be compiled. It simply calls stock ndk-build on it.
(6) (last parts of compile) This step uses javac to compile
all the .java that has been generated via the other steps,
placing the results down in build/classes. It also copies
over the metadata JSON file (created in (1) down into
build/classes so it will easily get added to the module
jar later.
Post-Compilation:
The last steps of the "dist" target are responsible for packaging up
the module jar (including putting anything in assets/ into the jar, except
for the CommonJS module, if any, since that gets compiled),
then zipping it together with the manifest, any docs, other libs in
the lib folder as well as example/* and platform/* and the
timodule.xml.
-->
<project name="build-module">
<property name="ti.module.root" location="${basedir}"/>
<property file="${ti.module.root}/build.properties"/>
<property name="android.jar" location="${android.platform}/android.jar"/>
<property name="ti.module.support.dir" location="${titanium.platform}/../module"/>
<!-- the manifest format seems to be compatible w/ the properties format -->
<property file="${ti.module.root}/manifest" prefix="manifest"/>
<!-- we use some special tasks that aren't part of stock ant -->
<taskdef classname="org.appcelerator.titanium.ant.StringTask" name="ti.string" classpath="${ti.module.support.dir}/android/ant-tasks.jar"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${ti.module.support.dir}/android/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
<property name="src" location="${ti.module.root}/src"/>
<property name="build" location="${ti.module.root}/build"/>
<property name="gen" location="${build}/generated"/>
<property name="genjson" location="${build}/generated/json"/>
<property name="genjava" location="${build}/generated/java"/>
<property name="genjni" location="${build}/generated/jni"/>
<property name="genjni.local" location="${genjni}-local"/>
<property name="genjs" location="${build}/generated/js"/>
<property name="classes" location="${build}/classes"/>
<property name="docs" location="${build}/docs"/>
<property name="dist" location="${ti.module.root}/dist"/>
<property name="lib" location="${ti.module.root}/lib"/>
<property name="jni" location="${ti.module.root}/jni"/>
<property name="libs" location="${ti.module.root}/libs"/>
<property name="assets" location="${ti.module.root}/assets"/>
<property name="jsmodule.source" location="${assets}/${manifest.moduleid}.js"/>
<property name="jsmodule.compiled" location="${genjs}/${manifest.moduleid}.js"/>
<property name="javac.debug" value="true"/>
<path id="project.classpath">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${titanium.platform}">
<include name="*.jar"/>
<include name="modules/titanium-*.jar"/>
</fileset>
<pathelement path="${android.jar}"/>
<pathelement path="${google.apis}/libs/maps.jar"/>
</path>
<target name="init">
<mkdir dir="${classes}"/>
<mkdir dir="${gen}"/>
<mkdir dir="${dist}"/>
</target>
<target name="process.annotations" depends="init"
description="Processes @Kroll.proxy and @Kroll.module annotations">
<mkdir dir="${genjson}"/>
<javac
srcdir="${src}"
destdir="${classes}"
target="1.6"
source="1.6"
debug="${javac.debug}"
includeantruntime="false">
<compilerarg value="-processor"/>
<compilerarg value="org.appcelerator.kroll.annotations.generator.KrollJSONGenerator"/>
<compilerarg value="-s"/>
<compilerarg value="${genjson}"/>
<compilerarg line="-Akroll.jsonFile=${manifest.name}.json"/>
<compilerarg line="-Akroll.jsonPackage=org.appcelerator.titanium.bindings"/>
<compilerarg line="-Akroll.checkTiContext=true"/>
<classpath refid="project.classpath"/>
</javac>
</target>
<macrodef name="generate.runtime.bindings">
<attribute name="runtime"/>
<attribute name="outdir"/>
<sequential>
<java classname="org.appcelerator.kroll.annotations.generator.KrollBindingGenerator" classpathref="project.classpath">
<!-- runtime to generate for -->
<arg value="@{runtime}"/>
<!-- output directory -->
<arg value="@{outdir}"/>
<!-- isModule -->
<arg value="true"/>
<!-- modulePackage -->
<arg value="${manifest.moduleid}"/>
<!-- moduleClassName -->
<arg value="${manifest.name}GeneratedBindings"/>
<!-- binding json -->
<arg value="${genjson}/org/appcelerator/titanium/bindings/${manifest.name}.json"/>
</java>
</sequential>
</macrodef>
<target name="generate.rhino.bindings">
<generate.runtime.bindings runtime="rhino" outdir="${genjava}"/>
<antcall target="generate.rhino.idswitch"/>
</target>
<target name="generate.v8.bindings">
<generate.runtime.bindings runtime="v8" outdir="${genjni}"/>
<property name="bootstrap.py" location="${ti.module.support.dir}/android/bootstrap.py"/>
<property name="js2c.py" location="${ti.module.support.dir}/android/js2c.py"/>
<python file="${bootstrap.py}">
<!-- js runtime -->
<arg value="v8"/>
<!-- module id -->
<arg value="${manifest.moduleid}"/>
<!-- module name -->
<arg value="${ant.project.name}"/>
<!-- binding json -->
<arg value="${genjson}/org/appcelerator/titanium/bindings/${manifest.name}.json"/>
<!-- output dir -->
<arg value="${gen}"/>
</python>
</target>
<target name="generate.bindings" depends="generate.rhino.bindings,generate.v8.bindings">
</target>
<property name="rhino.idswitch" value="org.mozilla.javascript.tools.idswitch.Main"/>
<macrodef name="idswitch">
<attribute name="file"/>
<sequential>
<java classpathref="project.classpath" classname="${rhino.idswitch}" failonerror="true" logerror="true">
<arg file="@{file}"/>
</java>
</sequential>
</macrodef>
<!--
Generates an optimized id switch statement for prototype
and instance IDs
-->
<target name="generate.rhino.idswitch">
<path id="rhino.prototypes">
<fileset dir="${gen}" includes="**/*.java"/>
</path>
<for param="prototype">
<path refid="rhino.prototypes"/>
<sequential>
<echo>Generating IDs for @{prototype}</echo>
<idswitch file="@{prototype}"/>
</sequential>
</for>
</target>
<target name="pre.compile">
<available file="${ti.module.root}/jni" type="dir" property="jni.local"/>
<available file="${jsmodule.source}" type="file" property="isJSModule"/>
<!-- If applicable, will set commonjs key value in manifest and
prepare a Java class that will hand-off the source code to that JavaScript
at runtime of the Titanium application the module is used in.-->
<property name="android.py" location="${ti.module.support.dir}/android/android.py"/>
<python file="${android.py}">
<arg value="--prepare-commonjs"/>
<arg value="${ti.module.root}"/>
</python>
</target>
<target name="compile" depends="process.annotations,generate.bindings,pre.compile,js.compile,ndk.build,ndk.build.local" description="Compile this module's source code">
<javac
destdir="${classes}"
debug="${javac.debug}"
target="1.6"
source="1.6"
includeantruntime="false">
<src path="${src}" />
<src path="${genjava}" />
<include name="**/*.java" />
<classpath refid="project.classpath" />
</javac>
<copy todir="${classes}">
<fileset dir="${genjson}" includes="**/*.json" excludes="metadata.json"/>
</copy>
<antcall target="post.compile"/>
</target>
<target name="post.compile">
</target>
<macrodef name="check.ndk">
<sequential>
<property environment="env"/>
<fail message="Neither the ANDROID_NDK environment variable, or the android.ndk property is not set to an existing Android NDK installation (check your module's build.properties)">
<condition>
<not>
<or>
<available file="${android.ndk}" type="dir"/>
<available file="${env.ANDROID_NDK}" type="dir"/>
</or>
</not>
</condition>
</fail>
<condition property="ndk.path" value="${android.ndk}" else="${env.ANDROID_NDK}">
<isset property="android.ndk"/>
</condition>
</sequential>
</macrodef>
<macrodef name="build.ndk">
<attribute name="gendir"/>
<sequential>
<condition property="ndk.build"
value="${ndk.path}/ndk-build.cmd"
else="${ndk.path}/ndk-build">
<os family="windows"/>
</condition>
<property name="mobilesdk.dir" location="${titanium.platform}/.."/>
<property name="ndk.verbose" value="0"/>
<property name="tmpdir" value="${java.io.tmpdir}/${user.name}/${ant.project.name}-generated" />
<mkdir dir="${tmpdir}" />
<copy todir="${tmpdir}" preservelastmodified="true" overwrite="true" force="true" includeEmptyDirs="true">
<fileset dir="@{gendir}"/>
</copy>
<exec executable="${ndk.build}" dir="${tmpdir}" failonerror="true">
<arg value="TI_MOBILE_SDK=${mobilesdk.dir}"/>
<arg value="NDK_PROJECT_PATH=${tmpdir}"/>
<arg value="NDK_APPLICATION_MK=${tmpdir}/Application.mk"/>
<arg value="PYTHON=${python.exec}"/>
<arg value="V=${ndk.verbose}"/>
</exec>
<move todir="@{gendir}" preservelastmodified="true" overwrite="true" force="true" includeEmptyDirs="true">
<fileset dir="${tmpdir}"/>
</move>
</sequential>
</macrodef>
<target name="ndk.build">
<check.ndk/>
<mkdir dir="${genjni}"/>
<property name="module.generated.dir"
location="${titanium.platform}/../module/android/generated"/>
<ti.string property="class.rhs"
string="${ant.project.name}" substring="1"/>
<ti.string property="class.lhs1"
string="${ant.project.name}" substring="0:1"/>
<ti.string property="class.lhs2"
string="${class.lhs1}" touppercase="true"/>
<property name="module.classname" value="${class.lhs2}${class.rhs}"/>
<filterset id="ndk.filter">
<filter token="MODULE_ID" value="${manifest.moduleid}"/>
<filter token="MODULE_NAME" value="${ant.project.name}"/>
<filter token="CLASS_NAME" value="${module.classname}"/>
</filterset>
<copy todir="${gen}"
file="${module.generated.dir}/Application.mk">
<filterset refid="ndk.filter"/>
</copy>
<copy todir="${genjni}"
file="${module.generated.dir}/Android.mk">
<filterset refid="ndk.filter"/>
</copy>
<build.ndk gendir="${gen}"/>
<copy todir="${libs}">
<fileset dir="${gen}/libs">
<include name="**/*"/>
<exclude name="**/libstlport_shared.so"/>
</fileset>
</copy>
</target>
<target name="js.compile" if="${isJSModule}">
<echo>CommonJS module ${jsmodule.source} found. Compiling.</echo>
<mkdir dir="${genjs}"/>
<!-- Closure compiler -->
<java jar="${titanium.platform}/lib/closure-compiler.jar" fork="true" failonerror="true">
<arg value="--js"/>
<arg value="${jsmodule.source}"/>
<arg value="--js_output_file"/>
<arg value="${jsmodule.compiled}"/>
<arg value="--jscomp_off=internetExplorerChecks"/>
</java>
<!-- Packer -->
<property name="jspacker.py" location="${titanium.platform}/jspacker.py"/>
<python file="${jspacker.py}">
<!-- generated/js dir -->
<arg value="${genjs}"/>
<!-- commonjs file -->
<arg value="${jsmodule.compiled}"/>
<!-- package -->
<arg value="${manifest.moduleid}"/>
<!-- output dir -->
<arg value="${genjava}"/>
</python>
</target>
<target name="ndk.build.local" if="${jni.local}">
<check.ndk/>
<mkdir dir="${genjni.local}"/>
<copy todir="${genjni.local}">
<fileset dir="${ti.module.root}/jni">
<include name="**"/>
</fileset>
</copy>
<build.ndk gendir="${genjni.local}"/>
<copy todir="${libs}">
<fileset dir="${genjni.local}/libs">
<include name="**/*.so"/>
</fileset>
</copy>
</target>
<target name="libs.check">
<condition property="libs.exists">
<available file="${libs}" type="dir"/>
</condition>
</target>
<target name="zip.libs" depends="libs.check" if="libs.exists">
<zip destfile="${dist}/${module.id}-android-${manifest.version}.zip" update="true">
<zipfileset dir="${libs}" prefix="${zip.prefix}/libs">
<include name="**/*.so"/>
</zipfileset>
</zip>
</target>
<target name="zip.metadata" if="isJSModule">
<zip destfile="${dist}/${module.id}-android-${manifest.version}.zip" update="true">
<zipfileset file="${genjson}/metadata.json" prefix="${zip.prefix}"/>
</zip>
</target>
<target name="pre.dist">
</target>
<target name="post.jar">
</target>
<target name="dist" depends="compile,pre.dist" description="Generate a distributable module JAR">
<ti.string property="module.id" string="${manifest.moduleid}" tolowercase="true"/>
<property name="module.jar" location="${dist}/${ant.project.name}.jar"/>
<jar destfile="${module.jar}">
<fileset dir="${classes}"/>
<fileset dir="${ti.module.root}" includes="assets/**" excludes="assets/README assets/${manifest.moduleid}.js"/>
</jar>
<antcall target="post.jar"/>
<property name="zip.prefix" value="modules/android/${module.id}/${manifest.version}"/>
<antcall target="docgen"/>
<zip destfile="${dist}/${module.id}-android-${manifest.version}.zip">
<zipfileset file="${module.jar}" prefix="${zip.prefix}"/>
<zipfileset file="manifest" prefix="${zip.prefix}"/>
<zipfileset file="timodule.xml" prefix="${zip.prefix}"/>
<zipfileset dir="${docs}" prefix="${zip.prefix}/documentation"/>
<zipfileset dir="${lib}" includes="**/*.jar" prefix="${zip.prefix}/lib"/>
<zipfileset dir="${ti.module.root}" includes="platform/**" excludes="platform/README" prefix="${zip.prefix}"/>
<zipfileset dir="${ti.module.root}" includes="LICENSE" prefix="${zip.prefix}"/>
<zipfileset dir="${ti.module.root}" includes="example/**" prefix="${zip.prefix}"/>
</zip>
<antcall target="zip.libs"/>
<antcall target="zip.metadata"/>
<delete dir="${lib.expand.dir}" includeemptydirs="true" failonerror="false" deleteonexit="true"/>
<antcall target="post.dist"/>
</target>
<target name="post.dist">
</target>
<target name="pre.clean">
</target>
<target name="clean" description="Cleans classes and dist files" depends="ndk.clean,pre.clean">
<delete dir="${classes}"/>
<delete dir="${dist}"/>
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${gen}" includes="**/*"/>
</delete>
<antcall target="post.clean"/>
</target>
<target name="post.clean">
</target>
<target name="ndk.clean">
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${libs}" includes="**/*"/>
</delete>
</target>
<property name="titanium.py" location="${titanium.platform}/../titanium.py"/>
<property name="titanium.bat" location="${titanium.platform}/../titanium.bat"/>
<macrodef name="titanium">
<attribute name="command"/>
<element name="args" implicit="true" optional="true"/>
<sequential>
<!-- Python needs to be on the path in OSX / Linux -->
<condition property="titanium.exec" value="${titanium.bat}" else="${titanium.py}">
<os family="windows"/>
</condition>
<exec executable="${titanium.exec}" dir="${basedir}">
<env key="ANT_HOME" file="${ant.home}"/>
<arg value="@{command}"/>
<args/>
</exec>
</sequential>
</macrodef>
<property name="python.bat" location="${titanium.platform}/../python.bat"/>
<condition property="python.exec" value="${python.bat}" else="python">
<os family="windows"/>
</condition>
<macrodef name="python">
<attribute name="file"/>
<element name="args" implicit="true" optional="true"/>
<sequential>
<exec executable="${python.exec}" dir="${basedir}">
<arg value="@{file}"/>
<args/>
</exec>
</sequential>
</macrodef>
<target name="run.emulator" depends="clean,dist" description="Run the android emulator">
<titanium command="emulator"/>
</target>
<target name="run" depends="clean,dist" description="Run the module's test project">
<titanium command="run"/>
</target>
<target name="install" depends="clean,dist" description="Install the module's test project to device">
<titanium command="install"/>
</target>
<target name="pre.docgen">
</target>
<target name="docgen" depends="pre.docgen" description="Generate HTML documentation from Markdown">
<titanium command="docgen"/>
<antcall target="post.docgen"/>
</target>
<target name="post.docgen">
</target>
</project>