diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java index 02758269f97c39..fc31c1f29e2c2e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java @@ -33,10 +33,11 @@ import com.google.devtools.build.lib.analysis.Runfiles; import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.analysis.RunfilesSupport; +import com.google.devtools.build.lib.analysis.SourceManifestAction; +import com.google.devtools.build.lib.analysis.SourceManifestAction.ManifestType; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; import com.google.devtools.build.lib.analysis.actions.FileWriteAction; -import com.google.devtools.build.lib.analysis.actions.LazyWritePathsFileAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.analysis.config.CompilationMode; import com.google.devtools.build.lib.collect.nestedset.NestedSet; @@ -423,19 +424,25 @@ public ConfiguredTarget create(RuleContext ruleContext) NestedSetBuilder coverageSupportFiles = NestedSetBuilder.stableOrder(); if (ruleContext.getConfiguration().isCodeCoverageEnabled()) { - // Create an artifact that contains the root relative paths of the jars on the runtime - // classpath. + // Create an artifact that contains the runfiles relative paths of the jars on the runtime + // classpath. Using SourceManifestAction is the only reliable way to match the runfiles + // creation code. Artifact runtimeClasspathArtifact = ruleContext.getUniqueDirectoryArtifact( "runtime_classpath_for_coverage", "runtime_classpath.txt", ruleContext.getBinOrGenfilesDirectory()); ruleContext.registerAction( - new LazyWritePathsFileAction( + new SourceManifestAction( + ManifestType.SOURCES_ONLY, ruleContext.getActionOwner(), runtimeClasspathArtifact, - common.getRuntimeClasspath(), - /* filesToIgnore= */ ImmutableSet.of(), + new Runfiles.Builder( + ruleContext.getWorkspaceName(), + ruleContext.getConfiguration().legacyExternalRunfiles()) + // This matches the code below in collectDefaultRunfiles. + .addTransitiveArtifactsWrappedInStableOrder(common.getRuntimeClasspath()) + .build(), true)); filesBuilder.add(runtimeClasspathArtifact); diff --git a/tools/test/collect_coverage.sh b/tools/test/collect_coverage.sh index 08ae7a657c5b67..540c4c61de5cbf 100755 --- a/tools/test/collect_coverage.sh +++ b/tools/test/collect_coverage.sh @@ -140,7 +140,7 @@ if [[ ! -z "${JAVA_RUNTIME_CLASSPATH_FOR_COVERAGE}" ]]; then # Append the runfiles prefix to all the relative paths found in # JAVA_RUNTIME_CLASSPATH_FOR_COVERAGE, to invoke SingleJar with the # absolute paths. - RUNFILES_PREFIX="$TEST_SRCDIR/$TEST_WORKSPACE/" + RUNFILES_PREFIX="$TEST_SRCDIR/" cat "$JAVA_RUNTIME_CLASSPATH_FOR_COVERAGE" | sed "s@^@$RUNFILES_PREFIX@" >> "$single_jar_params_file" # Invoke SingleJar. This will create JACOCO_METADATA_JAR.