@@ -71,6 +71,7 @@ public final class JavaCompilationHelper {
7171 private NestedSet <String > javaBuilderJvmFlags = NestedSetBuilder .emptySet (Order .STABLE_ORDER );
7272 private final JavaSemantics semantics ;
7373 private final ImmutableList <Artifact > additionalInputsForDatabinding ;
74+ @ Nullable private final Artifact baselineCoverageFile ;
7475 private boolean enableJspecify = true ;
7576 private boolean enableDirectClasspath = true ;
7677 private final String execGroup ;
@@ -81,13 +82,15 @@ public JavaCompilationHelper(
8182 ImmutableList <String > javacOpts ,
8283 JavaTargetAttributes .Builder attributes ,
8384 JavaToolchainProvider javaToolchainProvider ,
84- ImmutableList <Artifact > additionalInputsForDatabinding ) {
85+ ImmutableList <Artifact > additionalInputsForDatabinding ,
86+ @ Nullable Artifact baselineCoverageFile ) {
8587 this .ruleContext = ruleContext ;
8688 this .javaToolchain = Preconditions .checkNotNull (javaToolchainProvider );
8789 this .attributes = attributes ;
8890 this .customJavacOpts = javacOptsInterner .intern (javacOpts );
8991 this .semantics = semantics ;
9092 this .additionalInputsForDatabinding = additionalInputsForDatabinding ;
93+ this .baselineCoverageFile = baselineCoverageFile ;
9194
9295 if (ruleContext .useAutoExecGroups ()) {
9396 this .execGroup = semantics .getJavaToolchainType ();
@@ -247,6 +250,7 @@ && getJavaConfiguration().experimentalEnableJspecify()
247250 builder .setTargetLabel (label );
248251 Artifact coverageArtifact = maybeCreateCoverageArtifact (outputs .output ());
249252 builder .setCoverageArtifact (coverageArtifact );
253+ builder .setBaselineCoverageFile (baselineCoverageFile );
250254 BootClassPathInfo bootClassPathInfo = getBootclasspathOrDefault ();
251255 builder .setBootClassPath (bootClassPathInfo );
252256 NestedSet <Artifact > classpath =
@@ -386,7 +390,9 @@ public BootClassPathInfo getBootclasspathOrDefault() throws RuleErrorException {
386390 */
387391 @ Nullable
388392 private Artifact maybeCreateCoverageArtifact (Artifact compileJar ) {
389- if (!shouldInstrumentJar ()) {
393+ // baselineCoverageFile != null is meant to be equivalent to shouldInstrumentJar(), but we need
394+ // to check both to support older versions of rules_java that do not set baseline_coverage_file.
395+ if (!shouldInstrumentJar () && baselineCoverageFile == null ) {
390396 return null ;
391397 }
392398 PathFragment packageRelativePath =
0 commit comments