Skip to content

Commit

Permalink
Code cleanup: Move decision on whether or not to generate a .d file i…
Browse files Browse the repository at this point in the history
…nto a

single location. No functional changes intended.

RELNOTES: None.
PiperOrigin-RevId: 332911614
  • Loading branch information
djasper authored and copybara-github committed Sep 21, 2020
1 parent 36ee499 commit ecab72e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,7 @@ private CcCompilationOutputs createCcCompileActions(Consumer<String> errorReport
if (!sourceArtifact.isTreeArtifact()) {
switch (source.getType()) {
case HEADER:
createHeaderAction(
sourceLabel, outputName, result, builder, isGenerateDotdFile(sourceArtifact));
createHeaderAction(sourceLabel, outputName, result, builder);
break;
default:
createSourceAction(
Expand All @@ -1372,8 +1371,7 @@ private CcCompilationOutputs createCcCompileActions(Consumer<String> errorReport
// output (since it isn't generating a native object with debug
// info). In that case the LtoBackendAction will generate the dwo.
ccToolchain.shouldCreatePerObjectDebugInfo(featureConfiguration, cppConfiguration),
bitcodeOutput,
isGenerateDotdFile(sourceArtifact));
bitcodeOutput);
break;
}
} else {
Expand Down Expand Up @@ -1649,8 +1647,7 @@ private void createModuleCodegenAction(
ruleErrorConsumer,
label,
ArtifactCategory.OBJECT_FILE,
outputName,
isGenerateDotdFile(module));
outputName);
PathFragment ccRelativeName = module.getRootRelativePath();

String gcnoFileName =
Expand Down Expand Up @@ -1700,18 +1697,11 @@ private void createModuleCodegenAction(
}
}

/** Returns true if Dotd file should be generated. */
private boolean isGenerateDotdFile(Artifact sourceArtifact) {
return CppFileTypes.headerDiscoveryRequired(sourceArtifact)
&& !featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES);
}

private void createHeaderAction(
Label sourceLabel,
String outputName,
CcCompilationOutputs.Builder result,
CppCompileActionBuilder builder,
boolean generateDotd)
CppCompileActionBuilder builder)
throws RuleErrorException {
String outputNameBase =
CppHelper.getArtifactNameForCategory(
Expand All @@ -1723,8 +1713,7 @@ private void createHeaderAction(
ruleErrorConsumer,
label,
ArtifactCategory.PROCESSED_HEADER,
outputNameBase,
generateDotd)
outputNameBase)
// If we generate pic actions, we prefer the header actions to use the pic artifacts.
.setPicMode(generatePicAction);
builder.setVariables(
Expand Down Expand Up @@ -1768,8 +1757,7 @@ private Collection<Artifact> createModuleAction(
/* addObject= */ false,
/* enableCoverage= */ false,
/* generateDwo= */ false,
/* bitcodeOutput= */ false,
isGenerateDotdFile(moduleMapArtifact));
/* bitcodeOutput= */ false);
}

private Collection<Artifact> createSourceAction(
Expand All @@ -1783,8 +1771,7 @@ private Collection<Artifact> createSourceAction(
boolean addObject,
boolean enableCoverage,
boolean generateDwo,
boolean bitcodeOutput,
boolean generateDotd)
boolean bitcodeOutput)
throws RuleErrorException {
ImmutableList.Builder<Artifact> directOutputs = new ImmutableList.Builder<>();
PathFragment ccRelativeName = sourceArtifact.getRootRelativePath();
Expand All @@ -1795,8 +1782,7 @@ private Collection<Artifact> createSourceAction(
String picOutputBase =
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, ArtifactCategory.PIC_FILE, outputName);
CppCompileActionBuilder picBuilder =
copyAsPicBuilder(builder, picOutputBase, outputCategory, generateDotd);
CppCompileActionBuilder picBuilder = copyAsPicBuilder(builder, picOutputBase, outputCategory);
String gcnoFileName =
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, ArtifactCategory.COVERAGE_DATA_FILE, picOutputBase);
Expand Down Expand Up @@ -1830,7 +1816,6 @@ private Collection<Artifact> createSourceAction(
outputName,
picBuilder,
/* usePic= */ true,
/* generateDotd= */ generateDotd,
ccRelativeName));

picBuilder.setGcnoFile(gcnoFile);
Expand Down Expand Up @@ -1865,12 +1850,7 @@ private Collection<Artifact> createSourceAction(
ruleErrorConsumer, ccToolchain, outputCategory, outputName),
configuration);
builder.setOutputs(
actionConstructionContext,
ruleErrorConsumer,
label,
outputCategory,
outputName,
generateDotd);
actionConstructionContext, ruleErrorConsumer, label, outputCategory, outputName);
String gcnoFileName =
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, ArtifactCategory.COVERAGE_DATA_FILE, outputName);
Expand Down Expand Up @@ -1905,7 +1885,6 @@ private Collection<Artifact> createSourceAction(
outputName,
builder,
/* usePic= */ false,
generateDotd,
ccRelativeName));

builder.setGcnoFile(gcnoFile);
Expand Down Expand Up @@ -1938,21 +1917,13 @@ private Collection<Artifact> createSourceAction(
* changing output and dotd file names.
*/
private CppCompileActionBuilder copyAsPicBuilder(
CppCompileActionBuilder builder,
String outputName,
ArtifactCategory outputCategory,
boolean generateDotd)
CppCompileActionBuilder builder, String outputName, ArtifactCategory outputCategory)
throws RuleErrorException {
CppCompileActionBuilder picBuilder = new CppCompileActionBuilder(builder);
picBuilder
.setPicMode(true)
.setOutputs(
actionConstructionContext,
ruleErrorConsumer,
label,
outputCategory,
outputName,
generateDotd);
actionConstructionContext, ruleErrorConsumer, label, outputCategory, outputName);

return picBuilder;
}
Expand Down Expand Up @@ -2029,7 +2000,6 @@ private ImmutableList<Artifact> createTempsActions(
String outputName,
CppCompileActionBuilder builder,
boolean usePic,
boolean generateDotd,
PathFragment ccRelativeName)
throws RuleErrorException {
if (!cppConfiguration.getSaveTemps()) {
Expand All @@ -2051,12 +2021,7 @@ private ImmutableList<Artifact> createTempsActions(

CppCompileActionBuilder dBuilder = new CppCompileActionBuilder(builder);
dBuilder.setOutputs(
actionConstructionContext,
ruleErrorConsumer,
label,
category,
outputArtifactNameBase,
generateDotd);
actionConstructionContext, ruleErrorConsumer, label, category, outputArtifactNameBase);
dBuilder.setVariables(
setupCompileBuildVariables(
dBuilder,
Expand All @@ -2082,8 +2047,7 @@ private ImmutableList<Artifact> createTempsActions(
ruleErrorConsumer,
label,
ArtifactCategory.GENERATED_ASSEMBLY,
outputArtifactNameBase,
generateDotd);
outputArtifactNameBase);
sdBuilder.setVariables(
setupCompileBuildVariables(
sdBuilder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ public CppCompileActionBuilder setOutputs(
RuleErrorConsumer ruleErrorConsumer,
Label label,
ArtifactCategory outputCategory,
String outputName,
boolean generateDotd)
String outputName)
throws RuleErrorException {
this.outputFile =
CppHelper.getCompileOutputArtifact(
Expand All @@ -441,7 +440,9 @@ public CppCompileActionBuilder setOutputs(
CppHelper.getArtifactNameForCategory(
ruleErrorConsumer, ccToolchain, outputCategory, outputName),
configuration);
if (generateDotd && !useHeaderModules()) {
if (CppFileTypes.headerDiscoveryRequired(sourceFile)
&& !useHeaderModules()
&& !featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES)) {
String dotdFileName =
CppHelper.getDotdFileName(ruleErrorConsumer, ccToolchain, outputCategory, outputName);
dotdFile =
Expand Down

0 comments on commit ecab72e

Please sign in to comment.