1#!/bin/bash
2#
3# Copyright 2018 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# make us exit on a failure
18set -e
19
20ASM_JAR="${ANDROID_BUILD_TOP}/prebuilts/misc/common/asm/asm-6.0.jar"
21INTERMEDIATE_CLASSES=classes-intermediate
22CLASSES=classes
23
24DEXER="${DX:-dx}"
25if [ "${USE_D8=false}" = "true" ]; then
26  DEXER="${ANDROID_HOST_OUT}/bin/d8-compat-dx"
27fi
28
29# Create directory for intermediate classes
30rm -rf "${INTERMEDIATE_CLASSES}"
31mkdir "${INTERMEDIATE_CLASSES}"
32
33# Generate intermediate classes that will allow transform to be applied to test classes
34JAVAC_ARGS="${JAVAC_ARGS} -source 1.8 -target 1.8 -cp ${ASM_JAR}"
35${JAVAC:-javac} ${JAVAC_ARGS} -d ${INTERMEDIATE_CLASSES} $(find src -name '*.java')
36
37# Create directory for transformed classes
38rm -rf "${CLASSES}"
39mkdir "${CLASSES}"
40
41# Run transform
42for class in ${INTERMEDIATE_CLASSES}/*.class ; do
43  transformed_class=${CLASSES}/$(basename ${class})
44  ${JAVA:-java} -cp "${ASM_JAR}:${INTERMEDIATE_CLASSES}" transformer.IndyTransformer ${class} ${transformed_class}
45done
46
47# Create DEX
48DX_FLAGS="${DX_FLAGS} --min-sdk-version=26 --debug --dump-width=1000"
49${DEXER} -JXmx256m --dex ${DX_FLAGS} --dump-to=${CLASSES}.lst --output=classes.dex ${CLASSES}
50
51# Zip DEX to file name expected by test runner
52zip ${TEST_NAME:-classes-dex}.jar classes.dex
53