Skip to content

Commit

Permalink
Make FdoSupport use outputName to generate object file path
Browse files Browse the repository at this point in the history
Object file path will no longer be derived from source file path directly.
This is a preparation change for[]

Related issue bazelbuild#4149

RELNOTES: None
PiperOrigin-RevId: 189572213
Change-Id: Iae7ee48e5f1f5500ae03999618598eb9475eaed8
  • Loading branch information
meteorcloudy committed Mar 20, 2018
1 parent 755a0a1 commit 030efad
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ private Artifact createCompileActionTemplate(
source.getLabel(),
usePic,
/* ccRelativeName= */ null,
/* outputName= */ null,
/* autoFdoImportPath= */ null,
/* gcnoFile= */ null,
/* dwoFile= */ null,
Expand All @@ -1475,6 +1476,7 @@ private void setupCompileBuildVariables(
Label sourceLabel,
boolean usePic,
PathFragment ccRelativeName,
String outputName,
PathFragment autoFdoImportPath,
Artifact gcnoFile,
Artifact dwoFile,
Expand Down Expand Up @@ -1601,6 +1603,7 @@ private void setupCompileBuildVariables(
ruleContext,
ccRelativeName,
autoFdoImportPath,
PathFragment.create(outputName),
usePic,
featureConfiguration,
fdoSupport);
Expand Down Expand Up @@ -1696,6 +1699,7 @@ private void createModuleCodegenAction(
sourceLabel,
/* usePic= */ pic,
ccRelativeName,
outputName,
module.getExecPath(),
gcnoFile,
dwoFile,
Expand Down Expand Up @@ -1744,6 +1748,7 @@ private void createHeaderAction(
sourceLabel,
this.getGeneratePicActions(),
/* ccRelativeName= */ null,
/* outputName= */ null,
/* autoFdoImportPath= */ null,
/* gcnoFile= */ null,
/* dwoFile= */ null,
Expand Down Expand Up @@ -1853,6 +1858,7 @@ private Collection<Artifact> createSourceAction(
sourceLabel,
/* usePic= */ true,
ccRelativeName,
outputName,
sourceArtifact.getExecPath(),
gcnoFile,
dwoFile,
Expand Down Expand Up @@ -1920,6 +1926,7 @@ private Collection<Artifact> createSourceAction(
sourceLabel,
/* usePic= */ false,
ccRelativeName,
outputName,
sourceArtifact.getExecPath(),
gcnoFile,
noPicDwoFile,
Expand Down Expand Up @@ -2022,6 +2029,7 @@ private void createFakeSourceAction(
sourceLabel,
usePic,
ccRelativeName,
outputName,
execPath,
/* gcnoFile= */ null,
/* dwoFile= */ null,
Expand Down Expand Up @@ -2136,6 +2144,7 @@ private ImmutableList<Artifact> createTempsActions(
sourceLabel,
usePic,
ccRelativeName,
outputName,
source.getExecPath(),
/* gcnoFile= */ null,
/* dwoFile= */ null,
Expand All @@ -2153,6 +2162,7 @@ private ImmutableList<Artifact> createTempsActions(
sourceLabel,
usePic,
ccRelativeName,
outputName,
source.getExecPath(),
/* gcnoFile= */ null,
/* dwoFile= */ null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,20 @@ private Iterable<PathFragment> getImports(PathFragment objDirectory, PathFragmen
}

/**
* Configures a compile action builder by setting up command line options and
* auxiliary inputs according to the FDO configuration. This method does
* nothing If FDO is disabled.
* Configures a compile action builder by setting up command line options and auxiliary inputs
* according to the FDO configuration. This method does nothing If FDO is disabled.
*/
@ThreadSafe
public void configureCompilation(CppCompileActionBuilder builder,
CcToolchainFeatures.Variables.Builder buildVariables, RuleContext ruleContext,
PathFragment sourceName, PathFragment sourceExecPath, boolean usePic,
FeatureConfiguration featureConfiguration, FdoSupportProvider fdoSupportProvider) {
public void configureCompilation(
CppCompileActionBuilder builder,
CcToolchainFeatures.Variables.Builder buildVariables,
RuleContext ruleContext,
PathFragment sourceName,
PathFragment sourceExecPath,
PathFragment outputName,
boolean usePic,
FeatureConfiguration featureConfiguration,
FdoSupportProvider fdoSupportProvider) {

// FDO is disabled -> do nothing.
if ((fdoInstrument == null) && (fdoRoot == null)) {
Expand All @@ -616,8 +621,9 @@ public void configureCompilation(CppCompileActionBuilder builder,
if (env.getSkyframeEnv().valuesMissing()) {
return;
}
Iterable<Artifact> auxiliaryInputs = getAuxiliaryInputs(
ruleContext, sourceName, sourceExecPath, usePic, fdoSupportProvider);
Iterable<Artifact> auxiliaryInputs =
getAuxiliaryInputs(
ruleContext, sourceName, sourceExecPath, outputName, usePic, fdoSupportProvider);
builder.addMandatoryInputs(auxiliaryInputs);
if (!Iterables.isEmpty(auxiliaryInputs)) {
if (featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
Expand All @@ -636,11 +642,13 @@ public void configureCompilation(CppCompileActionBuilder builder,
}
}

/**
* Returns the auxiliary files that need to be added to the {@link CppCompileAction}.
*/
/** Returns the auxiliary files that need to be added to the {@link CppCompileAction}. */
private Iterable<Artifact> getAuxiliaryInputs(
RuleContext ruleContext, PathFragment sourceName, PathFragment sourceExecPath, boolean usePic,
RuleContext ruleContext,
PathFragment sourceName,
PathFragment sourceExecPath,
PathFragment outputName,
boolean usePic,
FdoSupportProvider fdoSupportProvider) {
CcToolchainProvider toolchain =
CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext);
Expand All @@ -661,7 +669,7 @@ private Iterable<Artifact> getAuxiliaryInputs(
ImmutableSet.Builder<Artifact> auxiliaryInputs = ImmutableSet.builder();

PathFragment objectName =
FileSystemUtils.replaceExtension(sourceName, usePic ? ".pic.o" : ".o");
FileSystemUtils.appendExtension(outputName, usePic ? ".pic.o" : ".o");

Label lipoLabel = ruleContext.getLabel();
auxiliaryInputs.addAll(
Expand Down

0 comments on commit 030efad

Please sign in to comment.