jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | #!/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. |
| 18 | set -e |
| 19 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 20 | # Set default values for directories. |
| 21 | if [ -d smali ]; then |
| 22 | HAS_SMALI=true |
| 23 | else |
| 24 | HAS_SMALI=false |
| 25 | fi |
| 26 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 27 | # .j files in jasmin get compiled into classes.jar |
| 28 | if [ -d jasmin ]; then |
| 29 | HAS_JASMIN=true |
| 30 | else |
| 31 | HAS_JASMIN=false |
| 32 | fi |
| 33 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 34 | if [ -d src ]; then |
| 35 | HAS_SRC=true |
| 36 | else |
| 37 | HAS_SRC=false |
| 38 | fi |
| 39 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 40 | # .java files in src-art get compiled with libcore on the bootclasspath |
| 41 | if [ -d src-art ]; then |
| 42 | HAS_SRC_ART=true |
| 43 | else |
| 44 | HAS_SRC_ART=false |
| 45 | fi |
| 46 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 47 | if [ -d src2 ]; then |
| 48 | HAS_SRC2=true |
| 49 | else |
| 50 | HAS_SRC2=false |
| 51 | fi |
| 52 | |
| 53 | if [ -d src-multidex ]; then |
| 54 | HAS_SRC_MULTIDEX=true |
| 55 | else |
| 56 | HAS_SRC_MULTIDEX=false |
| 57 | fi |
| 58 | |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 59 | if [ -d smali-multidex ]; then |
| 60 | HAS_SMALI_MULTIDEX=true |
| 61 | else |
| 62 | HAS_SMALI_MULTIDEX=false |
| 63 | fi |
| 64 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 65 | # .j files in jasmin-multidex get compiled into classes2.jar |
| 66 | if [ -d jasmin-multidex ]; then |
| 67 | HAS_JASMIN_MULTIDEX=true |
| 68 | else |
| 69 | HAS_JASMIN_MULTIDEX=false |
| 70 | fi |
| 71 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 72 | if [ -d src-ex ]; then |
| 73 | HAS_SRC_EX=true |
| 74 | else |
| 75 | HAS_SRC_EX=false |
| 76 | fi |
| 77 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 78 | if [ -d src-dex2oat-unresolved ]; then |
| 79 | HAS_SRC_DEX2OAT_UNRESOLVED=true |
| 80 | else |
| 81 | HAS_SRC_DEX2OAT_UNRESOLVED=false |
| 82 | fi |
| 83 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 84 | if [ -f api-light-greylist.txt -o -f api-dark-greylist.txt -o -f api-blacklist.txt ]; then |
| 85 | HAS_HIDDENAPI_SPEC=true |
| 86 | else |
| 87 | HAS_HIDDENAPI_SPEC=false |
| 88 | fi |
| 89 | |
| 90 | # USE_HIDDENAPI=false run-test... will disable hiddenapi. |
| 91 | if [ -z "${USE_HIDDENAPI}" ]; then |
| 92 | USE_HIDDENAPI=true |
| 93 | fi |
| 94 | |
Igor Murashkin | e518193 | 2017-06-15 16:03:50 -0700 | [diff] [blame] | 95 | # DESUGAR=false run-test... will disable desugar. |
| 96 | if [[ "$DESUGAR" == false ]]; then |
| 97 | USE_DESUGAR=false |
| 98 | fi |
| 99 | |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 100 | # Allow overriding ZIP_COMPRESSION_METHOD with e.g. 'store' |
| 101 | ZIP_COMPRESSION_METHOD="deflate" |
| 102 | # Align every ZIP file made by calling $ZIPALIGN command? |
| 103 | WITH_ZIP_ALIGN=false |
| 104 | ZIP_ALIGN_BYTES="-1" |
| 105 | |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 106 | DX_FLAGS="--min-sdk-version=24" |
| 107 | DX_VM_FLAGS="" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 108 | EXPERIMENTAL="" |
| 109 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 110 | BUILD_MODE="target" |
| 111 | DEV_MODE="no" |
| 112 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 113 | # The key for default arguments if no experimental things are enabled. |
| 114 | DEFAULT_EXPERIMENT="no-experiment" |
| 115 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 116 | # Setup experimental flag mappings in a bash associative array. |
| 117 | declare -A JACK_EXPERIMENTAL_ARGS |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 118 | JACK_EXPERIMENTAL_ARGS["agents"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24" |
Yohann Roussel | 4b49567 | 2016-03-21 16:26:02 +0100 | [diff] [blame] | 119 | JACK_EXPERIMENTAL_ARGS["default-methods"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24" |
| 120 | JACK_EXPERIMENTAL_ARGS["lambdas"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24" |
mikaelpeltier | 3233dcc | 2016-11-18 14:23:45 +0100 | [diff] [blame] | 121 | JACK_EXPERIMENTAL_ARGS["method-handles"]="-D jack.java.source.version=1.7 -D jack.android.min-api-level=o-b1" |
Alex Light | e4893ee | 2017-02-09 15:28:53 -0800 | [diff] [blame] | 122 | JACK_EXPERIMENTAL_ARGS[${DEFAULT_EXPERIMENT}]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24" |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 123 | |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 124 | declare -A SMALI_EXPERIMENTAL_ARGS |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 125 | SMALI_EXPERIMENTAL_ARGS["default-methods"]="--api 24" |
| 126 | SMALI_EXPERIMENTAL_ARGS["method-handles"]="--api 26" |
| 127 | SMALI_EXPERIMENTAL_ARGS["agents"]="--api 26" |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 128 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 129 | declare -A JAVAC_EXPERIMENTAL_ARGS |
| 130 | JAVAC_EXPERIMENTAL_ARGS["default-methods"]="-source 1.8 -target 1.8" |
| 131 | JAVAC_EXPERIMENTAL_ARGS["lambdas"]="-source 1.8 -target 1.8" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 132 | JAVAC_EXPERIMENTAL_ARGS["method-handles"]="-source 1.8 -target 1.8" |
Orion Hodson | c4d3bf4 | 2018-02-06 16:02:49 +0000 | [diff] [blame^] | 133 | # We need to leave javac at default 1.7 so that dx will continue to work |
Alex Light | 4eec3c5 | 2017-04-14 13:17:26 -0700 | [diff] [blame] | 134 | JAVAC_EXPERIMENTAL_ARGS[${DEFAULT_EXPERIMENT}]="-source 1.8 -target 1.8" |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 135 | JAVAC_EXPERIMENTAL_ARGS["agents"]="-source 1.8 -target 1.8" |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 136 | |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 137 | declare -A DX_EXPERIMENTAL_ARGS |
| 138 | DX_EXPERIMENTAL_ARGS["method-handles"]="--min-sdk-version=26" |
| 139 | |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 140 | while true; do |
| 141 | if [ "x$1" = "x--dx-option" ]; then |
| 142 | shift |
Orion Hodson | e1fb77f | 2017-02-27 13:57:18 +0000 | [diff] [blame] | 143 | option="$1" |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 144 | DX_FLAGS="${DX_FLAGS} $option" |
| 145 | shift |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 146 | elif [ "x$1" = "x--dx-vm-option" ]; then |
| 147 | shift |
| 148 | option="$1" |
| 149 | DX_VM_FLAGS="${DX_VM_FLAGS} $option" |
| 150 | shift |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 151 | elif [ "x$1" = "x--jvm" ]; then |
| 152 | shift |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 153 | elif [ "x$1" = "x--no-src" ]; then |
| 154 | HAS_SRC=false |
| 155 | shift |
| 156 | elif [ "x$1" = "x--no-src2" ]; then |
| 157 | HAS_SRC2=false |
| 158 | shift |
| 159 | elif [ "x$1" = "x--no-src-multidex" ]; then |
| 160 | HAS_SRC_MULTIDEX=false |
| 161 | shift |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 162 | elif [ "x$1" = "x--no-smali-multidex" ]; then |
| 163 | HAS_SMALI_MULTIDEX=false |
| 164 | shift |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 165 | elif [ "x$1" = "x--no-src-ex" ]; then |
| 166 | HAS_SRC_EX=false |
| 167 | shift |
| 168 | elif [ "x$1" = "x--no-smali" ]; then |
| 169 | HAS_SMALI=false |
| 170 | shift |
| 171 | elif [ "x$1" = "x--experimental" ]; then |
| 172 | shift |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 173 | # We have a specific experimental configuration so don't use the default. |
| 174 | DEFAULT_EXPERIMENT="" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 175 | EXPERIMENTAL="${EXPERIMENTAL} $1" |
| 176 | shift |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 177 | elif [ "x$1" = "x--zip-compression-method" ]; then |
| 178 | # Allow using different zip compression method, e.g. 'store' |
| 179 | shift |
| 180 | ZIP_COMPRESSION_METHOD="$1" |
| 181 | shift |
| 182 | elif [ "x$1" = "x--zip-align" ]; then |
| 183 | # Align ZIP entries to some # of bytes. |
| 184 | shift |
| 185 | WITH_ZIP_ALIGN=true |
| 186 | ZIP_ALIGN_BYTES="$1" |
| 187 | shift |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 188 | elif [ "x$1" = "x--host" ]; then |
| 189 | BUILD_MODE="host" |
| 190 | shift |
| 191 | elif [ "x$1" = "x--target" ]; then |
| 192 | BUILD_MODE="target" |
| 193 | shift |
| 194 | elif [ "x$1" = "x--dev" ]; then |
| 195 | DEV_MODE="yes" |
| 196 | shift |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 197 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
| 198 | echo "unknown $0 option: $1" 1>&2 |
| 199 | exit 1 |
| 200 | else |
| 201 | break |
| 202 | fi |
| 203 | done |
| 204 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 205 | # Be sure to get any default arguments if not doing any experiments. |
| 206 | EXPERIMENTAL="${EXPERIMENTAL} ${DEFAULT_EXPERIMENT}" |
| 207 | |
Sebastien Hertz | 361ad55 | 2017-01-04 16:07:57 +0100 | [diff] [blame] | 208 | if [ "${JACK_SERVER}" = "false" ]; then |
| 209 | # Run in single-threaded mode for the continuous buildbot. |
| 210 | JACK_ARGS="${JACK_ARGS} -D sched.runner=single-threaded" |
| 211 | else |
| 212 | # Run with 4 threads to reduce memory footprint and thread contention. |
| 213 | JACK_ARGS="${JACK_ARGS} -D sched.runner=multi-threaded" |
| 214 | JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.kind=fixed" |
| 215 | JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.fixed.count=4" |
| 216 | fi |
| 217 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 218 | # Add args from the experimental mappings. |
| 219 | for experiment in ${EXPERIMENTAL}; do |
| 220 | JACK_ARGS="${JACK_ARGS} ${JACK_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 221 | SMALI_ARGS="${SMALI_ARGS} ${SMALI_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 222 | JAVAC_ARGS="${JAVAC_ARGS} ${JAVAC_EXPERIMENTAL_ARGS[${experiment}]}" |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 223 | DX_FLAGS="${DX_FLAGS} ${DX_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 224 | done |
| 225 | |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 226 | ######################################### |
| 227 | |
| 228 | # Catch all commands to 'ZIP' and prepend extra flags. |
| 229 | # Optionally, zipalign results to some alignment. |
| 230 | function zip() { |
| 231 | local zip_target="$1" |
| 232 | local entry_src="$2" |
| 233 | shift 2 |
| 234 | |
| 235 | command zip --compression-method "$ZIP_COMPRESSION_METHOD" "$zip_target" "$entry_src" "$@" |
| 236 | |
| 237 | if "$WITH_ZIP_ALIGN"; then |
| 238 | # zipalign does not operate in-place, so write results to a temp file. |
| 239 | local tmp_file="$(mktemp)" |
| 240 | "$ZIPALIGN" -f "$ZIP_ALIGN_BYTES" "$zip_target" "$tmp_file" |
| 241 | # replace original zip target with our temp file. |
| 242 | mv "$tmp_file" "$zip_target" |
| 243 | fi |
| 244 | } |
| 245 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 246 | function make_jasmin() { |
| 247 | local out_directory="$1" |
| 248 | shift |
| 249 | local jasmin_sources=("$@") |
| 250 | |
| 251 | mkdir -p "$out_directory" |
| 252 | |
| 253 | if [[ $DEV_MODE == yes ]]; then |
| 254 | echo ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}" |
| 255 | ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}" |
| 256 | else |
| 257 | ${JASMIN} -d "$out_directory" "${jasmin_sources[@]}" >/dev/null |
| 258 | fi |
| 259 | } |
| 260 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 261 | function desugar() { |
| 262 | local desugar_args=--mode=host |
| 263 | if [[ $BUILD_MODE == target ]]; then |
| 264 | desugar_args=--mode=target |
| 265 | fi |
| 266 | |
| 267 | if [[ $DEV_MODE == yes ]]; then |
| 268 | desugar_args="$desugar_args --show-commands" |
| 269 | fi |
| 270 | |
Igor Murashkin | e518193 | 2017-06-15 16:03:50 -0700 | [diff] [blame] | 271 | "$DESUGAR" --core-only $desugar_args "$@" |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 274 | # Like regular javac but includes libcore on the bootclasspath. |
| 275 | function javac_with_bootclasspath { |
| 276 | local javac_args=--mode=host |
| 277 | if [[ $BUILD_MODE == target ]]; then |
| 278 | javac_args=--mode=target |
| 279 | fi |
| 280 | |
| 281 | if [[ $DEV_MODE == yes ]]; then |
| 282 | javac_args="$javac_args --show-commands" |
| 283 | fi |
| 284 | |
| 285 | "$ANDROID_BUILD_TOP/art/tools/javac-helper.sh" --core-only $javac_args "$@" |
| 286 | } |
| 287 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 288 | # Make a "dex" file given a directory of classes in $1. |
| 289 | # Also calls desugar on the classes first to convert lambdas. |
| 290 | function make_dex() { |
| 291 | local name="$1" |
| 292 | |
| 293 | local dx_input |
| 294 | if [[ "$USE_DESUGAR" == "true" ]]; then |
| 295 | # Make a jar first so desugar doesn't need every .class file individually. |
| 296 | jar cf "$name.before-desugar.jar" -C "$name" . |
| 297 | |
| 298 | dx_input="${name}.desugar.jar" |
| 299 | |
| 300 | # Make desugared JAR. |
| 301 | desugar --input "$name.before-desugar.jar" --output "$dx_input" |
| 302 | else |
| 303 | dx_input="${name}" |
| 304 | fi |
| 305 | |
Alan Leung | 0afa07a | 2017-10-03 16:56:30 -0700 | [diff] [blame] | 306 | local dexer="${DX}" |
| 307 | if [ ${USE_D8} = "true" ]; then |
Alan Leung | a4ba9b5 | 2017-11-16 00:19:18 -0800 | [diff] [blame] | 308 | dexer="${ANDROID_HOST_OUT}/bin/d8-compat-dx" |
Alan Leung | 0afa07a | 2017-10-03 16:56:30 -0700 | [diff] [blame] | 309 | fi |
| 310 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 311 | # Make dex file from desugared JAR. |
Alan Leung | 0afa07a | 2017-10-03 16:56:30 -0700 | [diff] [blame] | 312 | ${dexer} -JXmx256m ${DX_VM_FLAGS} --debug --dex --dump-to=${name}.lst --output=${name}.dex --dump-width=1000 ${DX_FLAGS} "${dx_input}" |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 315 | # Merge all the dex files in $1..$N into $1. Skip non-existing files, but at least 1 file must exist. |
| 316 | function make_dexmerge() { |
| 317 | # Dex file that acts as the destination. |
| 318 | local dst_file="$1" |
| 319 | |
| 320 | # Dex files that act as the source. |
| 321 | local dex_files_to_merge=() |
| 322 | |
| 323 | # Skip any non-existing files. |
| 324 | while [[ $# -gt 0 ]]; do |
| 325 | if [[ -e "$1" ]]; then |
| 326 | dex_files_to_merge+=("$1") |
| 327 | fi |
| 328 | shift |
| 329 | done |
| 330 | |
| 331 | # Should have at least 1 dex_files_to_merge here, otherwise dxmerger will print the help. |
| 332 | ${DXMERGER} "$dst_file" "${dex_files_to_merge[@]}" |
| 333 | } |
| 334 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 335 | function make_hiddenapi() { |
| 336 | local args=() |
| 337 | while [[ $# -gt 0 ]]; do |
| 338 | args+=("--dex=$1") |
| 339 | shift |
| 340 | done |
| 341 | if [ -f api-light-greylist.txt ]; then |
| 342 | args+=("--light-greylist=api-light-greylist.txt") |
| 343 | fi |
| 344 | if [ -f api-dark-greylist.txt ]; then |
| 345 | args+=("--dark-greylist=api-dark-greylist.txt") |
| 346 | fi |
| 347 | if [ -f api-blacklist.txt ]; then |
| 348 | args+=("--blacklist=api-blacklist.txt") |
| 349 | fi |
| 350 | ${HIDDENAPI} "${args[@]}" |
| 351 | } |
| 352 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 353 | # Print the directory name only if it exists. |
| 354 | function maybe_dir() { |
| 355 | local dirname="$1" |
| 356 | if [[ -d "$dirname" ]]; then |
| 357 | echo "$dirname" |
| 358 | fi |
| 359 | } |
| 360 | |
Stephen Kyle | 40d3518 | 2014-10-03 13:47:56 +0100 | [diff] [blame] | 361 | if [ -e classes.dex ]; then |
| 362 | zip $TEST_NAME.jar classes.dex |
| 363 | exit 0 |
| 364 | fi |
| 365 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 366 | # Helper function for a common test. Evaluate with $(has_mutlidex). |
| 367 | function has_multidex() { |
| 368 | echo [ ${HAS_SRC_MULTIDEX} = "true" \ |
| 369 | -o ${HAS_JASMIN_MULTIDEX} = "true" \ |
| 370 | -o ${HAS_SMALI_MULTIDEX} = "true" ] |
| 371 | } |
| 372 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 373 | if [ ${HAS_SRC_DEX2OAT_UNRESOLVED} = "true" ]; then |
| 374 | mkdir classes |
| 375 | mkdir classes-ex |
| 376 | ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src-dex2oat-unresolved -d classes `find src -name '*.java'` |
| 377 | ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src -d classes-ex `find src-dex2oat-unresolved -name '*.java'` |
| 378 | if [ ${USE_JACK} = "true" ]; then |
| 379 | jar cf classes.jill.jar -C classes . |
| 380 | jar cf classes-ex.jill.jar -C classes-ex . |
| 381 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 382 | ${JACK} --import classes-ex.jill.jar --output-dex . |
| 383 | zip ${TEST_NAME}-ex.jar classes.dex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 384 | ${JACK} --import classes.jill.jar --output-dex . |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 385 | else |
| 386 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 387 | make_dex classes-ex |
Igor Murashkin | 6c946b5 | 2017-06-16 14:27:47 -0700 | [diff] [blame] | 388 | mv classes-ex.dex classes.dex # rename it so it shows up as "classes.dex" in the zip file. |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 389 | zip ${TEST_NAME}-ex.jar classes.dex |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 390 | make_dex classes |
Sebastien Hertz | 4856ca7 | 2016-03-03 18:08:17 +0100 | [diff] [blame] | 391 | fi |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 392 | fi |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 393 | else |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 394 | if [ ${USE_JACK} = "true" ]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 395 | # Jack toolchain |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 396 | if [[ "$HAS_SRC" == true || "$HAS_SRC_ART" == true ]]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 397 | if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then |
| 398 | # Compile src and src-multidex in the same .jack file. We will apply multidex partitioning |
| 399 | # when creating the output .dex file. |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 400 | ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) src-multidex $(maybe_dir src-art) |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 401 | jack_extra_args="${jack_extra_args} -D jack.dex.output.policy=minimal-multidex" |
| 402 | jack_extra_args="${jack_extra_args} -D jack.preprocessor=true" |
| 403 | jack_extra_args="${jack_extra_args} -D jack.preprocessor.file=multidex.jpp" |
| 404 | else |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 405 | ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) $(maybe_dir src-art) |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 406 | fi |
| 407 | jack_extra_args="${jack_extra_args} --import src.jack" |
| 408 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 409 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 410 | if [ "${HAS_SRC2}" = "true" ]; then |
| 411 | ${JACK} ${JACK_ARGS} --output-jack src2.jack src2 |
| 412 | # In case of duplicate classes, we want to take into account the classes from src2. Therefore |
| 413 | # we apply the 'keep-first' policy and import src2.jack file *before* the src.jack file. |
| 414 | jack_extra_args="${jack_extra_args} -D jack.import.type.policy=keep-first" |
| 415 | jack_extra_args="--import src2.jack ${jack_extra_args}" |
| 416 | fi |
| 417 | |
| 418 | # Compile jack files into a DEX file. |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 419 | if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ] || [ "${HAS_SRC_ART}" = "true" ]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 420 | ${JACK} ${JACK_ARGS} ${jack_extra_args} --output-dex . |
| 421 | fi |
| 422 | else |
| 423 | # Legacy toolchain with javac+dx |
| 424 | if [ "${HAS_SRC}" = "true" ]; then |
| 425 | mkdir classes |
| 426 | ${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'` |
| 427 | fi |
| 428 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 429 | if [ "${HAS_SRC_ART}" = "true" ]; then |
| 430 | mkdir -p classes |
| 431 | javac_with_bootclasspath ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'` |
| 432 | fi |
| 433 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 434 | if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then |
| 435 | mkdir classes2 |
Igor Murashkin | 10ba685 | 2017-06-21 11:05:23 -0700 | [diff] [blame] | 436 | ${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 437 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 438 | make_dex classes2 |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 439 | fi |
| 440 | fi |
| 441 | |
| 442 | if [ "${HAS_SRC2}" = "true" ]; then |
| 443 | mkdir -p classes |
Orion Hodson | c4d3bf4 | 2018-02-06 16:02:49 +0000 | [diff] [blame^] | 444 | ${JAVAC} ${JAVAC_ARGS} -d classes `find src2 -name '*.java'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 445 | fi |
| 446 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 447 | if [[ "${HAS_SRC}" == "true" || "${HAS_SRC2}" == "true" || "${HAS_SRC_ART}" == "true" ]]; then |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 448 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 449 | make_dex classes |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 450 | fi |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 451 | fi |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 452 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 453 | fi |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 454 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 455 | if [[ "${HAS_JASMIN}" == true ]]; then |
| 456 | # Compile Jasmin classes as if they were part of the classes.dex file. |
| 457 | make_jasmin jasmin_classes $(find 'jasmin' -name '*.j') |
| 458 | if [[ "${NEED_DEX}" == "true" ]]; then |
| 459 | # Disable desugar because it won't handle intentional linkage errors. |
| 460 | USE_DESUGAR=false make_dex jasmin_classes |
| 461 | make_dexmerge classes.dex jasmin_classes.dex |
| 462 | else |
| 463 | # Move jasmin classes into classes directory so that they are picked up with -cp classes. |
| 464 | mkdir -p classes |
| 465 | mv jasmin_classes/* classes |
| 466 | fi |
| 467 | fi |
| 468 | |
Andreas Gampe | 2b93681 | 2017-02-07 16:03:57 -0800 | [diff] [blame] | 469 | if [ "${HAS_SMALI}" = "true" -a ${NEED_DEX} = "true" ]; then |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 470 | # Compile Smali classes |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 471 | ${SMALI} -JXmx512m assemble ${SMALI_ARGS} --output smali_classes.dex `find smali -name '*.smali'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 472 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 473 | # Merge smali files into classes.dex, this takes priority over any jasmin files. |
| 474 | make_dexmerge classes.dex smali_classes.dex |
| 475 | fi |
| 476 | |
| 477 | # Compile Jasmin classes in jasmin-multidex as if they were part of the classes2.jar |
| 478 | if [[ "$HAS_JASMIN_MULTIDEX" == true ]]; then |
| 479 | make_jasmin jasmin_classes2 $(find 'jasmin-multidex' -name '*.j') |
| 480 | |
| 481 | if [[ "${NEED_DEX}" == "true" ]]; then |
| 482 | # Disable desugar because it won't handle intentional linkage errors. |
| 483 | USE_DESUGAR=false make_dex jasmin_classes2 |
| 484 | |
| 485 | # Merge jasmin_classes2.dex into classes2.dex |
| 486 | make_dexmerge classes2.dex jasmin_classes2.dex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 487 | else |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 488 | # Move jasmin classes into classes2 directory so that they are picked up with -cp classes2. |
| 489 | mkdir -p classes2 |
| 490 | mv jasmin_classes2/* classes2 |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 491 | fi |
| 492 | fi |
| 493 | |
Andreas Gampe | 2b93681 | 2017-02-07 16:03:57 -0800 | [diff] [blame] | 494 | if [ "${HAS_SMALI_MULTIDEX}" = "true" -a ${NEED_DEX} = "true" ]; then |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 495 | # Compile Smali classes |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 496 | ${SMALI} -JXmx512m assemble ${SMALI_ARGS} --output smali_classes2.dex `find smali-multidex -name '*.smali'` |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 497 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 498 | # Merge smali_classes2.dex into classes2.dex |
| 499 | make_dexmerge classes2.dex smali_classes2.dex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 500 | fi |
| 501 | |
| 502 | |
| 503 | if [ ${HAS_SRC_EX} = "true" ]; then |
| 504 | if [ ${USE_JACK} = "true" ]; then |
| 505 | # Rename previous "classes.dex" so it is not overwritten. |
| 506 | mv classes.dex classes-1.dex |
| 507 | #TODO find another way to append src.jack to the jack classpath |
| 508 | ${JACK}:src.jack ${JACK_ARGS} --output-dex . src-ex |
| 509 | zip $TEST_NAME-ex.jar classes.dex |
| 510 | # Restore previous "classes.dex" so it can be zipped. |
| 511 | mv classes-1.dex classes.dex |
| 512 | else |
Igor Murashkin | 829da13 | 2017-06-21 14:47:12 -0700 | [diff] [blame] | 513 | # Build src-ex into classes-ex. |
| 514 | # Includes 'src', 'src-art' source when compiling classes-ex, but exclude their .class files. |
| 515 | if [[ "${HAS_SRC}" == "true" ]]; then |
| 516 | mkdir -p classes-tmp-for-ex |
| 517 | ${JAVAC} ${JAVAC_ARGS} -d classes-tmp-for-ex `find src -name '*.java'` |
| 518 | src_tmp_for_ex="-cp classes-tmp-for-ex" |
| 519 | fi |
| 520 | if [[ "${HAS_SRC_ART}" == "true" ]]; then |
| 521 | mkdir -p classes-tmp-for-ex |
| 522 | javac_with_bootclasspath ${JAVAC_ARGS} -d classes-tmp-for-ex `find src-art -name '*.java'` |
| 523 | src_tmp_for_ex="-cp classes-tmp-for-ex" |
| 524 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 525 | mkdir classes-ex |
Igor Murashkin | 829da13 | 2017-06-21 14:47:12 -0700 | [diff] [blame] | 526 | ${JAVAC} ${JAVAC_ARGS} -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'` |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 527 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 528 | make_dex classes-ex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 529 | |
| 530 | # quick shuffle so that the stored name is "classes.dex" |
| 531 | mv classes.dex classes-1.dex |
| 532 | mv classes-ex.dex classes.dex |
| 533 | zip $TEST_NAME-ex.jar classes.dex |
| 534 | mv classes.dex classes-ex.dex |
| 535 | mv classes-1.dex classes.dex |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 536 | fi |
| 537 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 538 | fi |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 539 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 540 | # Apply hiddenapi on the dex files if the test has API list file(s). |
| 541 | if [ ${NEED_DEX} = "true" -a ${USE_HIDDENAPI} = "true" -a ${HAS_HIDDENAPI_SPEC} = "true" ]; then |
| 542 | if $(has_multidex); then |
| 543 | make_hiddenapi classes.dex classes2.dex |
| 544 | else |
| 545 | make_hiddenapi classes.dex |
| 546 | fi |
| 547 | fi |
| 548 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 549 | # Create a single dex jar with two dex files for multidex. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 550 | if [ ${NEED_DEX} = "true" ]; then |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 551 | if $(has_multidex); then |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 552 | zip $TEST_NAME.jar classes.dex classes2.dex |
| 553 | else |
| 554 | zip $TEST_NAME.jar classes.dex |
| 555 | fi |
Nicolas Geoffray | 1250861 | 2014-11-05 12:34:24 +0000 | [diff] [blame] | 556 | fi |