-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-scala.xml
executable file
·300 lines (284 loc) · 13.9 KB
/
build-scala.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
<?xml version="1.0" encoding="UTF-8"?>
<project name="build-scala">
<!-- This file is imported by the main Ant script. -->
<!-- Scala SDK (www.scala-lang.org) -->
<property name="scala-compiler.jar" value="${scala.dir}/lib/scala-compiler.jar" />
<property name="scala-library.jar" value="${scala.dir}/lib/scala-library.jar" />
<!-- ProGuard (www.proguard.com) -->
<property name="proguard.jar" value="${proguard.dir}/lib/proguard.jar" />
<!-- Project settings -->
<property name="configs.dir" value="${ant.android.scala.dir}/configs" />
<property name="ant-invoked.jar" value="${configs.dir}/ant-invoked.jar" />
<path id="scala.path">
<pathelement path="${scala-compiler.jar}" />
<pathelement path="${scala-library.jar}" />
</path>
<taskdef
resource="scala/tools/ant/antlib.xml"
classpathref="scala.path" />
<resourcecount property="scala.files.count">
<fileset dir="${source.dir}" includes="**/*.scala" />
</resourcecount>
<condition property="myapp.containsScala">
<not><equals arg1="${scala.files.count}" arg2="0" /></not>
</condition>
<uptodate property="do.not.compile" targetfile="${out.dir}/classes.complete">
<srcfiles dir="${source.dir}" includes="**/*.scala,**/*.java" />
<srcfiles dir="${resource.absolute.dir}" />
</uptodate>
<target name="scala-compile" depends="-compile"
description="Compiles project's .scala files into .class files"
if="myapp.containsScala" unless="do.not.compile">
<condition property="logging" value="verbose" else="none">
<istrue value="${verbose}" />
</condition>
<property prefix="scala"
resource="compiler.properties"
classpathref="scala.path" />
<echo
message="Scala version ${scala.version.number} - http://scala-lang.org"
level="info" taskname="scalac" />
<scalac
srcdir="${source.dir}" includes="**/*.scala"
destdir="${out.classes.absolute.dir}"
bootclasspathref="android.target.classpath"
logging="${logging}" addparams="${scalac.addparams}"
classpath="${extensible.classpath}">
<src path="${gen.absolute.dir}" />
<classpath>
<pathelement location="${scala-library.jar}" />
<pathelement location="${out.classes.absolute.dir}" />
<fileset dir="${extensible.libs.classpath}" includes="*.jar" />
<path refid="project.libraries.jars" />
</classpath>
</scalac>
<!-- if the project is a library then we generate a jar file -->
<if condition="${project.is.library}">
<then>
<echo>Creating library output jar file...</echo>
<property name="out.library.jar.file" location="${out.absolute.dir}/classes.jar" />
<if>
<condition>
<length string="${android.package.excludes}" trim="true" when="greater" length="0" />
</condition>
<then>
<echo>Custom jar packaging exclusion: ${android.package.excludes}</echo>
</then>
</if>
<jar destfile="${out.library.jar.file}">
<fileset dir="${out.classes.absolute.dir}" excludes="**/R.class **/R$*.class"/>
<fileset dir="${source.absolute.dir}" excludes="**/*.java **/*.scala ${android.package.excludes}" />
</jar>
</then>
</if>
<touch file="${out.dir}/classes.complete" verbose="no"/>
</target>
<target name="-shrink-if-test">
<echo
message="Checking if Scala libraries are installed on emulator or device..." />
<exec executable="${adb}" failonerror="false" outputproperty="adb.out">
<arg line="${adb.device.arg}" />
<arg line="shell echo '$BOOTCLASSPATH'" />
</exec>
<condition property="framework.isavailable">
<contains string="${adb.out}" substring="/data/framework/scala-" />
</condition>
<echo message="BOOTCLASSPATH=${adb.out}" taskname="adb" />
</target>
<target name="-shrink-config"
description="Generate ProGuard configuration file">
<do-only-if-not-library elseText="Library project: do not shrink..." >
<taskdef resource="scala/tools/ant/task.properties"
classpath="${ant-invoked.jar}" />
<invoked property="root.target" />
<condition property="infix" value="-debug"><or>
<equals arg1="${root.target}" arg2="debug" />
<equals arg1="${root.target}" arg2="install" />
<equals arg1="${root.target}" arg2="run-tests" />
</or></condition>
<condition property="infix" value="-release"><or>
<equals arg1="${root.target}" arg2="release" />
<equals arg1="${root.target}" arg2="install-release" />
</or></condition>
<!-- If ${infix} has not been set, then the root target is not
one that is supported. Give user a sensible error message. -->
<property name="infix" value="not-supported" />
<fail message="Your root target is '${root.target}'. This is not supported with Scala compilation.">
<condition><equals arg1="${infix}" arg2="not-supported" /></condition>
</fail>
<!-- priority is given to local configuration if present -->
<condition property="template.cfg" value="${configs.dir}/local${infix}.cfg">
<available file="${configs.dir}/local${infix}.cfg" />
</condition>
<condition property="template.cfg" value="${configs.dir}/default${infix}.cfg">
<available file="${configs.dir}/default${infix}.cfg" />
</condition>
<fail message="Template file '${template.cfg}' not found">
<condition><not><available file="${template.cfg}" /></not></condition>
</fail>
<basename property="basename.cfg" file="${template.cfg}" />
<property
name="gen.proguard.cfg"
value="${out.dir}/proguard.cfg" />
<property
name="proguard.cfg"
value="${out.dir}/${basename.cfg}" />
<property
name="myapp.jar"
value="${out.absolute.dir}/${ant.project.name}${infix}-shrinked.jar" />
<echo message="Generating configuration file ${proguard.cfg}" />
<dirname property="parentdir" file="${basedir}" />
<pathconvert property="rel.template.cfg">
<map from="${parentdir}${file.separator}" to="" />
<path location="${template.cfg}" />
</pathconvert>
<property name="header" value="# This file is automatically generated from ${rel.template.cfg}" />
<xpath input="AndroidManifest.xml"
expression="/manifest/@package" output="myapp.package" />
<pathconvert property="injars.libs.path">
<regexpmapper
from="^(.*)\.jar$$"
to="\1.jar(!META-INF/MANIFEST.MF,!library.properties)"/>
<path location="${scala-library.jar}" />
<fileset dir="${jar.libs.dir}" includes="*.jar" />
<path refid="project.libraries.jars" />
</pathconvert>
<proguard-helper property="injars" prefix="-injars"
path="${out.classes.absolute.dir}${path.separator}${injars.libs.path}" />
<proguard-helper property="outjars" prefix="-outjars"
path="${myapp.jar}" />
<pathconvert property="libraryjars.path" refid="android.target.classpath" />
<proguard-helper property="libraryjars" prefix="-libraryjars"
path="${libraryjars.path}" />
<copy file="${template.cfg}" tofile="${gen.proguard.cfg}">
<filterchain>
<replacetokens>
<token key="HEADER" value="${header}" />
<token key="INJARS" value="${injars}" />
<token key="OUTJARS" value="${outjars}" />
<token key="LIBRARYJARS" value="${libraryjars}" />
<token key="MYAPP_PACKAGE" value="${myapp.package}" />
</replacetokens>
</filterchain>
</copy>
</do-only-if-not-library>
<condition property="do.not.shrink"><or>
<isset property="framework.isavailable" />
<and>
<isset property="do.not.compile" />
<filesmatch file1="${gen.proguard.cfg}" file2="${proguard.cfg}" />
</and>
<equals arg1="${project.is.library}" arg2="true" />
<and>
<equals arg1="${scala.library.installed}" arg2="true" />
<equals arg1="${infix}" arg2="-debug" />
</and>
</or></condition>
</target>
<target name="scala-shrink" depends="-shrink-if-test, -shrink-config"
unless="do.not.shrink" description="Shrink the Scala library code">
<taskdef resource="proguard/ant/task.properties"
classpath="${proguard.jar}" />
<delete><fileset file="${myapp.jar}" /></delete>
<proguard configuration="${gen.proguard.cfg}" />
<move file="${gen.proguard.cfg}" tofile="${proguard.cfg}" />
</target>
<target name="install-release" depends="release"
description="Installs/reinstalls the release package onto a running
emulator or device. If the application was previously
installed, the signatures must match." >
<install-release-helper />
</target>
<macrodef name="install-release-helper">
<sequential>
<echo>Installing ${out.release.file} onto default emulator or device...</echo>
<exec executable="${adb}" failonerror="true">
<arg line="${adb.device.arg}" />
<arg value="install" />
<arg value="-r" />
<arg path="${out.release.file}" />
</exec>
</sequential>
</macrodef>
<macrodef name="scala-dex-helper">
<element name="external-libs" optional="yes" />
<element name="extra-parameters" optional="yes" />
<sequential>
<!-- sets the primary input for dex. If a pre-dex task sets it to
something else this has no effect -->
<property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" />
<!-- set the secondary dx input: the project (and library) jar files
If a pre-dex task sets it to something else this has no effect -->
<if>
<condition>
<isreference refid="out.dex.jar.input.ref" />
</condition>
<else><if>
<condition><and>
<available file="${myapp.jar}" />
<not><isset property="framework.isavailable" /></not>
</and></condition>
<then>
<path id="out.dex.jar.input.ref" />
</then>
<else>
<path id="out.dex.jar.input.ref">
<fileset dir="${jar.libs.dir}" includes="*.jar" />
</path>
</else>
</if></else>
</if>
<condition property="dex.input" value="${myapp.jar}"
else="${out.dex.input.absolute.dir}"><and>
<available file="${myapp.jar}" />
<not><isset property="framework.isavailable" /></not>
</and></condition>
<echo>Converting compiled files and external libraries into ${intermediate.dex.file}...</echo>
<dex executable="${dx}"
output="${intermediate.dex.file}"
nolocals="@{nolocals}"
verbose="${verbose}"
previousBuildType="${build.last.target}"
buildType="${build.target}">
<path path="${dex.input}"/>
<path refid="out.dex.jar.input.ref" />
<external-libs />
</dex>
</sequential>
</macrodef>
<!-- extract the first two package names (Android naming convention) -->
<macrodef name="package-prefix">
<attribute name="property" />
<sequential>
<tempfile property="temp.file" destdir="${out.dir}"
deleteonexit="true" />
<xmlproperty file="${basedir}/AndroidManifest.xml" />
<echo message="${manifest.package}" file="${temp.file}" />
<loadfile srcfile="${temp.file}" property="@{property}">
<filterchain>
<tokenfilter>
<stringtokenizer/>
<replaceregex pattern="([^.]+\.[^.]+\.).*" replace="\1**"/>
</tokenfilter>
</filterchain>
</loadfile>
</sequential>
</macrodef>
<macrodef name="proguard-helper">
<attribute name="property" />
<attribute name="prefix" />
<attribute name="path" />
<sequential>
<tempfile property="temp.file" destdir="${out.dir}"
deleteonexit="true" />
<echo message="@{path}" file="${temp.file}" />
<loadfile srcfile="${temp.file}" property="@{property}.list">
<filterchain>
<replacestring from="${path.separator}" to="${line.separator}"/>
<replaceregex pattern="(.*)" replace="@{prefix} \1" />
</filterchain>
</loadfile>
<property name="@{property}" value="${@{property}.list}" />
</sequential>
</macrodef>
</project>