blob: c281bca3f5f579912c6cdce85142ee001b13f6ed [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
29 elif expr "x$1" : "x--" >/dev/null 2>&1; then
30 echo "unknown $0 option: $1" 1>&2
31 exit 1
32 else
33 break
34 fi
35done
36
Stephen Kyle40d35182014-10-03 13:47:56 +010037if [ -e classes.dex ]; then
38 zip $TEST_NAME.jar classes.dex
39 exit 0
40fi
41
Igor Murashkin158f35c2015-06-10 15:55:30 -070042if ! [ -d src ] && ! [ -d src2 ]; then
43 # No src directory? Then forget about trying to run dx.
44 SKIP_DX_MERGER="true"
45fi
46
Sebastien Hertz19ac0272015-02-24 17:39:50 +010047if [ -d src-multidex ]; then
48 # Jack does not support this configuration unless we specify how to partition the DEX file
49 # with a .jpp file.
50 USE_JACK="false"
51fi
52
53if [ ${USE_JACK} = "true" ]; then
54 # Jack toolchain
55 if [ -d src ]; then
56 ${JACK} --output-jack src.jack src
57 imported_jack_files="--import src.jack"
58 fi
59
60 if [ -d src2 ]; then
61 ${JACK} --output-jack src2.jack src2
62 imported_jack_files="--import src2.jack ${imported_jack_files}"
63 fi
64
65 # Compile jack files into a DEX file. We set jack.import.type.policy=keep-first to consider
66 # class definitions from src2 first.
67 ${JACK} ${imported_jack_files} -D jack.import.type.policy=keep-first --output-dex .
68else
69 # Legacy toolchain with javac+dx
70 if [ -d src ]; then
71 mkdir classes
72 ${JAVAC} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
73 fi
74
75 if [ -d src-multidex ]; then
76 mkdir classes2
77 ${JAVAC} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
78 if [ ${NEED_DEX} = "true" ]; then
79 ${DX} -JXmx256m --debug --dex --dump-to=classes2.lst --output=classes2.dex \
80 --dump-width=1000 ${DX_FLAGS} classes2
81 fi
82 fi
83
84 if [ -d src2 ]; then
85 mkdir -p classes
86 ${JAVAC} -d classes `find src2 -name '*.java'`
87 fi
88
89 if [ ${NEED_DEX} = "true" -a ${SKIP_DX_MERGER} = "false" ]; then
90 ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex \
91 --dump-width=1000 ${DX_FLAGS} classes
92 fi
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +010093fi
94
Roland Levillain560b5ac2014-10-23 16:40:59 +010095if [ -d smali ]; then
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +010096 # Compile Smali classes
Igor Murashkin158f35c2015-06-10 15:55:30 -070097 ${SMALI} -JXmx256m --experimental --api-level 23 --output smali_classes.dex `find smali -name '*.smali'`
98
99 # Don't bother with dexmerger if we provide our own main function in a smali file.
100 if [ ${SKIP_DX_MERGER} = "false" ]; then
101 ${DXMERGER} classes.dex classes.dex smali_classes.dex
102 else
103 mv smali_classes.dex classes.dex
104 fi
Elliott Hughesc717eef2012-06-15 16:01:26 -0700105fi
TDYa127b92bcab2012-04-08 00:09:51 -0700106
Roland Levillain560b5ac2014-10-23 16:40:59 +0100107if [ -d src-ex ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100108 if [ ${USE_JACK} = "true" ]; then
109 # Rename previous "classes.dex" so it is not overwritten.
110 mv classes.dex classes-1.dex
111 #TODO find another way to append src.jack to the jack classpath
112 ${JACK}:src.jack --output-dex . src-ex
113 zip $TEST_NAME-ex.jar classes.dex
114 # Restore previous "classes.dex" so it can be zipped.
115 mv classes-1.dex classes.dex
116 else
117 mkdir classes-ex
118 ${JAVAC} -d classes-ex -cp classes `find src-ex -name '*.java'`
119 if [ ${NEED_DEX} = "true" ]; then
120 ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes-ex.dex \
121 --dump-width=1000 ${DX_FLAGS} classes-ex
jeffhao5d1ac922011-09-29 17:41:15 -0700122
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100123 # quick shuffle so that the stored name is "classes.dex"
124 mv classes.dex classes-1.dex
125 mv classes-ex.dex classes.dex
126 zip $TEST_NAME-ex.jar classes.dex
127 mv classes.dex classes-ex.dex
128 mv classes-1.dex classes.dex
129 fi
Elliott Hughesc717eef2012-06-15 16:01:26 -0700130 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700131fi
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100132
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000133# Create a single jar with two dex files for multidex.
134if [ -d src-multidex ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100135 zip $TEST_NAME.jar classes.dex classes2.dex
Nicolas Geoffray9437b782015-03-25 10:08:51 +0000136elif [ ${NEED_DEX} = "true" ]; then
Nicolas Geoffray12508612014-11-05 12:34:24 +0000137 zip $TEST_NAME.jar classes.dex
138fi