Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/tools/java/com/google/devtools/build/android/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ java_binary(
# recent example, 400 MB of memory was enough for about 500,000 entries.
jvm_flags = [
"-Xmx1600m",
"-Drunfiles.path=$$0.runfiles",
"-Dsinglejar.path=$(rlocationpath //tools/jdk:singlejar)",
],
main_class = "com.google.devtools.build.android.ZipFilterAction",
Expand Down Expand Up @@ -102,6 +101,7 @@ java_library(
"@rules_android_maven//:com_google_code_findbugs_jsr305",
"@rules_android_maven//:com_google_errorprone_error_prone_annotations",
"@rules_android_maven//:com_google_guava_guava",
"@rules_java//java/runfiles",
":android_common_30_1_3",
":android_databinding_wrapper_lib",
":android_options_utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Multimap;
import com.google.devtools.build.runfiles.Runfiles;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
Expand Down Expand Up @@ -305,15 +306,13 @@ static int run(String[] args) throws IOException {
throw new IllegalArgumentException("FORCE_DEFLATE is not supported.");
}

String singleJarPath =
Path.of(System.getProperty("runfiles.path"), System.getProperty("singlejar.path"))
.toString();
String singleJarPath = resolveSingleJarPath();
ImmutableList.Builder<String> singleJarArgsBuilder = ImmutableList.builder();
singleJarArgsBuilder
.add("--sources")
.add(options.inputZip.toString())
.add(singleJarParamPath(options.inputZip))
.add("--output")
.add(options.outputZip.toString())
.add(singleJarParamPath(options.outputZip))
.add(compressionStrategy)
.add("--exclude_build_data")
.add("--normalize");
Expand Down Expand Up @@ -367,4 +366,28 @@ static int run(String[] args) throws IOException {

return sawErrors;
}

private static String resolveSingleJarPath() throws IOException {
String singleJarPath = System.getProperty("singlejar.path");
if (singleJarPath == null || singleJarPath.isEmpty()) {
throw new IOException("Missing singlejar.path system property.");
}

Path directPath = Path.of(singleJarPath);
if (directPath.isAbsolute() && Files.exists(directPath)) {
return directPath.toString();
}

String resolvedPath = Runfiles.create().rlocation(singleJarPath);
if (resolvedPath != null) {
return resolvedPath;
}

throw new IOException("Could not resolve singlejar runfile: " + singleJarPath);
}

@VisibleForTesting
static String singleJarParamPath(Path path) {
return path.toString().replace('\\', '/');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ java_test(
"//tools/jdk:singlejar",
],
jvm_flags = [
"-Drunfiles.path=$$TEST_SRCDIR",
"-Dsinglejar.path=$(rlocationpath //tools/jdk:singlejar)",
],
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ private List<String> outputEntriesWithArgs(ImmutableList<String> args, File outp
ZipFilterAction.run(args.toArray(new String[0]));
}

@Test
public void singleJarParamPath_normalizesWindowsSeparators() {
assertThat(
ZipFilterAction.singleJarParamPath(
Path.of(
"bazel-out\\x64_windows-fastbuild\\bin\\tests\\emulator_instrumentation\\"
+ "instrumentation_app_deploy.jar")))
.isEqualTo(
"bazel-out/x64_windows-fastbuild/bin/tests/emulator_instrumentation/"
+ "instrumentation_app_deploy.jar");
}

@Test public void testFullIntegration() throws IOException {
Path input = createZip(new Entry("foo.java", "foo"), new Entry("bar.class", "bar"),
new Entry("baz.class", "baz"), new Entry("1.class", "1"), new Entry("2.class", "2"),
Expand Down