aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2016-02-09 12:52:48 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-02-10 10:22:19 +0000
commit2a7c9b821e625ec0ea44120787ba38097d8dabec (patch)
tree1f3a05a087260b037d4fa81c428774bd876b1d17 /src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
parent2b37dffcf30c985485ae323accc1c238ffc5ef5d (diff)
Remove the genfilesPath parameter from FdoSupport.prepareToBuild.
This makes the fdo support independent of the configuration, and therefore safe to cache. The genfilesPath was only used in AutoFDO builds, which now use the full exec path to look up profiling data. The profile already refers to imported files through their full exec paths, so this approach is more consistent. Furthermore, if we ever have a source file with the same root-relative path as a generated file, these would conflict in the FdoSupport map, potentially leading to errors in the build. This may not be possible right now since such files would conflict in the label namespace and such conflicts are always resolved towards the generated file. -- MOS_MIGRATED_REVID=114204994
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
index 73c0544173..f07f7eb38f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
@@ -269,9 +269,9 @@ public class FdoSupport {
* @throws PackageRootResolutionException
*/
@ThreadHostile // must be called before starting the build
- public void prepareToBuild(Path execRoot, PathFragment genfilesPath,
- ArtifactFactory artifactDeserializer, PackageRootResolver resolver)
- throws IOException, FdoException, PackageRootResolutionException {
+ public void prepareToBuild(Path execRoot, ArtifactFactory artifactDeserializer,
+ PackageRootResolver resolver)
+ throws IOException, FdoException, PackageRootResolutionException {
// The execRoot != null case is only there for testing. We cannot provide a real ZIP file in
// tests because ZipFileSystem does not work with a ZIP on an in-memory file system.
// IMPORTANT: Keep in sync with #declareSkyframeDependencies to avoid incrementality issues.
@@ -285,7 +285,7 @@ public class FdoSupport {
Path fdoImports = fdoProfile.getParentDirectory().getRelative(
fdoProfile.getBaseName() + ".imports");
if (isLipoEnabled()) {
- imports = readAutoFdoImports(artifactDeserializer, fdoImports, genfilesPath, resolver);
+ imports = readAutoFdoImports(artifactDeserializer, fdoImports, resolver);
}
FileSystemUtils.ensureSymbolicLink(
execRoot.getRelative(getAutoProfilePath()), fdoProfile);
@@ -392,21 +392,16 @@ public class FdoSupport {
* @throws PackageRootResolutionException
*/
private ImmutableMultimap<PathFragment, Artifact> readAutoFdoImports(
- ArtifactFactory artifactFactory, Path importsFile, PathFragment genFilePath,
- PackageRootResolver resolver)
+ ArtifactFactory artifactFactory, Path importsFile, PackageRootResolver resolver)
throws IOException, FdoException, PackageRootResolutionException {
ImmutableMultimap.Builder<PathFragment, Artifact> importBuilder = ImmutableMultimap.builder();
for (String line : FileSystemUtils.iterateLinesAsLatin1(importsFile)) {
if (!line.isEmpty()) {
PathFragment key = new PathFragment(line.substring(0, line.indexOf(':')));
- if (key.startsWith(genFilePath)) {
- key = key.relativeTo(genFilePath);
- }
if (key.isAbsolute()) {
throw new FdoException("Absolute paths not allowed in afdo imports file " + importsFile
+ ": " + key);
}
- key = FileSystemUtils.replaceSegments(key, "PROTECTED", "_protected", true);
for (String auxFile : line.substring(line.indexOf(':') + 1).split(" ")) {
if (auxFile.length() == 0) {
continue;
@@ -426,13 +421,13 @@ public class FdoSupport {
/**
* Returns the imports from the .afdo.imports file of a source file.
*
- * @param sourceName the source file
+ * @param sourceExecPath the source file
*/
- private Collection<Artifact> getAutoFdoImports(PathFragment sourceName) {
+ private Collection<Artifact> getAutoFdoImports(PathFragment sourceExecPath) {
Preconditions.checkState(isLipoEnabled());
- ImmutableCollection<Artifact> afdoImports = imports.get(sourceName);
+ ImmutableCollection<Artifact> afdoImports = imports.get(sourceExecPath);
Preconditions.checkState(afdoImports != null,
- "AutoFDO import data missing for %s", sourceName);
+ "AutoFDO import data missing for %s", sourceExecPath);
return afdoImports;
}
@@ -460,7 +455,8 @@ public class FdoSupport {
@ThreadSafe
public void configureCompilation(CppCompileActionBuilder builder,
CcToolchainFeatures.Variables.Builder buildVariables, RuleContext ruleContext,
- PathFragment sourceName, boolean usePic, FeatureConfiguration featureConfiguration) {
+ PathFragment sourceName, PathFragment sourceExecPath, boolean usePic,
+ FeatureConfiguration featureConfiguration) {
// It is a bug if this method is called with useLipo if lipo is disabled. However, it is legal
// if is is called with !useLipo, even though lipo is enabled.
LipoContextProvider lipoInputProvider = CppHelper.getLipoContextProvider(ruleContext);
@@ -484,7 +480,7 @@ public class FdoSupport {
return;
}
Iterable<Artifact> auxiliaryInputs = getAuxiliaryInputs(
- ruleContext, env, sourceName, usePic, lipoInputProvider);
+ ruleContext, env, sourceName, sourceExecPath, usePic, lipoInputProvider);
builder.addMandatoryInputs(auxiliaryInputs);
if (!Iterables.isEmpty(auxiliaryInputs)) {
if (featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
@@ -509,7 +505,7 @@ public class FdoSupport {
*/
private Iterable<Artifact> getAuxiliaryInputs(
RuleContext ruleContext, AnalysisEnvironment env, PathFragment sourceName,
- boolean usePic, LipoContextProvider lipoContextProvider) {
+ PathFragment sourceExecPath, boolean usePic, LipoContextProvider lipoContextProvider) {
// If --fdo_optimize was not specified, we don't have any additional inputs.
if (fdoProfile == null) {
return ImmutableSet.of();
@@ -524,7 +520,7 @@ public class FdoSupport {
env.registerAction(new FdoStubAction(ruleContext.getActionOwner(), artifact));
auxiliaryInputs.add(artifact);
if (lipoContextProvider != null) {
- auxiliaryInputs.addAll(getAutoFdoImports(sourceName));
+ auxiliaryInputs.addAll(getAutoFdoImports(sourceExecPath));
}
return auxiliaryInputs.build();
} else {