Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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=$(location :fields_types_jar)",
"-Djsimplejar=$(location :jsimple_jar)",
"-Dmultidexjar=$(location :multidex_jar)",
"-Dsimplejar=$(location :simple_jar)",
],
runtime_deps = [
":tests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down