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 | |
| 27 | if [ -d src ]; then |
| 28 | HAS_SRC=true |
| 29 | else |
| 30 | HAS_SRC=false |
| 31 | fi |
| 32 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 33 | # .java files in src-art get compiled with libcore on the bootclasspath |
| 34 | if [ -d src-art ]; then |
| 35 | HAS_SRC_ART=true |
| 36 | else |
| 37 | HAS_SRC_ART=false |
| 38 | fi |
| 39 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 40 | if [ -d src2 ]; then |
| 41 | HAS_SRC2=true |
| 42 | else |
| 43 | HAS_SRC2=false |
| 44 | fi |
| 45 | |
| 46 | if [ -d src-multidex ]; then |
| 47 | HAS_SRC_MULTIDEX=true |
| 48 | else |
| 49 | HAS_SRC_MULTIDEX=false |
| 50 | fi |
| 51 | |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 52 | if [ -d smali-multidex ]; then |
| 53 | HAS_SMALI_MULTIDEX=true |
| 54 | else |
| 55 | HAS_SMALI_MULTIDEX=false |
| 56 | fi |
| 57 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 58 | if [ -d src-ex ]; then |
| 59 | HAS_SRC_EX=true |
| 60 | else |
| 61 | HAS_SRC_EX=false |
| 62 | fi |
| 63 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 64 | if [ -d src-dex2oat-unresolved ]; then |
| 65 | HAS_SRC_DEX2OAT_UNRESOLVED=true |
| 66 | else |
| 67 | HAS_SRC_DEX2OAT_UNRESOLVED=false |
| 68 | fi |
| 69 | |
Igor Murashkin | e518193 | 2017-06-15 16:03:50 -0700 | [diff] [blame] | 70 | # DESUGAR=false run-test... will disable desugar. |
| 71 | if [[ "$DESUGAR" == false ]]; then |
| 72 | USE_DESUGAR=false |
| 73 | fi |
| 74 | |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 75 | # Allow overriding ZIP_COMPRESSION_METHOD with e.g. 'store' |
| 76 | ZIP_COMPRESSION_METHOD="deflate" |
| 77 | # Align every ZIP file made by calling $ZIPALIGN command? |
| 78 | WITH_ZIP_ALIGN=false |
| 79 | ZIP_ALIGN_BYTES="-1" |
| 80 | |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 81 | DX_FLAGS="--min-sdk-version=24" |
| 82 | DX_VM_FLAGS="" |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 83 | SKIP_DX_MERGER="false" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 84 | EXPERIMENTAL="" |
| 85 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 86 | BUILD_MODE="target" |
| 87 | DEV_MODE="no" |
| 88 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 89 | # The key for default arguments if no experimental things are enabled. |
| 90 | DEFAULT_EXPERIMENT="no-experiment" |
| 91 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 92 | # Setup experimental flag mappings in a bash associative array. |
| 93 | declare -A JACK_EXPERIMENTAL_ARGS |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 94 | 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] | 95 | JACK_EXPERIMENTAL_ARGS["default-methods"]="-D jack.java.source.version=1.8 -D jack.android.min-api-level=24" |
| 96 | 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] | 97 | 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] | 98 | 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] | 99 | |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 100 | declare -A SMALI_EXPERIMENTAL_ARGS |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 101 | SMALI_EXPERIMENTAL_ARGS["default-methods"]="--api 24" |
| 102 | SMALI_EXPERIMENTAL_ARGS["method-handles"]="--api 26" |
| 103 | SMALI_EXPERIMENTAL_ARGS["agents"]="--api 26" |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 104 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 105 | declare -A JAVAC_EXPERIMENTAL_ARGS |
| 106 | JAVAC_EXPERIMENTAL_ARGS["default-methods"]="-source 1.8 -target 1.8" |
| 107 | JAVAC_EXPERIMENTAL_ARGS["lambdas"]="-source 1.8 -target 1.8" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 108 | JAVAC_EXPERIMENTAL_ARGS["method-handles"]="-source 1.8 -target 1.8" |
Alex Light | e4893ee | 2017-02-09 15:28:53 -0800 | [diff] [blame] | 109 | # 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] | 110 | JAVAC_EXPERIMENTAL_ARGS[${DEFAULT_EXPERIMENT}]="-source 1.8 -target 1.8" |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 111 | JAVAC_EXPERIMENTAL_ARGS["agents"]="-source 1.8 -target 1.8" |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 112 | |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 113 | declare -A DX_EXPERIMENTAL_ARGS |
| 114 | DX_EXPERIMENTAL_ARGS["method-handles"]="--min-sdk-version=26" |
| 115 | |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 116 | while true; do |
| 117 | if [ "x$1" = "x--dx-option" ]; then |
| 118 | shift |
Orion Hodson | e1fb77f | 2017-02-27 13:57:18 +0000 | [diff] [blame] | 119 | option="$1" |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 120 | DX_FLAGS="${DX_FLAGS} $option" |
| 121 | shift |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 122 | elif [ "x$1" = "x--dx-vm-option" ]; then |
| 123 | shift |
| 124 | option="$1" |
| 125 | DX_VM_FLAGS="${DX_VM_FLAGS} $option" |
| 126 | shift |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 127 | elif [ "x$1" = "x--jvm" ]; then |
| 128 | shift |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 129 | elif [ "x$1" = "x--no-src" ]; then |
| 130 | HAS_SRC=false |
| 131 | shift |
| 132 | elif [ "x$1" = "x--no-src2" ]; then |
| 133 | HAS_SRC2=false |
| 134 | shift |
| 135 | elif [ "x$1" = "x--no-src-multidex" ]; then |
| 136 | HAS_SRC_MULTIDEX=false |
| 137 | shift |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 138 | elif [ "x$1" = "x--no-smali-multidex" ]; then |
| 139 | HAS_SMALI_MULTIDEX=false |
| 140 | shift |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 141 | elif [ "x$1" = "x--no-src-ex" ]; then |
| 142 | HAS_SRC_EX=false |
| 143 | shift |
| 144 | elif [ "x$1" = "x--no-smali" ]; then |
| 145 | HAS_SMALI=false |
| 146 | shift |
| 147 | elif [ "x$1" = "x--experimental" ]; then |
| 148 | shift |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 149 | # We have a specific experimental configuration so don't use the default. |
| 150 | DEFAULT_EXPERIMENT="" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 151 | EXPERIMENTAL="${EXPERIMENTAL} $1" |
| 152 | shift |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 153 | elif [ "x$1" = "x--zip-compression-method" ]; then |
| 154 | # Allow using different zip compression method, e.g. 'store' |
| 155 | shift |
| 156 | ZIP_COMPRESSION_METHOD="$1" |
| 157 | shift |
| 158 | elif [ "x$1" = "x--zip-align" ]; then |
| 159 | # Align ZIP entries to some # of bytes. |
| 160 | shift |
| 161 | WITH_ZIP_ALIGN=true |
| 162 | ZIP_ALIGN_BYTES="$1" |
| 163 | shift |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 164 | elif [ "x$1" = "x--host" ]; then |
| 165 | BUILD_MODE="host" |
| 166 | shift |
| 167 | elif [ "x$1" = "x--target" ]; then |
| 168 | BUILD_MODE="target" |
| 169 | shift |
| 170 | elif [ "x$1" = "x--dev" ]; then |
| 171 | DEV_MODE="yes" |
| 172 | shift |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 173 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
| 174 | echo "unknown $0 option: $1" 1>&2 |
| 175 | exit 1 |
| 176 | else |
| 177 | break |
| 178 | fi |
| 179 | done |
| 180 | |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 181 | # Be sure to get any default arguments if not doing any experiments. |
| 182 | EXPERIMENTAL="${EXPERIMENTAL} ${DEFAULT_EXPERIMENT}" |
| 183 | |
Sebastien Hertz | 361ad55 | 2017-01-04 16:07:57 +0100 | [diff] [blame] | 184 | if [ "${JACK_SERVER}" = "false" ]; then |
| 185 | # Run in single-threaded mode for the continuous buildbot. |
| 186 | JACK_ARGS="${JACK_ARGS} -D sched.runner=single-threaded" |
| 187 | else |
| 188 | # Run with 4 threads to reduce memory footprint and thread contention. |
| 189 | JACK_ARGS="${JACK_ARGS} -D sched.runner=multi-threaded" |
| 190 | JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.kind=fixed" |
| 191 | JACK_ARGS="${JACK_ARGS} -D sched.runner.thread.fixed.count=4" |
| 192 | fi |
| 193 | |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 194 | # Add args from the experimental mappings. |
| 195 | for experiment in ${EXPERIMENTAL}; do |
| 196 | JACK_ARGS="${JACK_ARGS} ${JACK_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | b55f1ac | 2016-04-12 15:50:55 -0700 | [diff] [blame] | 197 | SMALI_ARGS="${SMALI_ARGS} ${SMALI_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | ea1e770 | 2016-07-11 13:39:55 -0700 | [diff] [blame] | 198 | JAVAC_ARGS="${JAVAC_ARGS} ${JAVAC_EXPERIMENTAL_ARGS[${experiment}]}" |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 199 | DX_FLAGS="${DX_FLAGS} ${DX_EXPERIMENTAL_ARGS[${experiment}]}" |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 200 | done |
| 201 | |
Igor Murashkin | 271a0f8 | 2017-02-14 21:14:17 +0000 | [diff] [blame] | 202 | ######################################### |
| 203 | |
| 204 | # Catch all commands to 'ZIP' and prepend extra flags. |
| 205 | # Optionally, zipalign results to some alignment. |
| 206 | function zip() { |
| 207 | local zip_target="$1" |
| 208 | local entry_src="$2" |
| 209 | shift 2 |
| 210 | |
| 211 | command zip --compression-method "$ZIP_COMPRESSION_METHOD" "$zip_target" "$entry_src" "$@" |
| 212 | |
| 213 | if "$WITH_ZIP_ALIGN"; then |
| 214 | # zipalign does not operate in-place, so write results to a temp file. |
| 215 | local tmp_file="$(mktemp)" |
| 216 | "$ZIPALIGN" -f "$ZIP_ALIGN_BYTES" "$zip_target" "$tmp_file" |
| 217 | # replace original zip target with our temp file. |
| 218 | mv "$tmp_file" "$zip_target" |
| 219 | fi |
| 220 | } |
| 221 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 222 | function desugar() { |
| 223 | local desugar_args=--mode=host |
| 224 | if [[ $BUILD_MODE == target ]]; then |
| 225 | desugar_args=--mode=target |
| 226 | fi |
| 227 | |
| 228 | if [[ $DEV_MODE == yes ]]; then |
| 229 | desugar_args="$desugar_args --show-commands" |
| 230 | fi |
| 231 | |
Igor Murashkin | e518193 | 2017-06-15 16:03:50 -0700 | [diff] [blame] | 232 | "$DESUGAR" --core-only $desugar_args "$@" |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 235 | # Like regular javac but includes libcore on the bootclasspath. |
| 236 | function javac_with_bootclasspath { |
| 237 | local javac_args=--mode=host |
| 238 | if [[ $BUILD_MODE == target ]]; then |
| 239 | javac_args=--mode=target |
| 240 | fi |
| 241 | |
| 242 | if [[ $DEV_MODE == yes ]]; then |
| 243 | javac_args="$javac_args --show-commands" |
| 244 | fi |
| 245 | |
| 246 | "$ANDROID_BUILD_TOP/art/tools/javac-helper.sh" --core-only $javac_args "$@" |
| 247 | } |
| 248 | |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 249 | # Make a "dex" file given a directory of classes in $1. |
| 250 | # Also calls desugar on the classes first to convert lambdas. |
| 251 | function make_dex() { |
| 252 | local name="$1" |
| 253 | |
| 254 | local dx_input |
| 255 | if [[ "$USE_DESUGAR" == "true" ]]; then |
| 256 | # Make a jar first so desugar doesn't need every .class file individually. |
| 257 | jar cf "$name.before-desugar.jar" -C "$name" . |
| 258 | |
| 259 | dx_input="${name}.desugar.jar" |
| 260 | |
| 261 | # Make desugared JAR. |
| 262 | desugar --input "$name.before-desugar.jar" --output "$dx_input" |
| 263 | else |
| 264 | dx_input="${name}" |
| 265 | fi |
| 266 | |
| 267 | # Make dex file from desugared JAR. |
Igor Murashkin | 6919639 | 2017-06-16 15:25:32 -0700 | [diff] [blame] | 268 | ${DX} -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] | 269 | } |
| 270 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 271 | # Print the directory name only if it exists. |
| 272 | function maybe_dir() { |
| 273 | local dirname="$1" |
| 274 | if [[ -d "$dirname" ]]; then |
| 275 | echo "$dirname" |
| 276 | fi |
| 277 | } |
| 278 | |
Stephen Kyle | 40d3518 | 2014-10-03 13:47:56 +0100 | [diff] [blame] | 279 | if [ -e classes.dex ]; then |
| 280 | zip $TEST_NAME.jar classes.dex |
| 281 | exit 0 |
| 282 | fi |
| 283 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 284 | if ! [ "${HAS_SRC}" = "true" ] && ! [ "${HAS_SRC2}" = "true" ] && ! [ "${HAS_SRC_ART}" = "true" ]; then |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 285 | # No src directory? Then forget about trying to run dx. |
| 286 | SKIP_DX_MERGER="true" |
| 287 | fi |
| 288 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 289 | if [ ${HAS_SRC_DEX2OAT_UNRESOLVED} = "true" ]; then |
| 290 | mkdir classes |
| 291 | mkdir classes-ex |
| 292 | ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src-dex2oat-unresolved -d classes `find src -name '*.java'` |
| 293 | ${JAVAC} ${JAVAC_ARGS} -implicit:none -sourcepath src -d classes-ex `find src-dex2oat-unresolved -name '*.java'` |
| 294 | if [ ${USE_JACK} = "true" ]; then |
| 295 | jar cf classes.jill.jar -C classes . |
| 296 | jar cf classes-ex.jill.jar -C classes-ex . |
| 297 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 298 | ${JACK} --import classes-ex.jill.jar --output-dex . |
| 299 | zip ${TEST_NAME}-ex.jar classes.dex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 300 | ${JACK} --import classes.jill.jar --output-dex . |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 301 | else |
| 302 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 303 | make_dex classes-ex |
Igor Murashkin | 6c946b5 | 2017-06-16 14:27:47 -0700 | [diff] [blame] | 304 | 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] | 305 | zip ${TEST_NAME}-ex.jar classes.dex |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 306 | make_dex classes |
Sebastien Hertz | 4856ca7 | 2016-03-03 18:08:17 +0100 | [diff] [blame] | 307 | fi |
Alex Light | 6a439bc | 2015-10-26 17:52:36 -0700 | [diff] [blame] | 308 | fi |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 309 | else |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 310 | if [ ${USE_JACK} = "true" ]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 311 | # Jack toolchain |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 312 | if [[ "$HAS_SRC" == true || "$HAS_SRC_ART" == true ]]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 313 | if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then |
| 314 | # Compile src and src-multidex in the same .jack file. We will apply multidex partitioning |
| 315 | # when creating the output .dex file. |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 316 | ${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] | 317 | jack_extra_args="${jack_extra_args} -D jack.dex.output.policy=minimal-multidex" |
| 318 | jack_extra_args="${jack_extra_args} -D jack.preprocessor=true" |
| 319 | jack_extra_args="${jack_extra_args} -D jack.preprocessor.file=multidex.jpp" |
| 320 | else |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 321 | ${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] | 322 | fi |
| 323 | jack_extra_args="${jack_extra_args} --import src.jack" |
| 324 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 325 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 326 | if [ "${HAS_SRC2}" = "true" ]; then |
| 327 | ${JACK} ${JACK_ARGS} --output-jack src2.jack src2 |
| 328 | # In case of duplicate classes, we want to take into account the classes from src2. Therefore |
| 329 | # we apply the 'keep-first' policy and import src2.jack file *before* the src.jack file. |
| 330 | jack_extra_args="${jack_extra_args} -D jack.import.type.policy=keep-first" |
| 331 | jack_extra_args="--import src2.jack ${jack_extra_args}" |
| 332 | fi |
| 333 | |
| 334 | # Compile jack files into a DEX file. |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 335 | if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ] || [ "${HAS_SRC_ART}" ]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 336 | ${JACK} ${JACK_ARGS} ${jack_extra_args} --output-dex . |
| 337 | fi |
| 338 | else |
| 339 | # Legacy toolchain with javac+dx |
| 340 | if [ "${HAS_SRC}" = "true" ]; then |
| 341 | mkdir classes |
| 342 | ${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'` |
| 343 | fi |
| 344 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 345 | if [ "${HAS_SRC_ART}" = "true" ]; then |
| 346 | mkdir -p classes |
| 347 | javac_with_bootclasspath ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'` |
| 348 | fi |
| 349 | |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 350 | if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then |
| 351 | mkdir classes2 |
Igor Murashkin | 10ba685 | 2017-06-21 11:05:23 -0700 | [diff] [blame] | 352 | ${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] | 353 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 354 | make_dex classes2 |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 355 | fi |
| 356 | fi |
| 357 | |
| 358 | if [ "${HAS_SRC2}" = "true" ]; then |
| 359 | mkdir -p classes |
| 360 | ${JAVAC} ${JAVAC_ARGS} -d classes `find src2 -name '*.java'` |
| 361 | fi |
| 362 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 363 | if [[ "${HAS_SRC}" == "true" || "${HAS_SRC2}" == "true" || "${HAS_SRC_ART}" == "true" ]]; then |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 364 | if [ ${NEED_DEX} = "true" -a ${SKIP_DX_MERGER} = "false" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 365 | make_dex classes |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 366 | fi |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame] | 367 | fi |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 368 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 369 | fi |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 370 | |
Andreas Gampe | 2b93681 | 2017-02-07 16:03:57 -0800 | [diff] [blame] | 371 | if [ "${HAS_SMALI}" = "true" -a ${NEED_DEX} = "true" ]; then |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 372 | # Compile Smali classes |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 373 | ${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] | 374 | |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 375 | # Don't bother with dexmerger if we provide our own main function in a smali file. |
| 376 | if [ ${SKIP_DX_MERGER} = "false" ]; then |
| 377 | ${DXMERGER} classes.dex classes.dex smali_classes.dex |
| 378 | else |
| 379 | mv smali_classes.dex classes.dex |
| 380 | fi |
| 381 | fi |
| 382 | |
Andreas Gampe | 2b93681 | 2017-02-07 16:03:57 -0800 | [diff] [blame] | 383 | if [ "${HAS_SMALI_MULTIDEX}" = "true" -a ${NEED_DEX} = "true" ]; then |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 384 | # Compile Smali classes |
Ben Gruver | 14fc9db | 2017-04-28 15:30:49 -0700 | [diff] [blame] | 385 | ${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] | 386 | |
| 387 | # Don't bother with dexmerger if we provide our own main function in a smali file. |
| 388 | if [ ${HAS_SRC_MULTIDEX} = "true" ]; then |
| 389 | ${DXMERGER} classes2.dex classes2.dex smali_classes2.dex |
| 390 | else |
| 391 | mv smali_classes2.dex classes2.dex |
| 392 | fi |
| 393 | fi |
| 394 | |
| 395 | |
| 396 | if [ ${HAS_SRC_EX} = "true" ]; then |
| 397 | if [ ${USE_JACK} = "true" ]; then |
| 398 | # Rename previous "classes.dex" so it is not overwritten. |
| 399 | mv classes.dex classes-1.dex |
| 400 | #TODO find another way to append src.jack to the jack classpath |
| 401 | ${JACK}:src.jack ${JACK_ARGS} --output-dex . src-ex |
| 402 | zip $TEST_NAME-ex.jar classes.dex |
| 403 | # Restore previous "classes.dex" so it can be zipped. |
| 404 | mv classes-1.dex classes.dex |
| 405 | else |
Igor Murashkin | 829da13 | 2017-06-21 14:47:12 -0700 | [diff] [blame] | 406 | # Build src-ex into classes-ex. |
| 407 | # Includes 'src', 'src-art' source when compiling classes-ex, but exclude their .class files. |
| 408 | if [[ "${HAS_SRC}" == "true" ]]; then |
| 409 | mkdir -p classes-tmp-for-ex |
| 410 | ${JAVAC} ${JAVAC_ARGS} -d classes-tmp-for-ex `find src -name '*.java'` |
| 411 | src_tmp_for_ex="-cp classes-tmp-for-ex" |
| 412 | fi |
| 413 | if [[ "${HAS_SRC_ART}" == "true" ]]; then |
| 414 | mkdir -p classes-tmp-for-ex |
| 415 | javac_with_bootclasspath ${JAVAC_ARGS} -d classes-tmp-for-ex `find src-art -name '*.java'` |
| 416 | src_tmp_for_ex="-cp classes-tmp-for-ex" |
| 417 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 418 | mkdir classes-ex |
Igor Murashkin | 829da13 | 2017-06-21 14:47:12 -0700 | [diff] [blame] | 419 | ${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] | 420 | if [ ${NEED_DEX} = "true" ]; then |
Igor Murashkin | 2a33775 | 2017-06-16 14:34:40 +0000 | [diff] [blame] | 421 | make_dex classes-ex |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 422 | |
| 423 | # quick shuffle so that the stored name is "classes.dex" |
| 424 | mv classes.dex classes-1.dex |
| 425 | mv classes-ex.dex classes.dex |
| 426 | zip $TEST_NAME-ex.jar classes.dex |
| 427 | mv classes.dex classes-ex.dex |
| 428 | mv classes-1.dex classes.dex |
Nicolas Geoffray | 404b5bf | 2016-03-16 12:39:17 +0000 | [diff] [blame] | 429 | fi |
| 430 | fi |
Nicolas Geoffray | 44fd0e5 | 2016-03-16 15:16:06 +0000 | [diff] [blame] | 431 | fi |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 432 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 433 | # Create a single jar with two dex files for multidex. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 434 | if [ ${NEED_DEX} = "true" ]; then |
| 435 | if [ ${HAS_SRC_MULTIDEX} = "true" ] || [ ${HAS_SMALI_MULTIDEX} = "true" ]; then |
| 436 | zip $TEST_NAME.jar classes.dex classes2.dex |
| 437 | else |
| 438 | zip $TEST_NAME.jar classes.dex |
| 439 | fi |
Nicolas Geoffray | 1250861 | 2014-11-05 12:34:24 +0000 | [diff] [blame] | 440 | fi |