Skip to content

Commit

Permalink
Allow more cross-referencing between run-test sources.
Browse files Browse the repository at this point in the history
Allow all primary sources (src/, src-multidex/, src-aotex/,
src-bcpex/, src-ex/) to reference each other and jasmin*/
classes. Allow all replacement sources (src-art/, src2/,
src-ex2/) to reference the above classes.

The src/ folder needs to exist for this to take place, so
we moved src-art/ files to src/ in some tests.

As we're now compiling more files together into the `-cp`
folder "classes-tmp-all", classes defined in both src/
and src-ex/ would clash, so we moved the src-ex/ version
into src-ex2/.

Test: testrunner.py --host --optimizing --jvm
Test: testrunner.py --target --optimizing
Bug: 203171409
Change-Id: Ic890038b273f9ed7a99313f8d94323a2b612af43
  • Loading branch information
vmarko authored and Treehugger Robot committed Feb 15, 2022
1 parent 7116f80 commit dd0a65d
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 62 deletions.
23 changes: 7 additions & 16 deletions test/004-JniTest/build
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,20 @@
#
# Perform a mostly normal build.
# Since this test imports 'dalvik.annotation.optimization.FastNative' (and CriticalNative),
# we do a bit of trickery to allow the annotations to be used at javac-compile time,
# but remove them afterwards so it doesn't end up in the dex file.
# we put them to src-aotex/ to allow the annotations to be used at javac-compile time,
# but remove compiled *-aotex* artifacts afterwards.
#
# This enables the test to compile with vanilla RI javac and work on either ART or RI.
# TODO: The test is currently disabled for RI anyway, presumably because @CriticalNative
# has a different ABI and cannot be tested on RI.
#

# Stop on failure.
set -e

export ORIGINAL_JAVAC="$JAVAC"

# Wrapper function for javac which invokes the compiler and applies
# additional setup steps for the test.
cat >javac_wrapper.sh <<"EOF"
set -e # Stop on error - the caller script may not have this set.
$ORIGINAL_JAVAC "$@"
# Delete CriticalNative.java, FastNative.java annotations after building the .class files.
find classes/dalvik -name '*.class' -exec rm {} \;
EOF
export JAVAC=./javac_wrapper.sh

######################################################################

# Use release mode to check optimizations do not break JNI.
export D8_FLAGS=--release
./default-build "$@"

# Remove the *-aotex build artifacts (but keep src-aotex) with dalvik.* annotations.
rm -rf classes-aotex classes-aotex.jar $TEST_NAME-aotex.jar
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
84 changes: 38 additions & 46 deletions test/etc/default-build
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,39 @@ def has_multidex():
return HAS_SRC_MULTIDEX or HAS_JASMIN_MULTIDEX or HAS_SMALI_MULTIDEX


def add_to_cp_args(old_cp_args, path):
if len(old_cp_args) == 0:
return ["-cp", path]
else:
return ["-cp", old_cp_args[1] + ":" + path]


src_tmp_all = []
if HAS_SRC and (HAS_SRC_MULTIDEX or HAS_SRC_AOTEX or HAS_SRC_BCPEX):
# To allow circular references, compile src/, src-multidex/, src-aotex/ and
# src-bcpex/ together and pass the output as class path argument.
# Replacement sources in src-art/ and src2 can replace symbols used by the
# other src-* sources we compile here but everything needed to compile the
# other src-* sources should be present in src/.

if HAS_JASMIN:
make_jasmin("jasmin_classes", find("jasmin", "*.j"))
src_tmp_all = add_to_cp_args(src_tmp_all, "jasmin_classes")

if HAS_JASMIN_MULTIDEX:
make_jasmin("jasmin_classes2", find("jasmin-multidex", "*.j"))
src_tmp_all = add_to_cp_args(src_tmp_all, "jasmin_classes2")

if HAS_SRC and (HAS_SRC_MULTIDEX or HAS_SRC_AOTEX or HAS_SRC_BCPEX or
HAS_SRC_EX or HAS_SRC_ART or HAS_SRC2 or HAS_SRC_EX2):
# To allow circular references, compile src/, src-multidex/, src-aotex/,
# src-bcpex/, src-ex/ together and pass the output as class path argument.
# Replacement sources in src-art/, src2/ and src-ex2/ can replace symbols
# used by the other src-* sources we compile here but everything needed to
# compile the other src-* sources should be present in src/ (and jasmin*/).
os.makedirs("classes-tmp-all")
javac_with_bootclasspath(["-implicit:none", "-d", "classes-tmp-all"] +
javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
["-d", "classes-tmp-all"] +
find("src", "*.java") +
find("src-multidex", "*.java") +
find("src-aotex", "*.java") +
find("src-bcpex", "*.java"))
src_tmp_all = ["-cp", "classes-tmp-all"]
find("src-bcpex", "*.java") +
find("src-ex", "*.java"))
src_tmp_all = add_to_cp_args(src_tmp_all, "classes-tmp-all")

if HAS_SRC_AOTEX:
os.makedirs("classes-aotex")
Expand Down Expand Up @@ -309,7 +328,8 @@ if HAS_SRC_MULTIDEX:

if HAS_SRC2:
os.makedirs("classes", exist_ok=True)
javac_with_bootclasspath(["-classpath", "classes", "-d", "classes"] +
javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
["-d", "classes"] +
find("src2", "*.java"))

# If the classes directory is not-empty, package classes in a DEX file.
Expand All @@ -320,7 +340,6 @@ if find("classes", "*"):

if HAS_JASMIN:
# Compile Jasmin classes as if they were part of the classes.dex file.
make_jasmin("jasmin_classes", find("jasmin", "*.j"))
if NEED_DEX:
make_dex("jasmin_classes")
make_dexmerge("classes.dex", "jasmin_classes.dex")
Expand All @@ -342,8 +361,6 @@ if HAS_SMALI and NEED_DEX:
# Compile Jasmin classes in jasmin-multidex as if they were part of
# the classes2.jar
if HAS_JASMIN_MULTIDEX:
make_jasmin("jasmin_classes2", find("jasmin-multidex", "*.j"))

if NEED_DEX:
make_dex("jasmin_classes2")
make_dexmerge("classes2.dex", "jasmin_classes2.dex")
Expand All @@ -362,40 +379,15 @@ if HAS_SMALI_MULTIDEX and NEED_DEX:
# Merge smali_classes2.dex into classes2.dex
make_dexmerge("classes2.dex", "smali_classes2.dex")

if HAS_SRC_EX or HAS_SRC_EX2:
# Build src-ex into classes-ex.
# Includes 'src', 'src-art' and 'jasmin' source when compiling classes-ex,
# but exclude their .class files.
src_tmp_for_ex = []
if HAS_SRC or HAS_SRC_ART or HAS_JASMIN:
os.makedirs("classes-tmp-for-ex", exist_ok=True)
src_tmp_for_ex = ["-cp", "classes-tmp-for-ex"]
if HAS_SRC and HAS_SRC_MULTIDEX:
javac_with_bootclasspath(["-d", "classes-tmp-for-ex"] +
find("src", "*.java") +
find("src-multidex", "*.java"))
elif HAS_SRC:
javac_with_bootclasspath(["-d", "classes-tmp-for-ex"] +
find("src", "*.java"))
elif HAS_SRC_MULTIDEX:
javac_with_bootclasspath(["-d", "classes-tmp-for-ex"] +
find("src-multidex", "*.java"))
if HAS_SRC_ART:
javac_with_bootclasspath(["-d", "classes-tmp-for-ex"] +
find("src-art", "*.java"))
if HAS_JASMIN:
make_jasmin("classes-tmp-for-ex", find("jasmin", "*.j"))
if HAS_SRC_EX:
os.makedirs("classes-ex", exist_ok=True)
if HAS_SRC_EX:
javac_with_bootclasspath(["-d", "classes-ex"] + src_tmp_for_ex +
find("src-ex", "*.java"))
if not src_tmp_for_ex:
src_tmp_for_ex = ["-cp", "classes-ex"]
else:
src_tmp_for_ex[-1] += ":classes-ex"
if HAS_SRC_EX2:
javac_with_bootclasspath(["-d", "classes-ex"] + src_tmp_for_ex +
find("src-ex2", "*.java"))
javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
["-d", "classes-ex"] + find("src-ex", "*.java"))

if HAS_SRC_EX2:
os.makedirs("classes-ex", exist_ok=True)
javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
["-d", "classes-ex"] + find("src-ex2", "*.java"))

if path.exists("classes-ex") and NEED_DEX:
make_dex("classes-ex")
Expand Down

0 comments on commit dd0a65d

Please sign in to comment.