diff options
author | 2017-02-16 17:00:53 +0000 | |
---|---|---|
committer | 2017-02-16 17:02:42 +0000 | |
commit | 4b73e972d909bcd533f2f9940f95a00b9b73bdde (patch) | |
tree | 9144d26934aef8e16036d80d249f416bc585bbe4 /src/main/java/com/google/devtools/build/lib/rules/cpp | |
parent | b222872e8d61cbd590bdaeb3cbb1764df70e4270 (diff) |
Roll forward execroot change
RELNOTES[INC]: Previously, an external repository would be symlinked into the
execution root at execroot/local_repo/external/remote_repo. This changes it to
be at execroot/remote_repo. This may break genrules/Skylark actions that
hardcode execution root paths. If this causes breakages for you, ensure that
genrules are using $(location :target) to access files and Skylark rules are
using http://bazel.io/docs/skylark/lib/File.html's path, dirname, etc.
functions. Custom crosstools that hardcode external/<repo> paths will have to
be updated.
Issue #1262.
--
PiperOrigin-RevId: 147726370
MOS_MIGRATED_REVID=147726370
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp')
8 files changed, 44 insertions, 38 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index 597e5dd1a8..e9ef99984f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -414,7 +414,7 @@ public final class CcCommon { List<PathFragment> getSystemIncludeDirs() { List<PathFragment> result = new ArrayList<>(); PackageIdentifier packageIdentifier = ruleContext.getLabel().getPackageIdentifier(); - PathFragment packageFragment = packageIdentifier.getPathUnderExecRoot(); + PathFragment pathUnderExecRoot = packageIdentifier.getPathUnderExecRoot(); for (String includesAttr : ruleContext.attributes().get("includes", Type.STRING_LIST)) { includesAttr = ruleContext.expandMakeVariables("includes", includesAttr); if (includesAttr.startsWith("/")) { @@ -422,10 +422,14 @@ public final class CcCommon { "ignoring invalid absolute path '" + includesAttr + "'"); continue; } - PathFragment includesPath = packageFragment.getRelative(includesAttr).normalize(); - if (!includesPath.isNormalized()) { + PathFragment includesPath = pathUnderExecRoot.getRelative(includesAttr).normalize(); + // It's okay for the includes path to start with ../workspace-name for external repos. + if ((packageIdentifier.getRepository().isMain() && !includesPath.isNormalized()) + || (!packageIdentifier.getRepository().isMain() + && !includesPath.startsWith( + packageIdentifier.getRepository().getPathUnderExecRoot()))) { ruleContext.attributeError("includes", - "Path references a path above the execution root."); + includesAttr + " references a path above the execution root (" + includesPath + ")."); } if (includesPath.segmentCount() == 0) { ruleContext.attributeError( @@ -435,7 +439,7 @@ public final class CcCommon { + "' resolves to the workspace root, which would allow this rule and all of its " + "transitive dependents to include any file in your workspace. Please include only" + " what you need"); - } else if (!includesPath.startsWith(packageFragment)) { + } else if (!includesPath.startsWith(pathUnderExecRoot)) { ruleContext.attributeWarning( "includes", "'" @@ -443,11 +447,14 @@ public final class CcCommon { + "' resolves to '" + includesPath + "' not below the relative path of its package '" - + packageFragment + + pathUnderExecRoot + "'. This will be an error in the future"); } result.add(includesPath); - result.add(ruleContext.getConfiguration().getGenfilesFragment().getRelative(includesPath)); + result.add(packageIdentifier.getRepository().getPathUnderExecRoot() + .getRelative(ruleContext.getConfiguration().getGenfilesFragment()) + .getRelative(packageIdentifier.getPackageFragment()) + .getRelative(includesAttr)); } return result; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java index 11fcd4777a..faed073638 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java @@ -1264,7 +1264,7 @@ public final class CcLibraryHelper { ruleContext.getLabel().getPackageIdentifier().getRepository().getPathUnderExecRoot(); contextBuilder.addQuoteIncludeDir(repositoryPath); contextBuilder.addQuoteIncludeDir( - ruleContext.getConfiguration().getGenfilesFragment().getRelative(repositoryPath)); + repositoryPath.getRelative(ruleContext.getConfiguration().getGenfilesFragment())); for (PathFragment systemIncludeDir : systemIncludeDirs) { contextBuilder.addSystemIncludeDir(systemIncludeDir); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index 6e75edd809..4d3af44879 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -477,13 +477,14 @@ public class CppCompileActionBuilder { continue; } // One starting ../ is okay for getting to a sibling repository. + PathFragment originalInclude = include; if (include.startsWith(new PathFragment(Label.EXTERNAL_PATH_PREFIX))) { include = include.relativeTo(Label.EXTERNAL_PATH_PREFIX); } - if (include.isAbsolute() - || !PathFragment.EMPTY_FRAGMENT.getRelative(include).normalize().isNormalized()) { + if (include.isAbsolute() || !include.normalize().isNormalized()) { ruleContext.ruleError( - "The include path '" + include + "' references a path outside of the execution root."); + "The include path '" + originalInclude + + "' references a path outside of the execution root."); } } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index 9893dfc1e0..c0a7f69c31 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -525,10 +525,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { PathFragment defaultSysroot = toolchain.getBuiltinSysroot().length() == 0 ? null : new PathFragment(toolchain.getBuiltinSysroot()); - if ((defaultSysroot != null) && !defaultSysroot.isNormalized()) { - throw new IllegalArgumentException("The built-in sysroot '" + defaultSysroot - + "' is not normalized."); - } if ((cppOptions.libcTop != null) && (defaultSysroot == null)) { throw new InvalidConfigurationException("The selected toolchain " + toolchainIdentifier @@ -1071,7 +1067,7 @@ public class CppConfiguration extends BuildConfiguration.Fragment { if (packageEndIndex != -1 && s.startsWith(PACKAGE_START)) { String packageString = s.substring(PACKAGE_START.length(), packageEndIndex); try { - pathPrefix = PackageIdentifier.parse(packageString).getSourceRoot(); + pathPrefix = PackageIdentifier.parse(packageString).getPathUnderExecRoot(); } catch (LabelSyntaxException e) { throw new InvalidConfigurationException("The package '" + packageString + "' is not valid"); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 8541778e59..6b3604dd2e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -491,7 +491,7 @@ public class CppHelper { Preconditions.checkState(Link.SHARED_LIBRARY_FILETYPES.matches(artifact.getFilename())); symlinkedArtifacts.add(isCppRuntime ? SolibSymlinkAction.getCppRuntimeSymlink( - ruleContext, artifact, solibDirOverride, configuration) + ruleContext, artifact, solibDirOverride, configuration) : SolibSymlinkAction.getDynamicLibrarySymlink( ruleContext, artifact, false, true, configuration)); } @@ -500,7 +500,8 @@ public class CppHelper { } return ImmutableList.of( factory.createMiddlemanAllowMultiple(ruleContext.getAnalysisEnvironment(), actionOwner, - ruleContext.getPackageDirectory(), purpose, artifacts, + ruleContext.getLabel().getPackageIdentifier().getPathUnderExecRoot(), purpose, + artifacts, configuration.getMiddlemanDirectory(ruleContext.getRule().getRepository()))); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index 2746c64afe..d1fed5de30 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -50,6 +50,7 @@ import com.google.devtools.build.lib.rules.cpp.Link.Staticness; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.vfs.FileSystemUtils; +import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.ArrayList; import java.util.Collection; @@ -1544,8 +1545,9 @@ public class CppLinkActionBuilder { for (LinkerInput input : linkerInputs) { if (input.getArtifactCategory() == ArtifactCategory.DYNAMIC_LIBRARY) { PathFragment libDir = input.getArtifact().getExecPath().getParentDirectory(); + Path rootPath = input.getArtifact().getRoot().getExecRoot(); Preconditions.checkState( - libDir.startsWith(solibDir), + rootPath.getRelative(libDir).startsWith(rootPath.getRelative(solibDir)), "Artifact '%s' is not under directory '%s'.", input.getArtifact(), solibDir); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java index 5b59a0601f..847c1f5d4b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/HeaderDiscovery.java @@ -20,6 +20,7 @@ import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactResolver; +import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -99,10 +100,10 @@ public class HeaderDiscovery { return inputs.build(); } List<Path> systemIncludePrefixes = permittedSystemIncludePrefixes; - // Check inclusions. IncludeProblems problems = new IncludeProblems(); for (Path execPath : depSet.getDependencies()) { + RepositoryName repositoryName = RepositoryName.MAIN; PathFragment execPathFragment = execPath.asFragment(); if (execPathFragment.isAbsolute()) { // Absolute includes from system paths are ignored. @@ -114,15 +115,24 @@ public class HeaderDiscovery { // are, it's probably due to a non-hermetic #include, & we should stop // the build with an error. if (execPath.startsWith(execRoot)) { - execPathFragment = execPath.relativeTo(execRoot); // funky but tolerable path - } else { - problems.add(execPathFragment.getPathString()); - continue; + // Funky but tolerable path. + execPathFragment = execPath.relativeTo(execRoot); + } else if (execPath.startsWith(execRoot.getParentDirectory())) { + // External repository. + execPathFragment = execPath.relativeTo(execRoot.getParentDirectory()); + String workspace = execPathFragment.getSegment(0); + execPathFragment = execPathFragment.relativeTo(workspace); + try { + repositoryName = RepositoryName.create("@" + workspace); + } catch (LabelSyntaxException e) { + throw new IllegalStateException(workspace + " is not a valid repository name"); + } } } - Artifact artifact = allowedDerivedInputsMap.get(execPathFragment); + Artifact artifact = allowedDerivedInputsMap.get( + repositoryName.getPathUnderExecRoot().getRelative(execPathFragment)); if (artifact == null) { - artifact = artifactResolver.resolveSourceArtifact(execPathFragment, RepositoryName.MAIN); + artifact = artifactResolver.resolveSourceArtifact(execPathFragment, repositoryName); } if (artifact != null) { inputs.add(artifact); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java index 8abcaef9d8..fd77e0cda9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java @@ -280,18 +280,7 @@ public class CcProtoAspect extends NativeAspectClass implements ConfiguredAspect } private void createProtoCompileAction(SupportData supportData, Collection<Artifact> outputs) { - String genfilesPath = - ruleContext - .getConfiguration() - .getGenfilesFragment() - .getRelative( - ruleContext - .getLabel() - .getPackageIdentifier() - .getRepository() - .getPathUnderExecRoot()) - .getPathString(); - + String genfilesPath = ruleContext.getBinOrGenfilesDirectory().getExecPathString(); ImmutableList.Builder<ToolchainInvocation> invocations = ImmutableList.builder(); invocations.add( new ToolchainInvocation("C++", checkNotNull(getProtoToolchainProvider()), genfilesPath)); |