test: enable javac/dx to import libcore on the bootclasspath
Fixes 12 tests with javac/dx.
Previously, javac with the default bootclasspath (unspecified) was used,
meaning that it would usually pickup rt.jar from a developer's JDK system
install.
With javac-helper.sh, libcore is used for the javac -bootclasspath,
enabling art tests to load libcore-specific packages such as libcore or
dalvik (in particular, it uses the output of art/tools/bootjars.sh which
calculates the correct bootclasspath from the build artifacts).
To get libcore on the bootclasspath, source files must be placed in a
'art/test/$TESTNAME/src-art' directory. Otherwise the old behavior is
kept to encourage tests to be cross-platform compatible.
The minimal set of tests that relied on 'import dalvik/import libcore'
had their src directories renamed to src-art, and are now building
successfully.
Test: ANDROID_COMPILE_WITH_JACK=false art/test.py
Bug: 36902714
Change-Id: Iafd245de9e04c312c5ac107897e34d7b97191726
diff --git a/test/etc/default-build b/test/etc/default-build
index a88ef92..977b071 100755
--- a/test/etc/default-build
+++ b/test/etc/default-build
@@ -30,6 +30,13 @@
HAS_SRC=false
fi
+# .java files in src-art get compiled with libcore on the bootclasspath
+if [ -d src-art ]; then
+ HAS_SRC_ART=true
+else
+ HAS_SRC_ART=false
+fi
+
if [ -d src2 ]; then
HAS_SRC2=true
else
@@ -225,6 +232,20 @@
"$DESUGAR" --core-only $desugar_args "$@"
}
+# Like regular javac but includes libcore on the bootclasspath.
+function javac_with_bootclasspath {
+ local javac_args=--mode=host
+ if [[ $BUILD_MODE == target ]]; then
+ javac_args=--mode=target
+ fi
+
+ if [[ $DEV_MODE == yes ]]; then
+ javac_args="$javac_args --show-commands"
+ fi
+
+ "$ANDROID_BUILD_TOP/art/tools/javac-helper.sh" --core-only $javac_args "$@"
+}
+
# Make a "dex" file given a directory of classes in $1.
# Also calls desugar on the classes first to convert lambdas.
function make_dex() {
@@ -247,12 +268,20 @@
${DX} -JXmx256m ${DX_VM_FLAGS} --debug --dex --dump-to=${name}.lst --output=${name}.dex --dump-width=1000 ${DX_FLAGS} "${dx_input}"
}
+# Print the directory name only if it exists.
+function maybe_dir() {
+ local dirname="$1"
+ if [[ -d "$dirname" ]]; then
+ echo "$dirname"
+ fi
+}
+
if [ -e classes.dex ]; then
zip $TEST_NAME.jar classes.dex
exit 0
fi
-if ! [ "${HAS_SRC}" = "true" ] && ! [ "${HAS_SRC2}" = "true" ]; then
+if ! [ "${HAS_SRC}" = "true" ] && ! [ "${HAS_SRC2}" = "true" ] && ! [ "${HAS_SRC_ART}" = "true" ]; then
# No src directory? Then forget about trying to run dx.
SKIP_DX_MERGER="true"
fi
@@ -280,16 +309,16 @@
else
if [ ${USE_JACK} = "true" ]; then
# Jack toolchain
- if [ "${HAS_SRC}" = "true" ]; then
+ if [[ "$HAS_SRC" == true || "$HAS_SRC_ART" == true ]]; then
if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then
# Compile src and src-multidex in the same .jack file. We will apply multidex partitioning
# when creating the output .dex file.
- ${JACK} ${JACK_ARGS} --output-jack src.jack src src src-multidex
+ ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) src-multidex $(maybe_dir src-art)
jack_extra_args="${jack_extra_args} -D jack.dex.output.policy=minimal-multidex"
jack_extra_args="${jack_extra_args} -D jack.preprocessor=true"
jack_extra_args="${jack_extra_args} -D jack.preprocessor.file=multidex.jpp"
else
- ${JACK} ${JACK_ARGS} --output-jack src.jack src
+ ${JACK} ${JACK_ARGS} --output-jack src.jack $(maybe_dir src) $(maybe_dir src-art)
fi
jack_extra_args="${jack_extra_args} --import src.jack"
fi
@@ -303,7 +332,7 @@
fi
# Compile jack files into a DEX file.
- if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ]; then
+ if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ] || [ "${HAS_SRC_ART}" ]; then
${JACK} ${JACK_ARGS} ${jack_extra_args} --output-dex .
fi
else
@@ -313,6 +342,11 @@
${JAVAC} ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
fi
+ if [ "${HAS_SRC_ART}" = "true" ]; then
+ mkdir -p classes
+ javac_with_bootclasspath ${JAVAC_ARGS} -implicit:none -classpath src-multidex -d classes `find src-art -name '*.java'`
+ fi
+
if [ "${HAS_SRC_MULTIDEX}" = "true" ]; then
mkdir classes2
${JAVAC} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
@@ -326,7 +360,7 @@
${JAVAC} ${JAVAC_ARGS} -d classes `find src2 -name '*.java'`
fi
- if [ "${HAS_SRC}" = "true" ] || [ "${HAS_SRC2}" = "true" ]; then
+ if [[ "${HAS_SRC}" == "true" || "${HAS_SRC2}" == "true" || "${HAS_SRC_ART}" == "true" ]]; then
if [ ${NEED_DEX} = "true" -a ${SKIP_DX_MERGER} = "false" ]; then
make_dex classes
fi