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