Skip to content

Commit 191add5

Browse files
meteorcloudyCopybara-Service
authored andcommitted
Make FdoSupport use outputName to generate object file path
Object file path will no longer be derived from source file path directly. This is a preparation change for[] Related issue #4149 RELNOTES: None PiperOrigin-RevId: 189722421
1 parent 755a0a1 commit 191add5

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,7 @@ private Artifact createCompileActionTemplate(
14501450
source.getLabel(),
14511451
usePic,
14521452
/* ccRelativeName= */ null,
1453+
/* outputName= */ null,
14531454
/* autoFdoImportPath= */ null,
14541455
/* gcnoFile= */ null,
14551456
/* dwoFile= */ null,
@@ -1475,6 +1476,7 @@ private void setupCompileBuildVariables(
14751476
Label sourceLabel,
14761477
boolean usePic,
14771478
PathFragment ccRelativeName,
1479+
String outputName,
14781480
PathFragment autoFdoImportPath,
14791481
Artifact gcnoFile,
14801482
Artifact dwoFile,
@@ -1601,6 +1603,7 @@ private void setupCompileBuildVariables(
16011603
ruleContext,
16021604
ccRelativeName,
16031605
autoFdoImportPath,
1606+
PathFragment.create(outputName),
16041607
usePic,
16051608
featureConfiguration,
16061609
fdoSupport);
@@ -1696,6 +1699,7 @@ private void createModuleCodegenAction(
16961699
sourceLabel,
16971700
/* usePic= */ pic,
16981701
ccRelativeName,
1702+
outputName,
16991703
module.getExecPath(),
17001704
gcnoFile,
17011705
dwoFile,
@@ -1744,6 +1748,7 @@ private void createHeaderAction(
17441748
sourceLabel,
17451749
this.getGeneratePicActions(),
17461750
/* ccRelativeName= */ null,
1751+
/* outputName= */ null,
17471752
/* autoFdoImportPath= */ null,
17481753
/* gcnoFile= */ null,
17491754
/* dwoFile= */ null,
@@ -1853,6 +1858,7 @@ private Collection<Artifact> createSourceAction(
18531858
sourceLabel,
18541859
/* usePic= */ true,
18551860
ccRelativeName,
1861+
outputName,
18561862
sourceArtifact.getExecPath(),
18571863
gcnoFile,
18581864
dwoFile,
@@ -1920,6 +1926,7 @@ private Collection<Artifact> createSourceAction(
19201926
sourceLabel,
19211927
/* usePic= */ false,
19221928
ccRelativeName,
1929+
outputName,
19231930
sourceArtifact.getExecPath(),
19241931
gcnoFile,
19251932
noPicDwoFile,
@@ -2022,6 +2029,7 @@ private void createFakeSourceAction(
20222029
sourceLabel,
20232030
usePic,
20242031
ccRelativeName,
2032+
outputName,
20252033
execPath,
20262034
/* gcnoFile= */ null,
20272035
/* dwoFile= */ null,
@@ -2136,6 +2144,7 @@ private ImmutableList<Artifact> createTempsActions(
21362144
sourceLabel,
21372145
usePic,
21382146
ccRelativeName,
2147+
outputName,
21392148
source.getExecPath(),
21402149
/* gcnoFile= */ null,
21412150
/* dwoFile= */ null,
@@ -2153,6 +2162,7 @@ private ImmutableList<Artifact> createTempsActions(
21532162
sourceLabel,
21542163
usePic,
21552164
ccRelativeName,
2165+
outputName,
21562166
source.getExecPath(),
21572167
/* gcnoFile= */ null,
21582168
/* dwoFile= */ null,

src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,20 @@ private Iterable<PathFragment> getImports(PathFragment objDirectory, PathFragmen
590590
}
591591

592592
/**
593-
* Configures a compile action builder by setting up command line options and
594-
* auxiliary inputs according to the FDO configuration. This method does
595-
* nothing If FDO is disabled.
593+
* Configures a compile action builder by setting up command line options and auxiliary inputs
594+
* according to the FDO configuration. This method does nothing If FDO is disabled.
596595
*/
597596
@ThreadSafe
598-
public void configureCompilation(CppCompileActionBuilder builder,
599-
CcToolchainFeatures.Variables.Builder buildVariables, RuleContext ruleContext,
600-
PathFragment sourceName, PathFragment sourceExecPath, boolean usePic,
601-
FeatureConfiguration featureConfiguration, FdoSupportProvider fdoSupportProvider) {
597+
public void configureCompilation(
598+
CppCompileActionBuilder builder,
599+
CcToolchainFeatures.Variables.Builder buildVariables,
600+
RuleContext ruleContext,
601+
PathFragment sourceName,
602+
PathFragment sourceExecPath,
603+
PathFragment outputName,
604+
boolean usePic,
605+
FeatureConfiguration featureConfiguration,
606+
FdoSupportProvider fdoSupportProvider) {
602607

603608
// FDO is disabled -> do nothing.
604609
if ((fdoInstrument == null) && (fdoRoot == null)) {
@@ -616,8 +621,9 @@ public void configureCompilation(CppCompileActionBuilder builder,
616621
if (env.getSkyframeEnv().valuesMissing()) {
617622
return;
618623
}
619-
Iterable<Artifact> auxiliaryInputs = getAuxiliaryInputs(
620-
ruleContext, sourceName, sourceExecPath, usePic, fdoSupportProvider);
624+
Iterable<Artifact> auxiliaryInputs =
625+
getAuxiliaryInputs(
626+
ruleContext, sourceName, sourceExecPath, outputName, usePic, fdoSupportProvider);
621627
builder.addMandatoryInputs(auxiliaryInputs);
622628
if (!Iterables.isEmpty(auxiliaryInputs)) {
623629
if (featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
@@ -636,11 +642,13 @@ public void configureCompilation(CppCompileActionBuilder builder,
636642
}
637643
}
638644

639-
/**
640-
* Returns the auxiliary files that need to be added to the {@link CppCompileAction}.
641-
*/
645+
/** Returns the auxiliary files that need to be added to the {@link CppCompileAction}. */
642646
private Iterable<Artifact> getAuxiliaryInputs(
643-
RuleContext ruleContext, PathFragment sourceName, PathFragment sourceExecPath, boolean usePic,
647+
RuleContext ruleContext,
648+
PathFragment sourceName,
649+
PathFragment sourceExecPath,
650+
PathFragment outputName,
651+
boolean usePic,
644652
FdoSupportProvider fdoSupportProvider) {
645653
CcToolchainProvider toolchain =
646654
CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext);
@@ -661,7 +669,7 @@ private Iterable<Artifact> getAuxiliaryInputs(
661669
ImmutableSet.Builder<Artifact> auxiliaryInputs = ImmutableSet.builder();
662670

663671
PathFragment objectName =
664-
FileSystemUtils.replaceExtension(sourceName, usePic ? ".pic.o" : ".o");
672+
FileSystemUtils.appendExtension(outputName, usePic ? ".pic.o" : ".o");
665673

666674
Label lipoLabel = ruleContext.getLabel();
667675
auxiliaryInputs.addAll(

0 commit comments

Comments
 (0)