Skip to content

Commit

Permalink
Stop listing .gcno files as outputs when using LLVM coverage map fo…
Browse files Browse the repository at this point in the history
…rmat

When using `--experimental_use_llvm_covmap`, no `.gcno` files are output. By
listing them as outputs there is a mismatch between expected and actual
outputs. Bazel will create these empty files after the action is run,
but they non-deterministically get counted in the `Action` outputs, which can
lead to cache misses on subsequent runs.

Closes #22132.

PiperOrigin-RevId: 630996820
Change-Id: Ia7de7a05305095c8befee4f86181cf84d9737814
  • Loading branch information
brentleyjones authored and Copybara-Service committed May 6, 2024
1 parent 7637f62 commit a4d77c5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ private Artifact createCompileActionTemplate(
usePic,
/* needsFdoBuildVariables= */ false,
ccCompilationContext.getCppModuleMap(),
/* enableCoverage= */ false,
/* gcnoFile= */ null,
/* isUsingFission= */ false,
/* dwoFile= */ null,
Expand Down Expand Up @@ -1262,6 +1263,7 @@ private CcToolchainVariables setupCompileBuildVariables(
boolean usePic,
boolean needsFdoBuildVariables,
CppModuleMap cppModuleMap,
boolean enableCoverage,
Artifact gcnoFile,
boolean isUsingFission,
Artifact dwoFile,
Expand Down Expand Up @@ -1352,6 +1354,7 @@ private CcToolchainVariables setupCompileBuildVariables(
buildVariables,
toPathString(sourceFile),
toPathString(builder.getOutputFile()),
enableCoverage,
toPathString(gcnoFile),
toPathString(dwoFile),
isUsingFission,
Expand Down Expand Up @@ -1410,7 +1413,7 @@ private void createModuleCodegenAction(
ccToolchain, ArtifactCategory.COVERAGE_DATA_FILE, outputName);
// TODO(djasper): This is now duplicated. Refactor the various create..Action functions.
Artifact gcnoFile =
isCodeCoverageEnabled
isCodeCoverageEnabled && !cppConfiguration.useLLVMCoverageMapFormat()
? CppHelper.getCompileOutputArtifact(
actionConstructionContext, label, gcnoFileName, configuration)
: null;
Expand All @@ -1431,6 +1434,7 @@ private void createModuleCodegenAction(
/* usePic= */ pic,
/* needsFdoBuildVariables= */ ccRelativeName != null,
ccCompilationContext.getCppModuleMap(),
isCodeCoverageEnabled,
gcnoFile,
generateDwo,
dwoFile,
Expand Down Expand Up @@ -1477,6 +1481,7 @@ private void createHeaderAction(
generatePicAction,
/* needsFdoBuildVariables= */ false,
ccCompilationContext.getCppModuleMap(),
/* enableCoverage= */ false,
/* gcnoFile= */ null,
/* isUsingFission= */ false,
/* dwoFile= */ null,
Expand Down Expand Up @@ -1541,7 +1546,7 @@ private ImmutableList<Artifact> createSourceAction(
CppHelper.getArtifactNameForCategory(
ccToolchain, ArtifactCategory.COVERAGE_DATA_FILE, picOutputBase);
Artifact gcnoFile =
enableCoverage
enableCoverage && !cppConfiguration.useLLVMCoverageMapFormat()
? CppHelper.getCompileOutputArtifact(
actionConstructionContext, label, gcnoFileName, configuration)
: null;
Expand All @@ -1557,6 +1562,7 @@ private ImmutableList<Artifact> createSourceAction(
/* usePic= */ true,
/* needsFdoBuildVariables= */ ccRelativeName != null && addObject,
cppModuleMap,
enableCoverage,
gcnoFile,
generateDwo,
dwoFile,
Expand Down Expand Up @@ -1615,7 +1621,7 @@ private ImmutableList<Artifact> createSourceAction(

// Create no-PIC compile actions
Artifact gcnoFile =
enableCoverage
isCodeCoverageEnabled && !cppConfiguration.useLLVMCoverageMapFormat()
? CppHelper.getCompileOutputArtifact(
actionConstructionContext, label, gcnoFileName, configuration)
: null;
Expand All @@ -1630,6 +1636,7 @@ private ImmutableList<Artifact> createSourceAction(
/* usePic= */ false,
/* needsFdoBuildVariables= */ ccRelativeName != null,
cppModuleMap,
isCodeCoverageEnabled,
gcnoFile,
generateDwo,
noPicDwoFile,
Expand Down Expand Up @@ -1796,6 +1803,7 @@ private ImmutableList<Artifact> createTempsActions(
usePic,
/* needsFdoBuildVariables= */ ccRelativeName != null,
ccCompilationContext.getCppModuleMap(),
/* enableCoverage= */ false,
/* gcnoFile= */ null,
/* isUsingFission= */ false,
/* dwoFile= */ null,
Expand All @@ -1821,6 +1829,7 @@ private ImmutableList<Artifact> createTempsActions(
usePic,
/* needsFdoBuildVariables= */ ccRelativeName != null,
ccCompilationContext.getCppModuleMap(),
/* enableCoverage= */ false,
/* gcnoFile= */ null,
/* isUsingFission= */ false,
/* dwoFile= */ null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ public CcToolchainVariables getCompileBuildVariables(
ccToolchainProvider,
convertFromNoneable(sourceFile, /* defaultValue= */ null),
convertFromNoneable(outputFile, /* defaultValue= */ null),
/* isCodeCoverageEnabled= */ false,
/* gcnoFile= */ null,
/* isUsingFission= */ false,
/* dwoFile= */ null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static CcToolchainVariables setupVariablesOrReportRuleError(
CcToolchainProvider ccToolchainProvider,
String sourceFile,
String outputFile,
boolean isCodeCoverageEnabled,
String gcnoFile,
boolean isUsingFission,
String dwoFile,
Expand Down Expand Up @@ -173,6 +174,7 @@ public static CcToolchainVariables setupVariablesOrReportRuleError(
ccToolchainProvider.getBuildVars(),
sourceFile,
outputFile,
isCodeCoverageEnabled,
gcnoFile,
isUsingFission,
dwoFile,
Expand Down Expand Up @@ -204,6 +206,7 @@ public static CcToolchainVariables setupVariablesOrThrowEvalException(
CcToolchainProvider ccToolchainProvider,
String sourceFile,
String outputFile,
boolean isCodeCoverageEnabled,
String gcnoFile,
boolean isUsingFission,
String dwoFile,
Expand Down Expand Up @@ -238,6 +241,7 @@ public static CcToolchainVariables setupVariablesOrThrowEvalException(
ccToolchainProvider.getBuildVars(),
sourceFile,
outputFile,
isCodeCoverageEnabled,
gcnoFile,
isUsingFission,
dwoFile,
Expand Down Expand Up @@ -269,6 +273,7 @@ private static CcToolchainVariables setupVariables(
CcToolchainVariables parent,
String sourceFile,
String outputFile,
boolean isCodeCoverageEnabled,
String gcnoFile,
boolean isUsingFission,
String dwoFile,
Expand Down Expand Up @@ -314,6 +319,7 @@ private static CcToolchainVariables setupVariables(
buildVariables,
sourceFile,
outputFile,
isCodeCoverageEnabled,
gcnoFile,
dwoFile,
isUsingFission,
Expand All @@ -334,6 +340,7 @@ public static void setupSpecificVariables(
CcToolchainVariables.Builder buildVariables,
String sourceFile,
String outputFile,
boolean isCodeCoverageEnabled,
String gcnoFile,
String dwoFile,
boolean isUsingFission,
Expand Down Expand Up @@ -371,6 +378,10 @@ public static void setupSpecificVariables(

if (gcnoFile != null) {
buildVariables.addStringVariable(GCOV_GCNO_FILE.getVariableName(), gcnoFile);
} else if (isCodeCoverageEnabled) {
// TODO: Blaze currently uses `gcov_gcno_file` to detect if code coverage is enabled. It
// should use a different signal.
buildVariables.addStringVariable(GCOV_GCNO_FILE.getVariableName(), "");
}

if (dwoFile != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private static CcToolchainVariables getVariables(
ccToolchainProvider,
sourceFile.getExecPathString(),
outputFile.getExecPathString(),
/* isCodeCoverageEnabled= */ false,
/* gcnoFile= */ null,
/* isUsingFission= */ false,
/* dwoFile= */ null,
Expand Down

0 comments on commit a4d77c5

Please sign in to comment.