blob: d1d82212615d6c6f27dc80e5801961002e1174e9 [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
Orion Hodson6005f422017-02-15 15:48:28 +000043if [ "x$ANDROID_BUILD_TOP" = "x" ]; then
44 echo Build environment is not set-up.
45 exit -1
46fi
47
48# This only works internally for now (sorry folks!)
49jack_annotations_lib=/google/data/rw/teams/android-runtime/jack/jack-test-annotations-lib.jack
50if [ ! -f $jack_annotations_lib ]; then
51 echo Try 'prodaccess' to access android-runtime directory.
52 exit -1
53fi
Orion Hodsonc069a302017-01-18 09:23:12 +000054
55# Compile test into a base64 string that can be instantiated via
56# reflection on hosts without the jack-test-annotations-lib.jack file.
57mkdir $tmp_dir
58for input_file in $progdir/*.java; do
59 i=${input_file##*/Test}
60 i=${i%%.java}
61 src_file=$progdir/Test$i.java
62 jack_file=./src.jack
63 dex_file=./classes.dex
64 base_64_file=$tmp_dir/TestData$i.base64
65 output_file=$progdir/../src/TestData$i.java
66 # Compile source file to jack file.
Orion Hodson6005f422017-02-15 15:48:28 +000067 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
Orion Hodsonc069a302017-01-18 09:23:12 +000068 # Compile jack file to classes.dex.
69 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 .
70 # Pack the classes.dex file into a base64 string.
71 base64 -w 72 $dex_file > $base_64_file
72 # Emit a managed source file containing the base64 string. The test can be
73 # run by loading this string as a dex file and invoking it via reflection.
74cat > $output_file <<HEADER
75/* Generated by ${prog##*/} from ${src_file##*/} */
76public class TestData$i {
77 public static final String BASE64_DEX_FILE =
78HEADER
79sed -e 's/^\(.*\)$/ "\1" +/' -e '$s/ +/;/' $base_64_file >> $output_file
80cat >> $output_file <<FOOTER
81}
82FOOTER
83 rm $dex_file $jack_file
84done
85
86rm -rf $tmp_dir