blob: 6040f7d9104c3d6adc523ff5bb8bb88abd2105ef [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/bin/bash
2#
3# Copyright (C) 2008 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Stop if something fails.
18set -e
19
Alex Light6a439bc2015-10-26 17:52:36 -070020# Set default values for directories.
21if [ -d smali ]; then
22 HAS_SMALI=true
23else
24 HAS_SMALI=false
25fi
26
Igor Murashkin4014d842017-07-11 11:58:44 -070027# .j files in jasmin get compiled into classes.jar
28if [ -d jasmin ]; then
29 HAS_JASMIN=true
30else
31 HAS_JASMIN=false
32fi
33
Alex Light6a439bc2015-10-26 17:52:36 -070034if [ -d src ]; then
35 HAS_SRC=true
36else
37 HAS_SRC=false
38fi
39
Igor Murashkin1c843e92017-06-19 14:33:06 -070040# .java files in src-art get compiled with libcore on the bootclasspath
41if [ -d src-art ]; then
42 HAS_SRC_ART=true
43else
44 HAS_SRC_ART=false
45fi
46
Alex Light6a439bc2015-10-26 17:52:36 -070047if [ -d src2 ]; then
48 HAS_SRC2=true
49else
50 HAS_SRC2=false
51fi
52
53if [ -d src-multidex ]; then
54 HAS_SRC_MULTIDEX=true
55else
56 HAS_SRC_MULTIDEX=false
57fi
58
Alex Lightfedd91d2016-01-07 14:49:16 -080059if [ -d smali-multidex ]; then
60 HAS_SMALI_MULTIDEX=true
61else
62 HAS_SMALI_MULTIDEX=false
63fi
64
Igor Murashkin4014d842017-07-11 11:58:44 -070065# .j files in jasmin-multidex get compiled into classes2.jar
66if [ -d jasmin-multidex ]; then
67 HAS_JASMIN_MULTIDEX=true
68else
69 HAS_JASMIN_MULTIDEX=false
70fi
71
Alex Light6a439bc2015-10-26 17:52:36 -070072if [ -d src-ex ]; then
73 HAS_SRC_EX=true
74else
75 HAS_SRC_EX=false
76fi
77
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +000078if [ -d src-dex2oat-unresolved ]; then
79 HAS_SRC_DEX2OAT_UNRESOLVED=true
80else
81 HAS_SRC_DEX2OAT_UNRESOLVED=false
82fi
83
David Brazdil11b67b22018-01-18 16:41:40 +000084if [ -f api-light-greylist.txt -o -f api-dark-greylist.txt -o -f api-blacklist.txt ]; then
85 HAS_HIDDENAPI_SPEC=true
86else
87 HAS_HIDDENAPI_SPEC=false
88fi
89
90# USE_HIDDENAPI=false run-test... will disable hiddenapi.
91if [ -z "${USE_HIDDENAPI}" ]; then
92 USE_HIDDENAPI=true
93fi
94
Igor Murashkine5181932017-06-15 16:03:50 -070095# DESUGAR=false run-test... will disable desugar.
96if [[ "$DESUGAR" == false ]]; then
97 USE_DESUGAR=false
98fi
99
Igor Murashkin271a0f82017-02-14 21:14:17 +0000100# Allow overriding ZIP_COMPRESSION_METHOD with e.g. 'store'
101ZIP_COMPRESSION_METHOD="deflate"
102# Align every ZIP file made by calling $ZIPALIGN command?
103WITH_ZIP_ALIGN=false
104ZIP_ALIGN_BYTES="-1"
105
Igor Murashkin69196392017-06-16 15:25:32 -0700106DX_FLAGS="--min-sdk-version=24"
107DX_VM_FLAGS=""
Alex Light6a439bc2015-10-26 17:52:36 -0700108EXPERIMENTAL=""
109
Igor Murashkin2a337752017-06-16 14:34:40 +0000110BUILD_MODE="target"
111DEV_MODE="no"
112
Alex Lightea1e7702016-07-11 13:39:55 -0700113# The key for default arguments if no experimental things are enabled.
114DEFAULT_EXPERIMENT="no-experiment"
115
Alex Light6a439bc2015-10-26 17:52:36 -0700116# Setup experimental flag mappings in a bash associative array.
117declare -A JACK_EXPERIMENTAL_ARGS
Alex Lightdba61482016-12-21 08:20:29 -0800118JACK_EXPERIMENTAL_ARGS["agents"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24"
Yohann Roussel4b495672016-03-21 16:26:02 +0100119JACK_EXPERIMENTAL_ARGS["default-methods"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24"
120JACK_EXPERIMENTAL_ARGS["lambdas"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24"
mikaelpeltier3233dcc2016-11-18 14:23:45 +0100121JACK_EXPERIMENTAL_ARGS["method-handles"]="-D jack.java.source.version=1.7 -D jack.android.min-api-level=o-b1"
Alex Lighte4893ee2017-02-09 15:28:53 -0800122JACK_EXPERIMENTAL_ARGS[${DEFAULT_EXPERIMENT}]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24"
David Brazdil4846d132015-01-15 19:07:08 +0000123
Alex Lightb55f1ac2016-04-12 15:50:55 -0700124declare -A SMALI_EXPERIMENTAL_ARGS
Ben Gruver14fc9db2017-04-28 15:30:49 -0700125SMALI_EXPERIMENTAL_ARGS["default-methods"]="--api 24"
126SMALI_EXPERIMENTAL_ARGS["method-handles"]="--api 26"
Orion Hodsonbecc83b2017-12-08 11:36:19 +0000127SMALI_EXPERIMENTAL_ARGS["var-handles"]="--api 26"
Ben Gruver14fc9db2017-04-28 15:30:49 -0700128SMALI_EXPERIMENTAL_ARGS["agents"]="--api 26"
Alex Lightb55f1ac2016-04-12 15:50:55 -0700129
Alex Lightea1e7702016-07-11 13:39:55 -0700130declare -A JAVAC_EXPERIMENTAL_ARGS
131JAVAC_EXPERIMENTAL_ARGS["default-methods"]="-source 1.8 -target 1.8"
132JAVAC_EXPERIMENTAL_ARGS["lambdas"]="-source 1.8 -target 1.8"
Narayan Kamath9823e782016-08-03 12:46:58 +0100133JAVAC_EXPERIMENTAL_ARGS["method-handles"]="-source 1.8 -target 1.8"
Orion Hodsonbecc83b2017-12-08 11:36:19 +0000134JAVAC_EXPERIMENTAL_ARGS["var-handles"]="-source 1.8 -target 1.8"
Alex Light4eec3c52017-04-14 13:17:26 -0700135JAVAC_EXPERIMENTAL_ARGS[${DEFAULT_EXPERIMENT}]="-source 1.8 -target 1.8"
Alex Lightdba61482016-12-21 08:20:29 -0800136JAVAC_EXPERIMENTAL_ARGS["agents"]="-source 1.8 -target 1.8"
Alex Lightea1e7702016-07-11 13:39:55 -0700137
Igor Murashkin69196392017-06-16 15:25:32 -0700138declare -A DX_EXPERIMENTAL_ARGS
139DX_EXPERIMENTAL_ARGS["method-handles"]="--min-sdk-version=26"
Orion Hodsonbecc83b2017-12-08 11:36:19 +0000140DX_EXPERIMENTAL_ARGS["var-handles"]="--min-sdk-version=26"
Igor Murashkin69196392017-06-16 15:25:32 -0700141
David Brazdil4846d132015-01-15 19:07:08 +0000142while true; do
143 if [ "x$1" = "x--dx-option" ]; then
144 shift
Orion Hodsone1fb77f2017-02-27 13:57:18 +0000145 option="$1"
David Brazdil4846d132015-01-15 19:07:08 +0000146 DX_FLAGS="${DX_FLAGS} $option"
147 shift
Igor Murashkin69196392017-06-16 15:25:32 -0700148 elif [ "x$1" = "x--dx-vm-option" ]; then
149 shift
150 option="$1"
151 DX_VM_FLAGS="${DX_VM_FLAGS} $option"
152 shift
Alex Lighteb7c1442015-08-31 13:17:42 -0700153 elif [ "x$1" = "x--jvm" ]; then
154 shift
Alex Light6a439bc2015-10-26 17:52:36 -0700155 elif [ "x$1" = "x--no-src" ]; then
156 HAS_SRC=false
157 shift
158 elif [ "x$1" = "x--no-src2" ]; then
159 HAS_SRC2=false
160 shift
161 elif [ "x$1" = "x--no-src-multidex" ]; then
162 HAS_SRC_MULTIDEX=false
163 shift
Alex Lightfedd91d2016-01-07 14:49:16 -0800164 elif [ "x$1" = "x--no-smali-multidex" ]; then
165 HAS_SMALI_MULTIDEX=false
166 shift
Alex Light6a439bc2015-10-26 17:52:36 -0700167 elif [ "x$1" = "x--no-src-ex" ]; then
168 HAS_SRC_EX=false
169 shift
170 elif [ "x$1" = "x--no-smali" ]; then
171 HAS_SMALI=false
172 shift
173 elif [ "x$1" = "x--experimental" ]; then
174 shift
Alex Lightea1e7702016-07-11 13:39:55 -0700175 # We have a specific experimental configuration so don't use the default.
176 DEFAULT_EXPERIMENT=""
Alex Light6a439bc2015-10-26 17:52:36 -0700177 EXPERIMENTAL="${EXPERIMENTAL} $1"
178 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000179 elif [ "x$1" = "x--zip-compression-method" ]; then
180 # Allow using different zip compression method, e.g. 'store'
181 shift
182 ZIP_COMPRESSION_METHOD="$1"
183 shift
184 elif [ "x$1" = "x--zip-align" ]; then
185 # Align ZIP entries to some # of bytes.
186 shift
187 WITH_ZIP_ALIGN=true
188 ZIP_ALIGN_BYTES="$1"
189 shift
Igor Murashkin2a337752017-06-16 14:34:40 +0000190 elif [ "x$1" = "x--host" ]; then
191 BUILD_MODE="host"
192 shift
193 elif [ "x$1" = "x--target" ]; then
194 BUILD_MODE="target"
195 shift
196 elif [ "x$1" = "x--dev" ]; then
197 DEV_MODE="yes"
198 shift
David Brazdil4846d132015-01-15 19:07:08 +0000199 elif expr "x$1" : "x--" >/dev/null 2>&1; then
200 echo "unknown $0 option: $1" 1>&2
201 exit 1
202 else
203 break
204 fi
205done
206
Alex Lightea1e7702016-07-11 13:39:55 -0700207# Be sure to get any default arguments if not doing any experiments.
208EXPERIMENTAL="${EXPERIMENTAL} ${DEFAULT_EXPERIMENT}"
209
Sebastien Hertz361ad552017-01-04 16:07:57 +0100210if [ "${JACK_SERVER}" = "false" ]; then
211 # Run in single-threaded mode for the continuous buildbot.
212 JACK_ARGS="${JACK_ARGS} -D sched.runner=single-threaded"
213else
214 # Run with 4 threads to reduce memory footprint and thread contention.
215 JACK_ARGS="${JACK_ARGS} -D sched.runner=multi-threaded"
216 JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.kind=fixed"
217 JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.fixed.count=4"
218fi
219
Alex Light6a439bc2015-10-26 17:52:36 -0700220# Add args from the experimental mappings.
221for experiment in ${EXPERIMENTAL}; do
222 JACK_ARGS="${JACK_ARGS} ${JACK_EXPERIMENTAL_ARGS[${experiment}]}"
Alex Lightb55f1ac2016-04-12 15:50:55 -0700223 SMALI_ARGS="${SMALI_ARGS} ${SMALI_EXPERIMENTAL_ARGS[${experiment}]}"
Alex Lightea1e7702016-07-11 13:39:55 -0700224 JAVAC_ARGS="${JAVAC_ARGS} ${JAVAC_EXPERIMENTAL_ARGS[${experiment}]}"
Igor Murashkin69196392017-06-16 15:25:32 -0700225 DX_FLAGS="${DX_FLAGS} ${DX_EXPERIMENTAL_ARGS[${experiment}]}"
Alex Light6a439bc2015-10-26 17:52:36 -0700226done
227
Igor Murashkin271a0f82017-02-14 21:14:17 +0000228#########################################
229
230# Catch all commands to 'ZIP' and prepend extra flags.
231# Optionally, zipalign results to some alignment.
232function zip() {
233 local zip_target="$1"
234 local entry_src="$2"
235 shift 2
236
237 command zip --compression-method "$ZIP_COMPRESSION_METHOD" "$zip_target" "$entry_src" "$@"
238
239 if "$WITH_ZIP_ALIGN"; then
240 # zipalign does not operate in-place, so write results to a temp file.
241 local tmp_file="$(mktemp)"
242 "$ZIPALIGN" -f "$ZIP_ALIGN_BYTES" "$zip_target" "$tmp_file"
243 # replace original zip target with our temp file.
244 mv "$tmp_file" "$zip_target"
245 fi
246}
247
Igor Murashkin4014d842017-07-11 11:58:44 -0700248function make_jasmin() {
249 local out_directory="$1"
250 shift
251 local jasmin_sources=("$@")
252
253 mkdir -p "$out_directory"
254
255 if [[ $DEV_MODE == yes ]]; then
256 echo ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}"
257 ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}"
258 else
259 ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}" >/dev/null
260 fi
261}
262
Igor Murashkin2a337752017-06-16 14:34:40 +0000263function desugar() {
264 local desugar_args=--mode=host
265 if [[ $BUILD_MODE == target ]]; then
266 desugar_args=--mode=target
267 fi
268
269 if [[ $DEV_MODE == yes ]]; then
270 desugar_args="$desugar_args --show-commands"
271 fi
272
Igor Murashkine5181932017-06-15 16:03:50 -0700273 "$DESUGAR" --core-only $desugar_args "$@"
Igor Murashkin2a337752017-06-16 14:34:40 +0000274}
275
Igor Murashkin1c843e92017-06-19 14:33:06 -0700276# Like regular javac but includes libcore on the bootclasspath.
277function javac_with_bootclasspath {
278 local javac_args=--mode=host
279 if [[ $BUILD_MODE == target ]]; then
280 javac_args=--mode=target
281 fi
282
283 if [[ $DEV_MODE == yes ]]; then
284 javac_args="$javac_args --show-commands"
285 fi
286
287 "$ANDROID_BUILD_TOP/art/tools/javac-helper.sh" --core-only $javac_args "$@"
288}
289
Igor Murashkin2a337752017-06-16 14:34:40 +0000290# Make a "dex" file given a directory of classes in $1.
291# Also calls desugar on the classes first to convert lambdas.
292function make_dex() {
293 local name="$1"
294
295 local dx_input
296 if [[ "$USE_DESUGAR" == "true" ]]; then
297 # Make a jar first so desugar doesn't need every .class file individually.
298 jar cf "$name.before-desugar.jar" -C "$name" .
299
300 dx_input="${name}.desugar.jar"
301
302 # Make desugared JAR.
303 desugar --input "$name.before-desugar.jar" --output "$dx_input"
304 else
305 dx_input="${name}"
306 fi
307
Alan Leung0afa07a2017-10-03 16:56:30 -0700308 local dexer="${DX}"
309 if [ ${USE_D8} = "true" ]; then
Alan Leunga4ba9b52017-11-16 00:19:18 -0800310 dexer="${ANDROID_HOST_OUT}/bin/d8-compat-dx"
Alan Leung0afa07a2017-10-03 16:56:30 -0700311 fi
312
Igor Murashkin2a337752017-06-16 14:34:40 +0000313 # Make dex file from desugared JAR.
Alan Leung0afa07a2017-10-03 16:56:30 -0700314 ${dexer} -JXmx256m ${DX_VM_FLAGS} --debug --dex --dump-to=${name}.lst --output=${name}.dex --dump-width=1000 ${DX_FLAGS} "${dx_input}"
Igor Murashkin2a337752017-06-16 14:34:40 +0000315}
316
Igor Murashkin4014d842017-07-11 11:58:44 -0700317# Merge all the dex files in $1..$N into $1. Skip non-existing files, but at least 1 file must exist.
318function make_dexmerge() {
319 # Dex file that acts as the destination.
320 local dst_file="$1"
321
322 # Dex files that act as the source.
323 local dex_files_to_merge=()
324
325 # Skip any non-existing files.
326 while [[ $# -gt 0 ]]; do
327 if [[ -e "$1" ]]; then
328 dex_files_to_merge+=("$1")
329 fi
330 shift
331 done
332
333 # Should have at least 1 dex_files_to_merge here, otherwise dxmerger will print the help.
334 ${DXMERGER} "$dst_file" "${dex_files_to_merge[@]}"
335}
336
David Brazdil11b67b22018-01-18 16:41:40 +0000337function make_hiddenapi() {
338 local args=()
339 while [[ $# -gt 0 ]]; do
340 args+=("--dex=$1")
341 shift
342 done
343 if [ -f api-light-greylist.txt ]; then
344 args+=("--light-greylist=api-light-greylist.txt")
345 fi
346 if [ -f api-dark-greylist.txt ]; then
347 args+=("--dark-greylist=api-dark-greylist.txt")
348 fi
349 if [ -f api-blacklist.txt ]; then
350 args+=("--blacklist=api-blacklist.txt")
351 fi
352 ${HIDDENAPI} "${args[@]}"
353}
354
Igor Murashkin1c843e92017-06-19 14:33:06 -0700355# Print the directory name only if it exists.
356function maybe_dir() {
357 local dirname="$1"
358 if [[ -d "$dirname" ]]; then
359 echo "$dirname"
360 fi
361}
362
Stephen Kyle40d35182014-10-03 13:47:56 +0100363if [ -e classes.dex ]; then
364 zip $TEST_NAME.jar classes.dex
365 exit 0
366fi
367
David Brazdil11b67b22018-01-18 16:41:40 +0000368# Helper function for a common test. Evaluate with $(has_mutlidex).
369function has_multidex() {
370 echo [ ${HAS_SRC_MULTIDEX} = "true" \
371 -o ${HAS_JASMIN_MULTIDEX} = "true" \
372 -o ${HAS_SMALI_MULTIDEX} = "true" ]
373}
374
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000375if [ ${HAS_SRC_DEX2OAT_UNRESOLVED} = "true" ]; then
376 mkdir classes
377 mkdir classes-ex
378 ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src-dex2oat-unresolved -d classes `find src -name '*.java'`
379 ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src -d classes-ex `find src-dex2oat-unresolved -name '*.java'`
380 if [ ${USE_JACK} = "true" ]; then
381 jar cf classes.jill.jar -C classes .
382 jar cf classes-ex.jill.jar -C classes-ex .
383
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000384 ${JACK} --import classes-ex.jill.jar --output-dex .
385 zip ${TEST_NAME}-ex.jar classes.dex
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000386 ${JACK} --import classes.jill.jar --output-dex .
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000387 else
388 if [ ${NEED_DEX} = "true" ]; then
Igor Murashkin2a337752017-06-16 14:34:40 +0000389 make_dex classes-ex
Igor Murashkin6c946b52017-06-16 14:27:47 -0700390 mv classes-ex.dex classes.dex # rename it so it shows up as "classes.dex" in the zip file.
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000391 zip ${TEST_NAME}-ex.jar classes.dex
Igor Murashkin2a337752017-06-16 14:34:40 +0000392 make_dex classes
Sebastien Hertz4856ca72016-03-03 18:08:17 +0100393 fi
Alex Light6a439bc2015-10-26 17:52:36 -0700394 fi
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100395else
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100396 if [ ${USE_JACK} = "true" ]; then
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000397 # Jack toolchain
Igor Murashkin1c843e92017-06-19 14:33:06 -0700398 if [[ "$HAS_SRC" == true || "$HAS_SRC_ART" == true ]]; then
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000399 if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then
400 # Compile src and src-multidex in the same .jack file. We will apply multidex partitioning
401 # when creating the output .dex file.
Igor Murashkin1c843e92017-06-19 14:33:06 -0700402 ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) src-multidex $(maybe_dir src-art)
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000403 jack_extra_args="${jack_extra_args} -D jack.dex.output.policy=minimal-multidex"
404 jack_extra_args="${jack_extra_args} -D jack.preprocessor=true"
405 jack_extra_args="${jack_extra_args} -D jack.preprocessor.file=multidex.jpp"
406 else
Igor Murashkin1c843e92017-06-19 14:33:06 -0700407 ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) $(maybe_dir src-art)
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000408 fi
409 jack_extra_args="${jack_extra_args} --import src.jack"
410 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700411
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000412 if [ "${HAS_SRC2}" = "true" ]; then
413 ${JACK} ${JACK_ARGS} --output-jack src2.jack src2
414 # In case of duplicate classes, we want to take into account the classes from src2. Therefore
415 # we apply the 'keep-first' policy and import src2.jack file *before* the src.jack file.
416 jack_extra_args="${jack_extra_args} -D jack.import.type.policy=keep-first"
417 jack_extra_args="--import src2.jack ${jack_extra_args}"
418 fi
419
420 # Compile jack files into a DEX file.
Igor Murashkin4014d842017-07-11 11:58:44 -0700421 if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ] || [ "${HAS_SRC_ART}" = "true" ]; then
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000422 ${JACK} ${JACK_ARGS} ${jack_extra_args} --output-dex .
423 fi
424 else
425 # Legacy toolchain with javac+dx
426 if [ "${HAS_SRC}" = "true" ]; then
427 mkdir classes
428 ${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
429 fi
430
Igor Murashkin1c843e92017-06-19 14:33:06 -0700431 if [ "${HAS_SRC_ART}" = "true" ]; then
432 mkdir -p classes
433 javac_with_bootclasspath ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'`
434 fi
435
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000436 if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then
437 mkdir classes2
Igor Murashkin10ba6852017-06-21 11:05:23 -0700438 ${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000439 if [ ${NEED_DEX} = "true" ]; then
Igor Murashkin2a337752017-06-16 14:34:40 +0000440 make_dex classes2
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000441 fi
442 fi
443
444 if [ "${HAS_SRC2}" = "true" ]; then
445 mkdir -p classes
Orion Hodsonbecc83b2017-12-08 11:36:19 +0000446 ${JAVAC} ${JAVAC_ARGS} -classpath classes -d classes `find src2 -name '*.java'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000447 fi
448
Igor Murashkin1c843e92017-06-19 14:33:06 -0700449 if [[ "${HAS_SRC}" == "true" || "${HAS_SRC2}" == "true" || "${HAS_SRC_ART}" == "true" ]]; then
Igor Murashkin4014d842017-07-11 11:58:44 -0700450 if [ ${NEED_DEX} = "true" ]; then
Igor Murashkin2a337752017-06-16 14:34:40 +0000451 make_dex classes
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000452 fi
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100453 fi
Elliott Hughesc717eef2012-06-15 16:01:26 -0700454 fi
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000455fi
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000456
Igor Murashkin4014d842017-07-11 11:58:44 -0700457if [[ "${HAS_JASMIN}" == true ]]; then
458 # Compile Jasmin classes as if they were part of the classes.dex file.
459 make_jasmin jasmin_classes $(find 'jasmin' -name '*.j')
460 if [[ "${NEED_DEX}" == "true" ]]; then
461 # Disable desugar because it won't handle intentional linkage errors.
462 USE_DESUGAR=false make_dex jasmin_classes
463 make_dexmerge classes.dex jasmin_classes.dex
464 else
465 # Move jasmin classes into classes directory so that they are picked up with -cp classes.
466 mkdir -p classes
467 mv jasmin_classes/* classes
468 fi
469fi
470
Andreas Gampe2b936812017-02-07 16:03:57 -0800471if [ "${HAS_SMALI}" = "true" -a ${NEED_DEX} = "true" ]; then
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000472 # Compile Smali classes
Ben Gruver14fc9db2017-04-28 15:30:49 -0700473 ${SMALI} -JXmx512m assemble ${SMALI_ARGS} --output smali_classes.dex `find smali -name '*.smali'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000474
Igor Murashkin4014d842017-07-11 11:58:44 -0700475 # Merge smali files into classes.dex, this takes priority over any jasmin files.
476 make_dexmerge classes.dex smali_classes.dex
477fi
478
479# Compile Jasmin classes in jasmin-multidex as if they were part of the classes2.jar
480if [[ "$HAS_JASMIN_MULTIDEX" == true ]]; then
481 make_jasmin jasmin_classes2 $(find 'jasmin-multidex' -name '*.j')
482
483 if [[ "${NEED_DEX}" == "true" ]]; then
484 # Disable desugar because it won't handle intentional linkage errors.
485 USE_DESUGAR=false make_dex jasmin_classes2
486
487 # Merge jasmin_classes2.dex into classes2.dex
488 make_dexmerge classes2.dex jasmin_classes2.dex
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000489 else
Igor Murashkin4014d842017-07-11 11:58:44 -0700490 # Move jasmin classes into classes2 directory so that they are picked up with -cp classes2.
491 mkdir -p classes2
492 mv jasmin_classes2/* classes2
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000493 fi
494fi
495
Andreas Gampe2b936812017-02-07 16:03:57 -0800496if [ "${HAS_SMALI_MULTIDEX}" = "true" -a ${NEED_DEX} = "true" ]; then
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000497 # Compile Smali classes
Ben Gruver14fc9db2017-04-28 15:30:49 -0700498 ${SMALI} -JXmx512m assemble ${SMALI_ARGS} --output smali_classes2.dex `find smali-multidex -name '*.smali'`
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000499
Igor Murashkin4014d842017-07-11 11:58:44 -0700500 # Merge smali_classes2.dex into classes2.dex
501 make_dexmerge classes2.dex smali_classes2.dex
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000502fi
503
504
505if [ ${HAS_SRC_EX} = "true" ]; then
506 if [ ${USE_JACK} = "true" ]; then
507 # Rename previous "classes.dex" so it is not overwritten.
508 mv classes.dex classes-1.dex
509 #TODO find another way to append src.jack to the jack classpath
510 ${JACK}:src.jack ${JACK_ARGS} --output-dex . src-ex
511 zip $TEST_NAME-ex.jar classes.dex
512 # Restore previous "classes.dex" so it can be zipped.
513 mv classes-1.dex classes.dex
514 else
Igor Murashkin829da132017-06-21 14:47:12 -0700515 # Build src-ex into classes-ex.
516 # Includes 'src', 'src-art' source when compiling classes-ex, but exclude their .class files.
517 if [[ "${HAS_SRC}" == "true" ]]; then
518 mkdir -p classes-tmp-for-ex
519 ${JAVAC} ${JAVAC_ARGS} -d classes-tmp-for-ex `find src -name '*.java'`
520 src_tmp_for_ex="-cp classes-tmp-for-ex"
521 fi
522 if [[ "${HAS_SRC_ART}" == "true" ]]; then
523 mkdir -p classes-tmp-for-ex
524 javac_with_bootclasspath ${JAVAC_ARGS} -d classes-tmp-for-ex `find src-art -name '*.java'`
525 src_tmp_for_ex="-cp classes-tmp-for-ex"
526 fi
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000527 mkdir classes-ex
Igor Murashkin829da132017-06-21 14:47:12 -0700528 ${JAVAC} ${JAVAC_ARGS} -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'`
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000529 if [ ${NEED_DEX} = "true" ]; then
Igor Murashkin2a337752017-06-16 14:34:40 +0000530 make_dex classes-ex
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000531
532 # quick shuffle so that the stored name is "classes.dex"
533 mv classes.dex classes-1.dex
534 mv classes-ex.dex classes.dex
535 zip $TEST_NAME-ex.jar classes.dex
536 mv classes.dex classes-ex.dex
537 mv classes-1.dex classes.dex
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000538 fi
539 fi
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000540fi
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100541
David Brazdil11b67b22018-01-18 16:41:40 +0000542# Apply hiddenapi on the dex files if the test has API list file(s).
543if [ ${NEED_DEX} = "true" -a ${USE_HIDDENAPI} = "true" -a ${HAS_HIDDENAPI_SPEC} = "true" ]; then
544 if $(has_multidex); then
545 make_hiddenapi classes.dex classes2.dex
546 else
547 make_hiddenapi classes.dex
548 fi
549fi
550
Igor Murashkin4014d842017-07-11 11:58:44 -0700551# Create a single dex jar with two dex files for multidex.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000552if [ ${NEED_DEX} = "true" ]; then
David Brazdil11b67b22018-01-18 16:41:40 +0000553 if $(has_multidex); then
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000554 zip $TEST_NAME.jar classes.dex classes2.dex
555 else
556 zip $TEST_NAME.jar classes.dex
557 fi
Nicolas Geoffray12508612014-11-05 12:34:24 +0000558fi