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 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 20 | if [[ $# -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 |
| 24 | fi |
| 25 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 26 | # Set default values for directories. |
| 27 | if [ -d smali ]; then |
| 28 | HAS_SMALI=true |
| 29 | else |
| 30 | HAS_SMALI=false |
| 31 | fi |
| 32 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 33 | # .j files in jasmin get compiled into classes.jar |
| 34 | if [ -d jasmin ]; then |
| 35 | HAS_JASMIN=true |
| 36 | else |
| 37 | HAS_JASMIN=false |
| 38 | fi |
| 39 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 40 | if [ -d src ]; then |
| 41 | HAS_SRC=true |
| 42 | else |
| 43 | HAS_SRC=false |
| 44 | fi |
| 45 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 46 | # .java files in src-art get compiled with libcore on the bootclasspath |
| 47 | if [ -d src-art ]; then |
| 48 | HAS_SRC_ART=true |
| 49 | else |
| 50 | HAS_SRC_ART=false |
| 51 | fi |
| 52 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 53 | if [ -d src2 ]; then |
| 54 | HAS_SRC2=true |
| 55 | else |
| 56 | HAS_SRC2=false |
| 57 | fi |
| 58 | |
| 59 | if [ -d src-multidex ]; then |
| 60 | HAS_SRC_MULTIDEX=true |
| 61 | else |
| 62 | HAS_SRC_MULTIDEX=false |
| 63 | fi |
| 64 | |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 65 | if [ -d smali-multidex ]; then |
| 66 | HAS_SMALI_MULTIDEX=true |
| 67 | else |
| 68 | HAS_SMALI_MULTIDEX=false |
| 69 | fi |
| 70 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 71 | # .j files in jasmin-multidex get compiled into classes2.jar |
| 72 | if [ -d jasmin-multidex ]; then |
| 73 | HAS_JASMIN_MULTIDEX=true |
| 74 | else |
| 75 | HAS_JASMIN_MULTIDEX=false |
| 76 | fi |
| 77 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 78 | if [ -d src-ex ]; then |
| 79 | HAS_SRC_EX=true |
| 80 | else |
| 81 | HAS_SRC_EX=false |
| 82 | fi |
| 83 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 84 | if [ -d src-dex2oat-unresolved ]; then |
| 85 | HAS_SRC_DEX2OAT_UNRESOLVED=true |
| 86 | else |
| 87 | HAS_SRC_DEX2OAT_UNRESOLVED=false |
| 88 | fi |
| 89 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 90 | if [ -f api-light-greylist.txt -o -f api-dark-greylist.txt -o -f api-blacklist.txt ]; then |
| 91 | HAS_HIDDENAPI_SPEC=true |
| 92 | else |
| 93 | HAS_HIDDENAPI_SPEC=false |
| 94 | fi |
| 95 | |
| 96 | # USE_HIDDENAPI=false run-test... will disable hiddenapi. |
| 97 | if [ -z "${USE_HIDDENAPI}" ]; then |
| 98 | USE_HIDDENAPI=true |
| 99 | fi |
| 100 | |
Igor Murashkin | e518193 | 2017-06-15 16:03:50 -0700 | [diff] [blame] | 101 | # DESUGAR=false run-test... will disable desugar. |
| 102 | if [[ "$DESUGAR" == false ]]; then |
| 103 | USE_DESUGAR=false |
| 104 | fi |
| 105 | |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 106 | # Allow overriding ZIP_COMPRESSION_METHOD with e.g. 'store' |
| 107 | ZIP_COMPRESSION_METHOD="deflate" |
| 108 | # Align every ZIP file made by calling $ZIPALIGN command? |
| 109 | WITH_ZIP_ALIGN=false |
| 110 | ZIP_ALIGN_BYTES="-1" |
| 111 | |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 112 | DX_FLAGS="--min-sdk-version=24" |
| 113 | DX_VM_FLAGS="" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 114 | EXPERIMENTAL="" |
| 115 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 116 | BUILD_MODE="target" |
| 117 | DEV_MODE="no" |
| 118 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 119 | # The key for default arguments if no experimental things are enabled. |
| 120 | DEFAULT_EXPERIMENT="no-experiment" |
| 121 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 122 | # Setup experimental flag mappings in a bash associative array. |
| 123 | declare -A JACK_EXPERIMENTAL_ARGS |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 124 | 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] | 125 | JACK_EXPERIMENTAL_ARGS["default-methods"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24" |
| 126 | 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] | 127 | 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] | 128 | 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] | 129 | |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 130 | declare -A SMALI_EXPERIMENTAL_ARGS |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 131 | SMALI_EXPERIMENTAL_ARGS["default-methods"]="--api 24" |
| 132 | SMALI_EXPERIMENTAL_ARGS["method-handles"]="--api 26" |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 133 | SMALI_EXPERIMENTAL_ARGS["var-handles"]="--api 26" |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 134 | SMALI_EXPERIMENTAL_ARGS["agents"]="--api 26" |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 135 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 136 | declare -A JAVAC_EXPERIMENTAL_ARGS |
| 137 | JAVAC_EXPERIMENTAL_ARGS["default-methods"]="-source 1.8 -target 1.8" |
| 138 | JAVAC_EXPERIMENTAL_ARGS["lambdas"]="-source 1.8 -target 1.8" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 139 | JAVAC_EXPERIMENTAL_ARGS["method-handles"]="-source 1.8 -target 1.8" |
Orion Hodson | 58143d2 | 2018-02-20 08:44:20 +0000 | [diff] [blame] | 140 | JAVAC_EXPERIMENTAL_ARGS["parameter-annotations"]="-source 1.8 -target 1.8" |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 141 | JAVAC_EXPERIMENTAL_ARGS["var-handles"]="-source 1.8 -target 1.8" |
Alex Light | 4eec3c5 | 2017-04-14 13:17:26 -0700 | [diff] [blame] | 142 | JAVAC_EXPERIMENTAL_ARGS[${DEFAULT_EXPERIMENT}]="-source 1.8 -target 1.8" |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 143 | JAVAC_EXPERIMENTAL_ARGS["agents"]="-source 1.8 -target 1.8" |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 144 | |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 145 | declare -A DX_EXPERIMENTAL_ARGS |
| 146 | DX_EXPERIMENTAL_ARGS["method-handles"]="--min-sdk-version=26" |
Orion Hodson | 58143d2 | 2018-02-20 08:44:20 +0000 | [diff] [blame] | 147 | DX_EXPERIMENTAL_ARGS["parameter-annotations"]="--min-sdk-version=25" |
Alan Leung | 276d29b | 2018-04-05 11:37:40 -0700 | [diff] [blame] | 148 | DX_EXPERIMENTAL_ARGS["var-handles"]="--min-sdk-version=28" |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 149 | |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 150 | while true; do |
| 151 | if [ "x$1" = "x--dx-option" ]; then |
| 152 | shift |
Orion Hodson | e1fb77f | 2017-02-27 13:57:18 +0000 | [diff] [blame] | 153 | option="$1" |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 154 | DX_FLAGS="${DX_FLAGS} $option" |
| 155 | shift |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 156 | elif [ "x$1" = "x--dx-vm-option" ]; then |
| 157 | shift |
| 158 | option="$1" |
| 159 | DX_VM_FLAGS="${DX_VM_FLAGS} $option" |
| 160 | shift |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 161 | 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 Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 170 | elif [ "x$1" = "x--no-smali-multidex" ]; then |
| 171 | HAS_SMALI_MULTIDEX=false |
| 172 | shift |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 173 | 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 Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 181 | # We have a specific experimental configuration so don't use the default. |
| 182 | DEFAULT_EXPERIMENT="" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 183 | EXPERIMENTAL="${EXPERIMENTAL} $1" |
| 184 | shift |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 185 | 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 Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 196 | 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 Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 202 | elif [ "x$1" = "x--jvm" ]; then |
| 203 | BUILD_MODE="jvm" |
| 204 | shift |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 205 | elif [ "x$1" = "x--dev" ]; then |
| 206 | DEV_MODE="yes" |
| 207 | shift |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 208 | 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 |
| 214 | done |
| 215 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 216 | if [[ $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 |
| 221 | fi |
| 222 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 223 | # Be sure to get any default arguments if not doing any experiments. |
| 224 | EXPERIMENTAL="${EXPERIMENTAL} ${DEFAULT_EXPERIMENT}" |
| 225 | |
Sebastien Hertz | 361ad55 | 2017-01-04 16:07:57 +0100 | [diff] [blame] | 226 | if [ "${JACK_SERVER}" = "false" ]; then |
| 227 | # Run in single-threaded mode for the continuous buildbot. |
| 228 | JACK_ARGS="${JACK_ARGS} -D sched.runner=single-threaded" |
| 229 | else |
| 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" |
| 234 | fi |
| 235 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 236 | # Add args from the experimental mappings. |
| 237 | for experiment in ${EXPERIMENTAL}; do |
| 238 | JACK_ARGS="${JACK_ARGS} ${JACK_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 239 | SMALI_ARGS="${SMALI_ARGS} ${SMALI_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 240 | JAVAC_ARGS="${JAVAC_ARGS} ${JAVAC_EXPERIMENTAL_ARGS[${experiment}]}" |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 241 | DX_FLAGS="${DX_FLAGS} ${DX_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 242 | done |
| 243 | |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 244 | ######################################### |
| 245 | |
| 246 | # Catch all commands to 'ZIP' and prepend extra flags. |
| 247 | # Optionally, zipalign results to some alignment. |
| 248 | function 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 Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 264 | function 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 Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 279 | function desugar() { |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 280 | local desugar_args="--mode=$BUILD_MODE" |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 281 | |
| 282 | if [[ $DEV_MODE == yes ]]; then |
| 283 | desugar_args="$desugar_args --show-commands" |
| 284 | fi |
| 285 | |
Igor Murashkin | e518193 | 2017-06-15 16:03:50 -0700 | [diff] [blame] | 286 | "$DESUGAR" --core-only $desugar_args "$@" |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 289 | # Like regular javac but may include libcore on the bootclasspath. |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 290 | function javac_with_bootclasspath { |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 291 | local helper_args="--mode=$BUILD_MODE" |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 292 | |
| 293 | if [[ $DEV_MODE == yes ]]; then |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 294 | helper_args="$helper_args --show-commands" |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 295 | fi |
| 296 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 297 | # 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 Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 301 | # Make a "dex" file given a directory of classes in $1. |
| 302 | # Also calls desugar on the classes first to convert lambdas. |
| 303 | function 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 Leung | 0afa07a | 2017-10-03 16:56:30 -0700 | [diff] [blame] | 319 | local dexer="${DX}" |
Alan Leung | cf2de16 | 2018-03-30 20:18:20 +0000 | [diff] [blame] | 320 | if [[ "${USE_D8}" != "false" ]]; then |
Alan Leung | a4ba9b5 | 2017-11-16 00:19:18 -0800 | [diff] [blame] | 321 | dexer="${ANDROID_HOST_OUT}/bin/d8-compat-dx" |
Alan Leung | 0afa07a | 2017-10-03 16:56:30 -0700 | [diff] [blame] | 322 | fi |
| 323 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 324 | # Make dex file from desugared JAR. |
Alan Leung | 0afa07a | 2017-10-03 16:56:30 -0700 | [diff] [blame] | 325 | ${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] | 326 | } |
| 327 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 328 | # Merge all the dex files in $1..$N into $1. Skip non-existing files, but at least 1 file must exist. |
| 329 | function 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 | |
Alan Leung | d5cbc56 | 2018-03-15 14:02:46 -0700 | [diff] [blame] | 344 | # Skip merge if we are not merging anything. IE: input = output. |
| 345 | if [[ "${#dex_files_to_merge[@]}" -eq "1" ]]; then |
| 346 | local single_input=${dex_files_to_merge[0]} |
| 347 | if [[ "$dst_file" != "$single_input" ]]; then |
| 348 | mv "$single_input" "$dst_file"; |
| 349 | return |
| 350 | fi |
| 351 | fi |
| 352 | |
| 353 | # We assume the dexer did all the API level checks and just merge away. |
| 354 | mkdir d8_merge_out |
| 355 | ${DXMERGER} --min-api 1000 --output ./d8_merge_out "${dex_files_to_merge[@]}" |
| 356 | |
| 357 | if [[ -e "./d8_merge_out/classes2.dex" ]]; then |
| 358 | echo "Cannot merge all dex files into a single dex" |
| 359 | exit 1 |
| 360 | fi |
| 361 | |
| 362 | mv ./d8_merge_out/classes.dex "$dst_file"; |
| 363 | rmdir d8_merge_out |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 364 | } |
| 365 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 366 | function make_hiddenapi() { |
| 367 | local args=() |
| 368 | while [[ $# -gt 0 ]]; do |
| 369 | args+=("--dex=$1") |
| 370 | shift |
| 371 | done |
| 372 | if [ -f api-light-greylist.txt ]; then |
| 373 | args+=("--light-greylist=api-light-greylist.txt") |
| 374 | fi |
| 375 | if [ -f api-dark-greylist.txt ]; then |
| 376 | args+=("--dark-greylist=api-dark-greylist.txt") |
| 377 | fi |
| 378 | if [ -f api-blacklist.txt ]; then |
| 379 | args+=("--blacklist=api-blacklist.txt") |
| 380 | fi |
| 381 | ${HIDDENAPI} "${args[@]}" |
| 382 | } |
| 383 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 384 | # Print the directory name only if it exists. |
| 385 | function maybe_dir() { |
| 386 | local dirname="$1" |
| 387 | if [[ -d "$dirname" ]]; then |
| 388 | echo "$dirname" |
| 389 | fi |
| 390 | } |
| 391 | |
Stephen Kyle | 40d3518 | 2014-10-03 13:47:56 +0100 | [diff] [blame] | 392 | if [ -e classes.dex ]; then |
| 393 | zip $TEST_NAME.jar classes.dex |
| 394 | exit 0 |
| 395 | fi |
| 396 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 397 | # Helper function for a common test. Evaluate with $(has_mutlidex). |
| 398 | function has_multidex() { |
| 399 | echo [ ${HAS_SRC_MULTIDEX} = "true" \ |
| 400 | -o ${HAS_JASMIN_MULTIDEX} = "true" \ |
| 401 | -o ${HAS_SMALI_MULTIDEX} = "true" ] |
| 402 | } |
| 403 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 404 | if [ ${HAS_SRC_DEX2OAT_UNRESOLVED} = "true" ]; then |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 405 | mkdir -p classes |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 406 | mkdir classes-ex |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 407 | javac_with_bootclasspath -implicit:none -sourcepath src-dex2oat-unresolved -d classes `find src -name '*.java'` |
| 408 | javac_with_bootclasspath -implicit:none -sourcepath src -d classes-ex `find src-dex2oat-unresolved -name '*.java'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 409 | if [ ${USE_JACK} = "true" ]; then |
| 410 | jar cf classes.jill.jar -C classes . |
| 411 | jar cf classes-ex.jill.jar -C classes-ex . |
| 412 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 413 | ${JACK} --import classes-ex.jill.jar --output-dex . |
| 414 | zip ${TEST_NAME}-ex.jar classes.dex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 415 | ${JACK} --import classes.jill.jar --output-dex . |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 416 | else |
| 417 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 418 | make_dex classes-ex |
Igor Murashkin | 6c946b5 | 2017-06-16 14:27:47 -0700 | [diff] [blame] | 419 | 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] | 420 | zip ${TEST_NAME}-ex.jar classes.dex |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 421 | make_dex classes |
Sebastien Hertz | 4856ca7 | 2016-03-03 18:08:17 +0100 | [diff] [blame] | 422 | fi |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 423 | fi |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 424 | else |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 425 | if [ ${USE_JACK} = "true" ]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 426 | # Jack toolchain |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 427 | if [[ "$HAS_SRC" == true || "$HAS_SRC_ART" == true ]]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 428 | if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then |
| 429 | # Compile src and src-multidex in the same .jack file. We will apply multidex partitioning |
| 430 | # when creating the output .dex file. |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 431 | ${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] | 432 | jack_extra_args="${jack_extra_args} -D jack.dex.output.policy=minimal-multidex" |
| 433 | jack_extra_args="${jack_extra_args} -D jack.preprocessor=true" |
| 434 | jack_extra_args="${jack_extra_args} -D jack.preprocessor.file=multidex.jpp" |
| 435 | else |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 436 | ${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] | 437 | fi |
| 438 | jack_extra_args="${jack_extra_args} --import src.jack" |
| 439 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 440 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 441 | if [ "${HAS_SRC2}" = "true" ]; then |
| 442 | ${JACK} ${JACK_ARGS} --output-jack src2.jack src2 |
| 443 | # In case of duplicate classes, we want to take into account the classes from src2. Therefore |
| 444 | # we apply the 'keep-first' policy and import src2.jack file *before* the src.jack file. |
| 445 | jack_extra_args="${jack_extra_args} -D jack.import.type.policy=keep-first" |
| 446 | jack_extra_args="--import src2.jack ${jack_extra_args}" |
| 447 | fi |
| 448 | |
| 449 | # Compile jack files into a DEX file. |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 450 | if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ] || [ "${HAS_SRC_ART}" = "true" ]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 451 | ${JACK} ${JACK_ARGS} ${jack_extra_args} --output-dex . |
| 452 | fi |
| 453 | else |
| 454 | # Legacy toolchain with javac+dx |
| 455 | if [ "${HAS_SRC}" = "true" ]; then |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 456 | mkdir -p classes |
| 457 | javac_with_bootclasspath -implicit:none -classpath src-multidex -d classes `find src -name '*.java'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 458 | fi |
| 459 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 460 | if [ "${HAS_SRC_ART}" = "true" ]; then |
| 461 | mkdir -p classes |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 462 | javac_with_bootclasspath -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'` |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 463 | fi |
| 464 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 465 | if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then |
| 466 | mkdir classes2 |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 467 | javac_with_bootclasspath -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 468 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 469 | make_dex classes2 |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 470 | fi |
| 471 | fi |
| 472 | |
| 473 | if [ "${HAS_SRC2}" = "true" ]; then |
| 474 | mkdir -p classes |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 475 | javac_with_bootclasspath -classpath classes -d classes `find src2 -name '*.java'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 476 | fi |
| 477 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 478 | if [[ "${HAS_SRC}" == "true" || "${HAS_SRC2}" == "true" || "${HAS_SRC_ART}" == "true" ]]; then |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 479 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 480 | make_dex classes |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 481 | fi |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 482 | fi |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 483 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 484 | fi |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 485 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 486 | if [[ "${HAS_JASMIN}" == true ]]; then |
| 487 | # Compile Jasmin classes as if they were part of the classes.dex file. |
| 488 | make_jasmin jasmin_classes $(find 'jasmin' -name '*.j') |
| 489 | if [[ "${NEED_DEX}" == "true" ]]; then |
| 490 | # Disable desugar because it won't handle intentional linkage errors. |
| 491 | USE_DESUGAR=false make_dex jasmin_classes |
| 492 | make_dexmerge classes.dex jasmin_classes.dex |
| 493 | else |
| 494 | # Move jasmin classes into classes directory so that they are picked up with -cp classes. |
| 495 | mkdir -p classes |
| 496 | mv jasmin_classes/* classes |
| 497 | fi |
| 498 | fi |
| 499 | |
Andreas Gampe | 2b93681 | 2017-02-07 16:03:57 -0800 | [diff] [blame] | 500 | if [ "${HAS_SMALI}" = "true" -a ${NEED_DEX} = "true" ]; then |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 501 | # Compile Smali classes |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 502 | ${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] | 503 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 504 | # Merge smali files into classes.dex, this takes priority over any jasmin files. |
| 505 | make_dexmerge classes.dex smali_classes.dex |
| 506 | fi |
| 507 | |
| 508 | # Compile Jasmin classes in jasmin-multidex as if they were part of the classes2.jar |
| 509 | if [[ "$HAS_JASMIN_MULTIDEX" == true ]]; then |
| 510 | make_jasmin jasmin_classes2 $(find 'jasmin-multidex' -name '*.j') |
| 511 | |
| 512 | if [[ "${NEED_DEX}" == "true" ]]; then |
| 513 | # Disable desugar because it won't handle intentional linkage errors. |
| 514 | USE_DESUGAR=false make_dex jasmin_classes2 |
| 515 | |
| 516 | # Merge jasmin_classes2.dex into classes2.dex |
| 517 | make_dexmerge classes2.dex jasmin_classes2.dex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 518 | else |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 519 | # Move jasmin classes into classes2 directory so that they are picked up with -cp classes2. |
| 520 | mkdir -p classes2 |
| 521 | mv jasmin_classes2/* classes2 |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 522 | fi |
| 523 | fi |
| 524 | |
Andreas Gampe | 2b93681 | 2017-02-07 16:03:57 -0800 | [diff] [blame] | 525 | if [ "${HAS_SMALI_MULTIDEX}" = "true" -a ${NEED_DEX} = "true" ]; then |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 526 | # Compile Smali classes |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 527 | ${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] | 528 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 529 | # Merge smali_classes2.dex into classes2.dex |
| 530 | make_dexmerge classes2.dex smali_classes2.dex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 531 | fi |
| 532 | |
| 533 | |
| 534 | if [ ${HAS_SRC_EX} = "true" ]; then |
| 535 | if [ ${USE_JACK} = "true" ]; then |
| 536 | # Rename previous "classes.dex" so it is not overwritten. |
| 537 | mv classes.dex classes-1.dex |
| 538 | #TODO find another way to append src.jack to the jack classpath |
| 539 | ${JACK}:src.jack ${JACK_ARGS} --output-dex . src-ex |
| 540 | zip $TEST_NAME-ex.jar classes.dex |
| 541 | # Restore previous "classes.dex" so it can be zipped. |
| 542 | mv classes-1.dex classes.dex |
| 543 | else |
Igor Murashkin | 829da13 | 2017-06-21 14:47:12 -0700 | [diff] [blame] | 544 | # Build src-ex into classes-ex. |
| 545 | # Includes 'src', 'src-art' source when compiling classes-ex, but exclude their .class files. |
| 546 | if [[ "${HAS_SRC}" == "true" ]]; then |
| 547 | mkdir -p classes-tmp-for-ex |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 548 | javac_with_bootclasspath -d classes-tmp-for-ex `find src -name '*.java'` |
Igor Murashkin | 829da13 | 2017-06-21 14:47:12 -0700 | [diff] [blame] | 549 | src_tmp_for_ex="-cp classes-tmp-for-ex" |
| 550 | fi |
| 551 | if [[ "${HAS_SRC_ART}" == "true" ]]; then |
| 552 | mkdir -p classes-tmp-for-ex |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 553 | javac_with_bootclasspath -d classes-tmp-for-ex `find src-art -name '*.java'` |
Igor Murashkin | 829da13 | 2017-06-21 14:47:12 -0700 | [diff] [blame] | 554 | src_tmp_for_ex="-cp classes-tmp-for-ex" |
| 555 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 556 | mkdir classes-ex |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 557 | javac_with_bootclasspath -d classes-ex $src_tmp_for_ex `find src-ex -name '*.java'` |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 558 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 559 | fi |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 560 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 561 | if [[ -d classes-ex ]] && [ ${NEED_DEX} = "true" ]; then |
| 562 | make_dex classes-ex |
| 563 | |
David Brazdil | 904e75a | 2018-05-15 13:45:08 +0100 | [diff] [blame^] | 564 | # Apply hiddenapi on the dex files if the test has API list file(s). |
| 565 | if [ ${USE_HIDDENAPI} = "true" -a ${HAS_HIDDENAPI_SPEC} = "true" ]; then |
| 566 | make_hiddenapi classes-ex.dex |
| 567 | fi |
| 568 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 569 | # quick shuffle so that the stored name is "classes.dex" |
| 570 | mv classes.dex classes-1.dex |
| 571 | mv classes-ex.dex classes.dex |
| 572 | zip $TEST_NAME-ex.jar classes.dex |
| 573 | mv classes.dex classes-ex.dex |
| 574 | mv classes-1.dex classes.dex |
| 575 | fi |
| 576 | |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 577 | # Apply hiddenapi on the dex files if the test has API list file(s). |
| 578 | if [ ${NEED_DEX} = "true" -a ${USE_HIDDENAPI} = "true" -a ${HAS_HIDDENAPI_SPEC} = "true" ]; then |
| 579 | if $(has_multidex); then |
| 580 | make_hiddenapi classes.dex classes2.dex |
| 581 | else |
| 582 | make_hiddenapi classes.dex |
| 583 | fi |
| 584 | fi |
| 585 | |
Igor Murashkin | 4014d84 | 2017-07-11 11:58:44 -0700 | [diff] [blame] | 586 | # Create a single dex jar with two dex files for multidex. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 587 | if [ ${NEED_DEX} = "true" ]; then |
David Brazdil | 11b67b2 | 2018-01-18 16:41:40 +0000 | [diff] [blame] | 588 | if $(has_multidex); then |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 589 | zip $TEST_NAME.jar classes.dex classes2.dex |
| 590 | else |
| 591 | zip $TEST_NAME.jar classes.dex |
| 592 | fi |
Nicolas Geoffray | 1250861 | 2014-11-05 12:34:24 +0000 | [diff] [blame] | 593 | fi |