blob: 3e6577cfda483758d206beba8b976df538ce35f9 [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
Igor Murashkin2de6e082018-02-28 15:25:23 -080020if [[ $# -le 0 ]]; then
21 echo 'Error:' '$0 should have the parameters from the "build" script forwarded to it' >&2
22 echo 'Error: An example of how do it correctly is ./default-build "$@"'
23 exit 1
24fi
25
Alex Light6a439bc2015-10-26 17:52:36 -070026# Set default values for directories.
27if [ -d smali ]; then
28 HAS_SMALI=true
29else
30 HAS_SMALI=false
31fi
32
Igor Murashkin4014d842017-07-11 11:58:44 -070033# .j files in jasmin get compiled into classes.jar
34if [ -d jasmin ]; then
35 HAS_JASMIN=true
36else
37 HAS_JASMIN=false
38fi
39
Alex Light6a439bc2015-10-26 17:52:36 -070040if [ -d src ]; then
41 HAS_SRC=true
42else
43 HAS_SRC=false
44fi
45
Igor Murashkin1c843e92017-06-19 14:33:06 -070046# .java files in src-art get compiled with libcore on the bootclasspath
47if [ -d src-art ]; then
48 HAS_SRC_ART=true
49else
50 HAS_SRC_ART=false
51fi
52
Alex Light6a439bc2015-10-26 17:52:36 -070053if [ -d src2 ]; then
54 HAS_SRC2=true
55else
56 HAS_SRC2=false
57fi
58
59if [ -d src-multidex ]; then
60 HAS_SRC_MULTIDEX=true
61else
62 HAS_SRC_MULTIDEX=false
63fi
64
Alex Lightfedd91d2016-01-07 14:49:16 -080065if [ -d smali-multidex ]; then
66 HAS_SMALI_MULTIDEX=true
67else
68 HAS_SMALI_MULTIDEX=false
69fi
70
Igor Murashkin4014d842017-07-11 11:58:44 -070071# .j files in jasmin-multidex get compiled into classes2.jar
72if [ -d jasmin-multidex ]; then
73 HAS_JASMIN_MULTIDEX=true
74else
75 HAS_JASMIN_MULTIDEX=false
76fi
77
Alex Light6a439bc2015-10-26 17:52:36 -070078if [ -d src-ex ]; then
79 HAS_SRC_EX=true
80else
81 HAS_SRC_EX=false
82fi
83
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +000084if [ -d src-dex2oat-unresolved ]; then
85 HAS_SRC_DEX2OAT_UNRESOLVED=true
86else
87 HAS_SRC_DEX2OAT_UNRESOLVED=false
88fi
89
David Brazdil11b67b22018-01-18 16:41:40 +000090if [ -f api-light-greylist.txt -o -f api-dark-greylist.txt -o -f api-blacklist.txt ]; then
91 HAS_HIDDENAPI_SPEC=true
92else
93 HAS_HIDDENAPI_SPEC=false
94fi
95
96# USE_HIDDENAPI=false run-test... will disable hiddenapi.
97if [ -z "${USE_HIDDENAPI}" ]; then
98 USE_HIDDENAPI=true
99fi
100
Igor Murashkine5181932017-06-15 16:03:50 -0700101# DESUGAR=false run-test... will disable desugar.
102if [[ "$DESUGAR" == false ]]; then
103 USE_DESUGAR=false
104fi
105
Igor Murashkin271a0f82017-02-14 21:14:17 +0000106# Allow overriding ZIP_COMPRESSION_METHOD with e.g. 'store'
107ZIP_COMPRESSION_METHOD="deflate"
108# Align every ZIP file made by calling $ZIPALIGN command?
109WITH_ZIP_ALIGN=false
110ZIP_ALIGN_BYTES="-1"
111
Igor Murashkin69196392017-06-16 15:25:32 -0700112DX_FLAGS="--min-sdk-version=24"
113DX_VM_FLAGS=""
Alex Light6a439bc2015-10-26 17:52:36 -0700114EXPERIMENTAL=""
115
Igor Murashkin2a337752017-06-16 14:34:40 +0000116BUILD_MODE="target"
117DEV_MODE="no"
118
Alex Lightea1e7702016-07-11 13:39:55 -0700119# The key for default arguments if no experimental things are enabled.
120DEFAULT_EXPERIMENT="no-experiment"
121
Alex Light6a439bc2015-10-26 17:52:36 -0700122# Setup experimental flag mappings in a bash associative array.
123declare -A JACK_EXPERIMENTAL_ARGS
Alex Lightdba61482016-12-21 08:20:29 -0800124JACK_EXPERIMENTAL_ARGS["agents"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24"
Yohann Roussel4b495672016-03-21 16:26:02 +0100125JACK_EXPERIMENTAL_ARGS["default-methods"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24"
126JACK_EXPERIMENTAL_ARGS["lambdas"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24"
mikaelpeltier3233dcc2016-11-18 14:23:45 +0100127JACK_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 -0800128JACK_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 +0000129
Alex Lightb55f1ac2016-04-12 15:50:55 -0700130declare -A SMALI_EXPERIMENTAL_ARGS
Ben Gruver14fc9db2017-04-28 15:30:49 -0700131SMALI_EXPERIMENTAL_ARGS["default-methods"]="--api 24"
132SMALI_EXPERIMENTAL_ARGS["method-handles"]="--api 26"
Orion Hodson928033d2018-02-07 05:30:54 +0000133SMALI_EXPERIMENTAL_ARGS["var-handles"]="--api 26"
Ben Gruver14fc9db2017-04-28 15:30:49 -0700134SMALI_EXPERIMENTAL_ARGS["agents"]="--api 26"
Alex Lightb55f1ac2016-04-12 15:50:55 -0700135
Alex Lightea1e7702016-07-11 13:39:55 -0700136declare -A JAVAC_EXPERIMENTAL_ARGS
137JAVAC_EXPERIMENTAL_ARGS["default-methods"]="-source 1.8 -target 1.8"
138JAVAC_EXPERIMENTAL_ARGS["lambdas"]="-source 1.8 -target 1.8"
Narayan Kamath9823e782016-08-03 12:46:58 +0100139JAVAC_EXPERIMENTAL_ARGS["method-handles"]="-source 1.8 -target 1.8"
Orion Hodson58143d22018-02-20 08:44:20 +0000140JAVAC_EXPERIMENTAL_ARGS["parameter-annotations"]="-source 1.8 -target 1.8"
Orion Hodson928033d2018-02-07 05:30:54 +0000141JAVAC_EXPERIMENTAL_ARGS["var-handles"]="-source 1.8 -target 1.8"
Alex Light4eec3c52017-04-14 13:17:26 -0700142JAVAC_EXPERIMENTAL_ARGS[${DEFAULT_EXPERIMENT}]="-source 1.8 -target 1.8"
Alex Lightdba61482016-12-21 08:20:29 -0800143JAVAC_EXPERIMENTAL_ARGS["agents"]="-source 1.8 -target 1.8"
Alex Lightea1e7702016-07-11 13:39:55 -0700144
Igor Murashkin69196392017-06-16 15:25:32 -0700145declare -A DX_EXPERIMENTAL_ARGS
146DX_EXPERIMENTAL_ARGS["method-handles"]="--min-sdk-version=26"
Orion Hodson58143d22018-02-20 08:44:20 +0000147DX_EXPERIMENTAL_ARGS["parameter-annotations"]="--min-sdk-version=25"
Orion Hodson928033d2018-02-07 05:30:54 +0000148DX_EXPERIMENTAL_ARGS["var-handles"]="--min-sdk-version=26"
Igor Murashkin69196392017-06-16 15:25:32 -0700149
David Brazdil4846d132015-01-15 19:07:08 +0000150while true; do
151 if [ "x$1" = "x--dx-option" ]; then
152 shift
Orion Hodsone1fb77f2017-02-27 13:57:18 +0000153 option="$1"
David Brazdil4846d132015-01-15 19:07:08 +0000154 DX_FLAGS="${DX_FLAGS} $option"
155 shift
Igor Murashkin69196392017-06-16 15:25:32 -0700156 elif [ "x$1" = "x--dx-vm-option" ]; then
157 shift
158 option="$1"
159 DX_VM_FLAGS="${DX_VM_FLAGS} $option"
160 shift
Alex Light6a439bc2015-10-26 17:52:36 -0700161 elif [ "x$1" = "x--no-src" ]; then
162 HAS_SRC=false
163 shift
164 elif [ "x$1" = "x--no-src2" ]; then
165 HAS_SRC2=false
166 shift
167 elif [ "x$1" = "x--no-src-multidex" ]; then
168 HAS_SRC_MULTIDEX=false
169 shift
Alex Lightfedd91d2016-01-07 14:49:16 -0800170 elif [ "x$1" = "x--no-smali-multidex" ]; then
171 HAS_SMALI_MULTIDEX=false
172 shift
Alex Light6a439bc2015-10-26 17:52:36 -0700173 elif [ "x$1" = "x--no-src-ex" ]; then
174 HAS_SRC_EX=false
175 shift
176 elif [ "x$1" = "x--no-smali" ]; then
177 HAS_SMALI=false
178 shift
179 elif [ "x$1" = "x--experimental" ]; then
180 shift
Alex Lightea1e7702016-07-11 13:39:55 -0700181 # We have a specific experimental configuration so don't use the default.
182 DEFAULT_EXPERIMENT=""
Alex Light6a439bc2015-10-26 17:52:36 -0700183 EXPERIMENTAL="${EXPERIMENTAL} $1"
184 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000185 elif [ "x$1" = "x--zip-compression-method" ]; then
186 # Allow using different zip compression method, e.g. 'store'
187 shift
188 ZIP_COMPRESSION_METHOD="$1"
189 shift
190 elif [ "x$1" = "x--zip-align" ]; then
191 # Align ZIP entries to some # of bytes.
192 shift
193 WITH_ZIP_ALIGN=true
194 ZIP_ALIGN_BYTES="$1"
195 shift
Igor Murashkin2a337752017-06-16 14:34:40 +0000196 elif [ "x$1" = "x--host" ]; then
197 BUILD_MODE="host"
198 shift
199 elif [ "x$1" = "x--target" ]; then
200 BUILD_MODE="target"
201 shift
Igor Murashkin2de6e082018-02-28 15:25:23 -0800202 elif [ "x$1" = "x--jvm" ]; then
203 BUILD_MODE="jvm"
204 shift
Igor Murashkin2a337752017-06-16 14:34:40 +0000205 elif [ "x$1" = "x--dev" ]; then
206 DEV_MODE="yes"
207 shift
David Brazdil4846d132015-01-15 19:07:08 +0000208 elif expr "x$1" : "x--" >/dev/null 2>&1; then
209 echo "unknown $0 option: $1" 1>&2
210 exit 1
211 else
212 break
213 fi
214done
215
Igor Murashkin2de6e082018-02-28 15:25:23 -0800216if [[ $BUILD_MODE == jvm ]]; then
217 # Does not need desugar on jvm because it supports the latest functionality.
218 USE_DESUGAR=false
219 # Do not attempt to build src-art directories on jvm, it would fail without libcore.
220 HAS_SRC_ART=false
221fi
222
Alex Lightea1e7702016-07-11 13:39:55 -0700223# Be sure to get any default arguments if not doing any experiments.
224EXPERIMENTAL="${EXPERIMENTAL} ${DEFAULT_EXPERIMENT}"
225
Sebastien Hertz361ad552017-01-04 16:07:57 +0100226if [ "${JACK_SERVER}" = "false" ]; then
227 # Run in single-threaded mode for the continuous buildbot.
228 JACK_ARGS="${JACK_ARGS} -D sched.runner=single-threaded"
229else
230 # Run with 4 threads to reduce memory footprint and thread contention.
231 JACK_ARGS="${JACK_ARGS} -D sched.runner=multi-threaded"
232 JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.kind=fixed"
233 JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.fixed.count=4"
234fi
235
Alex Light6a439bc2015-10-26 17:52:36 -0700236# Add args from the experimental mappings.
237for experiment in ${EXPERIMENTAL}; do
238 JACK_ARGS="${JACK_ARGS} ${JACK_EXPERIMENTAL_ARGS[${experiment}]}"
Alex Lightb55f1ac2016-04-12 15:50:55 -0700239 SMALI_ARGS="${SMALI_ARGS} ${SMALI_EXPERIMENTAL_ARGS[${experiment}]}"
Alex Lightea1e7702016-07-11 13:39:55 -0700240 JAVAC_ARGS="${JAVAC_ARGS} ${JAVAC_EXPERIMENTAL_ARGS[${experiment}]}"
Igor Murashkin69196392017-06-16 15:25:32 -0700241 DX_FLAGS="${DX_FLAGS} ${DX_EXPERIMENTAL_ARGS[${experiment}]}"
Alex Light6a439bc2015-10-26 17:52:36 -0700242done
243
Igor Murashkin271a0f82017-02-14 21:14:17 +0000244#########################################
245
246# Catch all commands to 'ZIP' and prepend extra flags.
247# Optionally, zipalign results to some alignment.
248function zip() {
249 local zip_target="$1"
250 local entry_src="$2"
251 shift 2
252
253 command zip --compression-method "$ZIP_COMPRESSION_METHOD" "$zip_target" "$entry_src" "$@"
254
255 if "$WITH_ZIP_ALIGN"; then
256 # zipalign does not operate in-place, so write results to a temp file.
257 local tmp_file="$(mktemp)"
258 "$ZIPALIGN" -f "$ZIP_ALIGN_BYTES" "$zip_target" "$tmp_file"
259 # replace original zip target with our temp file.
260 mv "$tmp_file" "$zip_target"
261 fi
262}
263
Igor Murashkin4014d842017-07-11 11:58:44 -0700264function make_jasmin() {
265 local out_directory="$1"
266 shift
267 local jasmin_sources=("$@")
268
269 mkdir -p "$out_directory"
270
271 if [[ $DEV_MODE == yes ]]; then
272 echo ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}"
273 ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}"
274 else
275 ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}" >/dev/null
276 fi
277}
278
Igor Murashkin2a337752017-06-16 14:34:40 +0000279function desugar() {
Igor Murashkin2de6e082018-02-28 15:25:23 -0800280 local desugar_args="--mode=$BUILD_MODE"
Igor Murashkin2a337752017-06-16 14:34:40 +0000281
282 if [[ $DEV_MODE == yes ]]; then
283 desugar_args="$desugar_args --show-commands"
284 fi
285
Igor Murashkine5181932017-06-15 16:03:50 -0700286 "$DESUGAR" --core-only $desugar_args "$@"
Igor Murashkin2a337752017-06-16 14:34:40 +0000287}
288
Igor Murashkin2de6e082018-02-28 15:25:23 -0800289# Like regular javac but may include libcore on the bootclasspath.
Igor Murashkin1c843e92017-06-19 14:33:06 -0700290function javac_with_bootclasspath {
Igor Murashkin2de6e082018-02-28 15:25:23 -0800291 local helper_args="--mode=$BUILD_MODE"
Igor Murashkin1c843e92017-06-19 14:33:06 -0700292
293 if [[ $DEV_MODE == yes ]]; then
Igor Murashkin2de6e082018-02-28 15:25:23 -0800294 helper_args="$helper_args --show-commands"
Igor Murashkin1c843e92017-06-19 14:33:06 -0700295 fi
296
Igor Murashkin2de6e082018-02-28 15:25:23 -0800297 # build with libcore for host and target, or openjdk for jvm
298 "$ANDROID_BUILD_TOP/art/tools/javac-helper.sh" --core-only $helper_args ${JAVAC_ARGS} "$@"
Igor Murashkin1c843e92017-06-19 14:33:06 -0700299}
300
Igor Murashkin2a337752017-06-16 14:34:40 +0000301# Make a "dex" file given a directory of classes in $1.
302# Also calls desugar on the classes first to convert lambdas.
303function make_dex() {
304 local name="$1"
305
306 local dx_input
307 if [[ "$USE_DESUGAR" == "true" ]]; then
308 # Make a jar first so desugar doesn't need every .class file individually.
309 jar cf "$name.before-desugar.jar" -C "$name" .
310
311 dx_input="${name}.desugar.jar"
312
313 # Make desugared JAR.
314 desugar --input "$name.before-desugar.jar" --output "$dx_input"
315 else
316 dx_input="${name}"
317 fi
318
Alan Leung0afa07a2017-10-03 16:56:30 -0700319 local dexer="${DX}"
320 if [ ${USE_D8} = "true" ]; then
Alan Leunga4ba9b52017-11-16 00:19:18 -0800321 dexer="${ANDROID_HOST_OUT}/bin/d8-compat-dx"
Alan Leung0afa07a2017-10-03 16:56:30 -0700322 fi
323
Igor Murashkin2a337752017-06-16 14:34:40 +0000324 # Make dex file from desugared JAR.
Alan Leung0afa07a2017-10-03 16:56:30 -0700325 ${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 +0000326}
327
Igor Murashkin4014d842017-07-11 11:58:44 -0700328# Merge all the dex files in $1..$N into $1. Skip non-existing files, but at least 1 file must exist.
329function make_dexmerge() {
330 # Dex file that acts as the destination.
331 local dst_file="$1"
332
333 # Dex files that act as the source.
334 local dex_files_to_merge=()
335
336 # Skip any non-existing files.
337 while [[ $# -gt 0 ]]; do
338 if [[ -e "$1" ]]; then
339 dex_files_to_merge+=("$1")
340 fi
341 shift
342 done
343
344 # Should have at least 1 dex_files_to_merge here, otherwise dxmerger will print the help.
345 ${DXMERGER} "$dst_file" "${dex_files_to_merge[@]}"
346}
347
David Brazdil11b67b22018-01-18 16:41:40 +0000348function make_hiddenapi() {
349 local args=()
350 while [[ $# -gt 0 ]]; do
351 args+=("--dex=$1")
352 shift
353 done
354 if [ -f api-light-greylist.txt ]; then
355 args+=("--light-greylist=api-light-greylist.txt")
356 fi
357 if [ -f api-dark-greylist.txt ]; then
358 args+=("--dark-greylist=api-dark-greylist.txt")
359 fi
360 if [ -f api-blacklist.txt ]; then
361 args+=("--blacklist=api-blacklist.txt")
362 fi
363 ${HIDDENAPI} "${args[@]}"
364}
365
Igor Murashkin1c843e92017-06-19 14:33:06 -0700366# Print the directory name only if it exists.
367function maybe_dir() {
368 local dirname="$1"
369 if [[ -d "$dirname" ]]; then
370 echo "$dirname"
371 fi
372}
373
Stephen Kyle40d35182014-10-03 13:47:56 +0100374if [ -e classes.dex ]; then
375 zip $TEST_NAME.jar classes.dex
376 exit 0
377fi
378
David Brazdil11b67b22018-01-18 16:41:40 +0000379# Helper function for a common test. Evaluate with $(has_mutlidex).
380function has_multidex() {
381 echo [ ${HAS_SRC_MULTIDEX} = "true" \
382 -o ${HAS_JASMIN_MULTIDEX} = "true" \
383 -o ${HAS_SMALI_MULTIDEX} = "true" ]
384}
385
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000386if [ ${HAS_SRC_DEX2OAT_UNRESOLVED} = "true" ]; then
Igor Murashkin2de6e082018-02-28 15:25:23 -0800387 mkdir -p classes
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000388 mkdir classes-ex
Igor Murashkin2de6e082018-02-28 15:25:23 -0800389 javac_with_bootclasspath -implicit:none -sourcepath src-dex2oat-unresolved -d classes `find src -name '*.java'`
390 javac_with_bootclasspath -implicit:none -sourcepath src -d classes-ex `find src-dex2oat-unresolved -name '*.java'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000391 if [ ${USE_JACK} = "true" ]; then
392 jar cf classes.jill.jar -C classes .
393 jar cf classes-ex.jill.jar -C classes-ex .
394
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000395 ${JACK} --import classes-ex.jill.jar --output-dex .
396 zip ${TEST_NAME}-ex.jar classes.dex
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000397 ${JACK} --import classes.jill.jar --output-dex .
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000398 else
399 if [ ${NEED_DEX} = "true" ]; then
Igor Murashkin2a337752017-06-16 14:34:40 +0000400 make_dex classes-ex
Igor Murashkin6c946b52017-06-16 14:27:47 -0700401 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 +0000402 zip ${TEST_NAME}-ex.jar classes.dex
Igor Murashkin2a337752017-06-16 14:34:40 +0000403 make_dex classes
Sebastien Hertz4856ca72016-03-03 18:08:17 +0100404 fi
Alex Light6a439bc2015-10-26 17:52:36 -0700405 fi
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100406else
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100407 if [ ${USE_JACK} = "true" ]; then
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000408 # Jack toolchain
Igor Murashkin1c843e92017-06-19 14:33:06 -0700409 if [[ "$HAS_SRC" == true || "$HAS_SRC_ART" == true ]]; then
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000410 if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then
411 # Compile src and src-multidex in the same .jack file. We will apply multidex partitioning
412 # when creating the output .dex file.
Igor Murashkin1c843e92017-06-19 14:33:06 -0700413 ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) src-multidex $(maybe_dir src-art)
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000414 jack_extra_args="${jack_extra_args} -D jack.dex.output.policy=minimal-multidex"
415 jack_extra_args="${jack_extra_args} -D jack.preprocessor=true"
416 jack_extra_args="${jack_extra_args} -D jack.preprocessor.file=multidex.jpp"
417 else
Igor Murashkin1c843e92017-06-19 14:33:06 -0700418 ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) $(maybe_dir src-art)
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000419 fi
420 jack_extra_args="${jack_extra_args} --import src.jack"
421 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700422
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000423 if [ "${HAS_SRC2}" = "true" ]; then
424 ${JACK} ${JACK_ARGS} --output-jack src2.jack src2
425 # In case of duplicate classes, we want to take into account the classes from src2. Therefore
426 # we apply the 'keep-first' policy and import src2.jack file *before* the src.jack file.
427 jack_extra_args="${jack_extra_args} -D jack.import.type.policy=keep-first"
428 jack_extra_args="--import src2.jack ${jack_extra_args}"
429 fi
430
431 # Compile jack files into a DEX file.
Igor Murashkin4014d842017-07-11 11:58:44 -0700432 if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ] || [ "${HAS_SRC_ART}" = "true" ]; then
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000433 ${JACK} ${JACK_ARGS} ${jack_extra_args} --output-dex .
434 fi
435 else
436 # Legacy toolchain with javac+dx
437 if [ "${HAS_SRC}" = "true" ]; then
Igor Murashkin2de6e082018-02-28 15:25:23 -0800438 mkdir -p classes
439 javac_with_bootclasspath -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000440 fi
441
Igor Murashkin1c843e92017-06-19 14:33:06 -0700442 if [ "${HAS_SRC_ART}" = "true" ]; then
443 mkdir -p classes
Igor Murashkin2de6e082018-02-28 15:25:23 -0800444 javac_with_bootclasspath -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'`
Igor Murashkin1c843e92017-06-19 14:33:06 -0700445 fi
446
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000447 if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then
448 mkdir classes2
Igor Murashkin2de6e082018-02-28 15:25:23 -0800449 javac_with_bootclasspath -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000450 if [ ${NEED_DEX} = "true" ]; then
Igor Murashkin2a337752017-06-16 14:34:40 +0000451 make_dex classes2
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000452 fi
453 fi
454
455 if [ "${HAS_SRC2}" = "true" ]; then
456 mkdir -p classes
Igor Murashkin2de6e082018-02-28 15:25:23 -0800457 javac_with_bootclasspath -classpath classes -d classes `find src2 -name '*.java'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000458 fi
459
Igor Murashkin1c843e92017-06-19 14:33:06 -0700460 if [[ "${HAS_SRC}" == "true" || "${HAS_SRC2}" == "true" || "${HAS_SRC_ART}" == "true" ]]; then
Igor Murashkin4014d842017-07-11 11:58:44 -0700461 if [ ${NEED_DEX} = "true" ]; then
Igor Murashkin2a337752017-06-16 14:34:40 +0000462 make_dex classes
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000463 fi
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100464 fi
Elliott Hughesc717eef2012-06-15 16:01:26 -0700465 fi
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000466fi
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000467
Igor Murashkin4014d842017-07-11 11:58:44 -0700468if [[ "${HAS_JASMIN}" == true ]]; then
469 # Compile Jasmin classes as if they were part of the classes.dex file.
470 make_jasmin jasmin_classes $(find 'jasmin' -name '*.j')
471 if [[ "${NEED_DEX}" == "true" ]]; then
472 # Disable desugar because it won't handle intentional linkage errors.
473 USE_DESUGAR=false make_dex jasmin_classes
474 make_dexmerge classes.dex jasmin_classes.dex
475 else
476 # Move jasmin classes into classes directory so that they are picked up with -cp classes.
477 mkdir -p classes
478 mv jasmin_classes/* classes
479 fi
480fi
481
Andreas Gampe2b936812017-02-07 16:03:57 -0800482if [ "${HAS_SMALI}" = "true" -a ${NEED_DEX} = "true" ]; then
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000483 # Compile Smali classes
Ben Gruver14fc9db2017-04-28 15:30:49 -0700484 ${SMALI} -JXmx512m assemble ${SMALI_ARGS} --output smali_classes.dex `find smali -name '*.smali'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000485
Igor Murashkin4014d842017-07-11 11:58:44 -0700486 # Merge smali files into classes.dex, this takes priority over any jasmin files.
487 make_dexmerge classes.dex smali_classes.dex
488fi
489
490# Compile Jasmin classes in jasmin-multidex as if they were part of the classes2.jar
491if [[ "$HAS_JASMIN_MULTIDEX" == true ]]; then
492 make_jasmin jasmin_classes2 $(find 'jasmin-multidex' -name '*.j')
493
494 if [[ "${NEED_DEX}" == "true" ]]; then
495 # Disable desugar because it won't handle intentional linkage errors.
496 USE_DESUGAR=false make_dex jasmin_classes2
497
498 # Merge jasmin_classes2.dex into classes2.dex
499 make_dexmerge classes2.dex jasmin_classes2.dex
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000500 else
Igor Murashkin4014d842017-07-11 11:58:44 -0700501 # Move jasmin classes into classes2 directory so that they are picked up with -cp classes2.
502 mkdir -p classes2
503 mv jasmin_classes2/* classes2
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000504 fi
505fi
506
Andreas Gampe2b936812017-02-07 16:03:57 -0800507if [ "${HAS_SMALI_MULTIDEX}" = "true" -a ${NEED_DEX} = "true" ]; then
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000508 # Compile Smali classes
Ben Gruver14fc9db2017-04-28 15:30:49 -0700509 ${SMALI} -JXmx512m assemble ${SMALI_ARGS} --output smali_classes2.dex `find smali-multidex -name '*.smali'`
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000510
Igor Murashkin4014d842017-07-11 11:58:44 -0700511 # Merge smali_classes2.dex into classes2.dex
512 make_dexmerge classes2.dex smali_classes2.dex
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000513fi
514
515
516if [ ${HAS_SRC_EX} = "true" ]; then
517 if [ ${USE_JACK} = "true" ]; then
518 # Rename previous "classes.dex" so it is not overwritten.
519 mv classes.dex classes-1.dex
520 #TODO find another way to append src.jack to the jack classpath
521 ${JACK}:src.jack ${JACK_ARGS} --output-dex . src-ex
522 zip $TEST_NAME-ex.jar classes.dex
523 # Restore previous "classes.dex" so it can be zipped.
524 mv classes-1.dex classes.dex
525 else
Igor Murashkin829da132017-06-21 14:47:12 -0700526 # Build src-ex into classes-ex.
527 # Includes 'src', 'src-art' source when compiling classes-ex, but exclude their .class files.
528 if [[ "${HAS_SRC}" == "true" ]]; then
529 mkdir -p classes-tmp-for-ex
Igor Murashkin2de6e082018-02-28 15:25:23 -0800530 javac_with_bootclasspath -d classes-tmp-for-ex `find src -name '*.java'`
Igor Murashkin829da132017-06-21 14:47:12 -0700531 src_tmp_for_ex="-cp classes-tmp-for-ex"
532 fi
533 if [[ "${HAS_SRC_ART}" == "true" ]]; then
534 mkdir -p classes-tmp-for-ex
Igor Murashkin2de6e082018-02-28 15:25:23 -0800535 javac_with_bootclasspath -d classes-tmp-for-ex `find src-art -name '*.java'`
Igor Murashkin829da132017-06-21 14:47:12 -0700536 src_tmp_for_ex="-cp classes-tmp-for-ex"
537 fi
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000538 mkdir classes-ex
Igor Murashkin2de6e082018-02-28 15:25:23 -0800539 javac_with_bootclasspath -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'`
Nicolas Geoffray404b5bf2016-03-16 12:39:17 +0000540 fi
Nicolas Geoffray44fd0e52016-03-16 15:16:06 +0000541fi
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100542
Igor Murashkin2de6e082018-02-28 15:25:23 -0800543if [[ -d classes-ex ]] && [ ${NEED_DEX} = "true" ]; then
544 make_dex classes-ex
545
546 # quick shuffle so that the stored name is "classes.dex"
547 mv classes.dex classes-1.dex
548 mv classes-ex.dex classes.dex
549 zip $TEST_NAME-ex.jar classes.dex
550 mv classes.dex classes-ex.dex
551 mv classes-1.dex classes.dex
552fi
553
David Brazdil11b67b22018-01-18 16:41:40 +0000554# Apply hiddenapi on the dex files if the test has API list file(s).
555if [ ${NEED_DEX} = "true" -a ${USE_HIDDENAPI} = "true" -a ${HAS_HIDDENAPI_SPEC} = "true" ]; then
556 if $(has_multidex); then
557 make_hiddenapi classes.dex classes2.dex
558 else
559 make_hiddenapi classes.dex
560 fi
561fi
562
Igor Murashkin4014d842017-07-11 11:58:44 -0700563# Create a single dex jar with two dex files for multidex.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000564if [ ${NEED_DEX} = "true" ]; then
David Brazdil11b67b22018-01-18 16:41:40 +0000565 if $(has_multidex); then
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000566 zip $TEST_NAME.jar classes.dex classes2.dex
567 else
568 zip $TEST_NAME.jar classes.dex
569 fi
Nicolas Geoffray12508612014-11-05 12:34:24 +0000570fi