blob: 47432168de8906351e40ab3e0fc6c7563e9001c0 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/bin/bash
2#
3# Copyright (C) 2008 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Stop if something fails.
18set -e
19
David Brazdil4846d132015-01-15 19:07:08 +000020DX_FLAGS=""
Igor Murashkin158f35c2015-06-10 15:55:30 -070021SKIP_DX_MERGER="false"
David Brazdil4846d132015-01-15 19:07:08 +000022
23while true; do
24 if [ "x$1" = "x--dx-option" ]; then
25 shift
26 option="$1"
27 DX_FLAGS="${DX_FLAGS} $option"
28 shift
Alex Lighteb7c1442015-08-31 13:17:42 -070029 elif [ "x$1" = "x--jvm" ]; then
30 shift
David Brazdil4846d132015-01-15 19:07:08 +000031 elif expr "x$1" : "x--" >/dev/null 2>&1; then
32 echo "unknown $0 option: $1" 1>&2
33 exit 1
34 else
35 break
36 fi
37done
38
Stephen Kyle40d35182014-10-03 13:47:56 +010039if [ -e classes.dex ]; then
40 zip $TEST_NAME.jar classes.dex
41 exit 0
42fi
43
Igor Murashkin158f35c2015-06-10 15:55:30 -070044if ! [ -d src ] && ! [ -d src2 ]; then
45 # No src directory? Then forget about trying to run dx.
46 SKIP_DX_MERGER="true"
47fi
48
Sebastien Hertz19ac0272015-02-24 17:39:50 +010049if [ -d src-multidex ]; then
50 # Jack does not support this configuration unless we specify how to partition the DEX file
51 # with a .jpp file.
52 USE_JACK="false"
53fi
54
55if [ ${USE_JACK} = "true" ]; then
56 # Jack toolchain
57 if [ -d src ]; then
58 ${JACK} --output-jack src.jack src
59 imported_jack_files="--import src.jack"
60 fi
61
62 if [ -d src2 ]; then
63 ${JACK} --output-jack src2.jack src2
64 imported_jack_files="--import src2.jack ${imported_jack_files}"
65 fi
66
67 # Compile jack files into a DEX file. We set jack.import.type.policy=keep-first to consider
68 # class definitions from src2 first.
69 ${JACK} ${imported_jack_files} -D jack.import.type.policy=keep-first --output-dex .
70else
71 # Legacy toolchain with javac+dx
72 if [ -d src ]; then
73 mkdir classes
74 ${JAVAC} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
75 fi
76
77 if [ -d src-multidex ]; then
78 mkdir classes2
79 ${JAVAC} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
80 if [ ${NEED_DEX} = "true" ]; then
81 ${DX} -JXmx256m --debug --dex --dump-to=classes2.lst --output=classes2.dex \
82 --dump-width=1000 ${DX_FLAGS} classes2
83 fi
84 fi
85
86 if [ -d src2 ]; then
87 mkdir -p classes
88 ${JAVAC} -d classes `find src2 -name '*.java'`
89 fi
90
91 if [ ${NEED_DEX} = "true" -a ${SKIP_DX_MERGER} = "false" ]; then
92 ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex \
93 --dump-width=1000 ${DX_FLAGS} classes
94 fi
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +010095fi
96
Roland Levillain560b5ac2014-10-23 16:40:59 +010097if [ -d smali ]; then
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +010098 # Compile Smali classes
Alex Light8a0e0332015-10-26 10:11:58 -070099 ${SMALI} -JXmx256m ${SMALI_ARGS} --output smali_classes.dex `find smali -name '*.smali'`
Igor Murashkin158f35c2015-06-10 15:55:30 -0700100
101 # Don't bother with dexmerger if we provide our own main function in a smali file.
102 if [ ${SKIP_DX_MERGER} = "false" ]; then
103 ${DXMERGER} classes.dex classes.dex smali_classes.dex
104 else
105 mv smali_classes.dex classes.dex
106 fi
Elliott Hughesc717eef2012-06-15 16:01:26 -0700107fi
TDYa127b92bcab2012-04-08 00:09:51 -0700108
Roland Levillain560b5ac2014-10-23 16:40:59 +0100109if [ -d src-ex ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100110 if [ ${USE_JACK} = "true" ]; then
111 # Rename previous "classes.dex" so it is not overwritten.
112 mv classes.dex classes-1.dex
113 #TODO find another way to append src.jack to the jack classpath
114 ${JACK}:src.jack --output-dex . src-ex
115 zip $TEST_NAME-ex.jar classes.dex
116 # Restore previous "classes.dex" so it can be zipped.
117 mv classes-1.dex classes.dex
118 else
119 mkdir classes-ex
120 ${JAVAC} -d classes-ex -cp classes `find src-ex -name '*.java'`
121 if [ ${NEED_DEX} = "true" ]; then
122 ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes-ex.dex \
123 --dump-width=1000 ${DX_FLAGS} classes-ex
jeffhao5d1ac922011-09-29 17:41:15 -0700124
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100125 # quick shuffle so that the stored name is "classes.dex"
126 mv classes.dex classes-1.dex
127 mv classes-ex.dex classes.dex
128 zip $TEST_NAME-ex.jar classes.dex
129 mv classes.dex classes-ex.dex
130 mv classes-1.dex classes.dex
131 fi
Elliott Hughesc717eef2012-06-15 16:01:26 -0700132 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700133fi
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100134
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000135# Create a single jar with two dex files for multidex.
136if [ -d src-multidex ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100137 zip $TEST_NAME.jar classes.dex classes2.dex
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000138elif [ ${NEED_DEX} = "true" ]; then
Nicolas Geoffray12508612014-11-05 12:34:24 +0000139 zip $TEST_NAME.jar classes.dex
140fi