blob: 90a60e6f8f359721790646f5abff76a9636f0304 [file] [log] [blame]
Orion Hodsonc069a302017-01-18 09:23:12 +00001#!/bin/bash
2#
3# Copyright (C) 2017 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# Set up prog to be the path of this script, including following symlinks,
18# and set up progdir to be the fully-qualified pathname of its directory.
19prog="$0"
20args="$@"
21while [ -h "${prog}" ]; do
22 newProg=`/bin/ls -ld "${prog}"`
23 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
24 if expr "x${newProg}" : 'x/' >/dev/null; then
25 prog="${newProg}"
26 else
27 progdir=`dirname "${prog}"`
28 prog="${progdir}/${newProg}"
29 fi
30done
31oldwd=`pwd`
32progdir=`dirname "${prog}"`
33cd "${progdir}"
34progdir=`pwd`
35prog="${progdir}"/`basename "${prog}"`
36test_dir="test-$$"
37if [ -z "$TMPDIR" ]; then
38 tmp_dir="/tmp/$USER/${test_dir}"
39else
40 tmp_dir="${TMPDIR}/${test_dir}"
41fi
42
43# This is a custom drop that necessitates this complexity.
44JACK_ANNOTATIONS_LIB=$HOME/Downloads/jack-test-annotations-lib.jack
45
46# Compile test into a base64 string that can be instantiated via
47# reflection on hosts without the jack-test-annotations-lib.jack file.
48mkdir $tmp_dir
49for input_file in $progdir/*.java; do
50 i=${input_file##*/Test}
51 i=${i%%.java}
52 src_file=$progdir/Test$i.java
53 jack_file=./src.jack
54 dex_file=./classes.dex
55 base_64_file=$tmp_dir/TestData$i.base64
56 output_file=$progdir/../src/TestData$i.java
57 # Compile source file to jack file.
58 jack -g -cp $ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:$ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack:$JACK_ANNOTATIONS_LIB -D sched.runner=multi-threaded -D sched.runner.thread.kind=fixed -D sched.runner.thread.fixed.count=4 -D jack.java.source.version=1.7 -D jack.android.min-api-level=o-b2 --output-jack $jack_file $src_file
59 # Compile jack file to classes.dex.
60 jack -g -cp $ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:$ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack -D sched.runner=multi-threaded -D sched.runner.thread.kind=fixed -D sched.runner.thread.fixed.count=4 -D jack.java.source.version=1.7 -D jack.android.min-api-level=o-b2 --import $jack_file --output-dex .
61 # Pack the classes.dex file into a base64 string.
62 base64 -w 72 $dex_file > $base_64_file
63 # Emit a managed source file containing the base64 string. The test can be
64 # run by loading this string as a dex file and invoking it via reflection.
65cat > $output_file <<HEADER
66/* Generated by ${prog##*/} from ${src_file##*/} */
67public class TestData$i {
68 public static final String BASE64_DEX_FILE =
69HEADER
70sed -e 's/^\(.*\)$/ "\1" +/' -e '$s/ +/;/' $base_64_file >> $output_file
71cat >> $output_file <<FOOTER
72}
73FOOTER
74 rm $dex_file $jack_file
75done
76
77rm -rf $tmp_dir