From b98b85d076e14c08385f6c3bd7309f7361175e14 Mon Sep 17 00:00:00 2001 From: Ted Xie Date: Wed, 8 Apr 2026 11:51:28 -0400 Subject: [PATCH 1/2] Fix dexer test --- .../com/google/devtools/build/android/dexer/BUILD | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD b/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD index 50b942bb..f534d305 100644 --- a/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD +++ b/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD @@ -53,14 +53,16 @@ java_test( size = "small", srcs = ["AllTests.java"], data = [ + ":fields_types_jar", ":jsimple_jar", ":multidex_jar", ":simple_jar", ], jvm_flags = [ - "-Djsimplejar=google3/$(location :jsimple_jar)", - "-Dmultidexjar=google3/$(location :multidex_jar)", - "-Dsimplejar=google3/$(location :simple_jar)", + "-Dfields_types_jar=rules_android/$(location :fields_types_jar)", + "-Djsimplejar=rules_android/$(location :jsimple_jar)", + "-Dmultidexjar=rules_android/$(location :multidex_jar)", + "-Dsimplejar=rules_android/$(location :simple_jar)", ], runtime_deps = [ ":tests", From adad70c9da80ac51cd6a8795f0b29d2692f4be10 Mon Sep 17 00:00:00 2001 From: Ted Xie Date: Wed, 8 Apr 2026 11:57:34 -0400 Subject: [PATCH 2/2] augment test to also work in google3 --- .../google/devtools/build/android/dexer/BUILD | 8 ++--- .../android/dexer/DexFileSplitterTest.java | 32 ++++++++++++++++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD b/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD index f534d305..1ccc73bf 100644 --- a/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD +++ b/src/tools/javatests/com/google/devtools/build/android/dexer/BUILD @@ -59,10 +59,10 @@ java_test( ":simple_jar", ], jvm_flags = [ - "-Dfields_types_jar=rules_android/$(location :fields_types_jar)", - "-Djsimplejar=rules_android/$(location :jsimple_jar)", - "-Dmultidexjar=rules_android/$(location :multidex_jar)", - "-Dsimplejar=rules_android/$(location :simple_jar)", + "-Dfields_types_jar=$(location :fields_types_jar)", + "-Djsimplejar=$(location :jsimple_jar)", + "-Dmultidexjar=$(location :multidex_jar)", + "-Dsimplejar=$(location :simple_jar)", ], runtime_deps = [ ":tests", diff --git a/src/tools/javatests/com/google/devtools/build/android/dexer/DexFileSplitterTest.java b/src/tools/javatests/com/google/devtools/build/android/dexer/DexFileSplitterTest.java index 5bfb42a1..09faf40a 100644 --- a/src/tools/javatests/com/google/devtools/build/android/dexer/DexFileSplitterTest.java +++ b/src/tools/javatests/com/google/devtools/build/android/dexer/DexFileSplitterTest.java @@ -63,15 +63,39 @@ public class DexFileSplitterTest { Runfiles runfiles = Runfiles.create(); // Look in the BUILD file for the corresponding genrules that codegen these jars. - SIMPLE_JAR = Paths.get(runfiles.rlocation(System.getProperty("simplejar"))); - MULTIDEX_JAR = Paths.get(runfiles.rlocation(System.getProperty("multidexjar"))); - JSIMPLE_JAR = Paths.get(runfiles.rlocation(System.getProperty("jsimplejar"))); - FIELDS_TYPES_JAR = Paths.get(runfiles.rlocation(System.getProperty("fields_types_jar"))); + SIMPLE_JAR = getRunfile(runfiles, "simplejar"); + MULTIDEX_JAR = getRunfile(runfiles, "multidexjar"); + JSIMPLE_JAR = getRunfile(runfiles, "jsimplejar"); + FIELDS_TYPES_JAR = getRunfile(runfiles, "fields_types_jar"); } catch (Exception e) { throw new ExceptionInInitializerError(e); } } + private static Path getRunfile(Runfiles runfiles, String property) { + String path = System.getProperty(property); + // This code lives simultaneously in a repo called google3 as well as the current repo + // rules_android. We check both prefixes to ensure the runfiles can be found in both + // environments. + String google3Path = runfiles.rlocation("google3/" + path); + if (google3Path != null && Files.exists(Paths.get(google3Path))) { + return Paths.get(google3Path); + } + String rulesAndroidPath = runfiles.rlocation("rules_android/" + path); + if (rulesAndroidPath != null && Files.exists(Paths.get(rulesAndroidPath))) { + return Paths.get(rulesAndroidPath); + } + + // Fallback for cases where neither prefix works (e.g. absolute paths or other prefixes) + String rlocation = runfiles.rlocation(path); + if (rlocation != null) { + return Paths.get(rlocation); + } + + throw new RuntimeException( + "Could not find runfile for property " + property + ": " + path); + } + private Path simpleDexArchive; private Path multidexArchive; private Path jsimpleDexArchive;