diff options
author | 2015-10-22 13:12:58 +0000 | |
---|---|---|
committer | 2015-10-22 15:17:31 +0000 | |
commit | d262fa501bcd6fff6de9e3fa3d71ae58a1daad27 (patch) | |
tree | 26d2a31532b81f60b9a72987d77a0d92b95d4a02 /src/main/java/com/google/devtools | |
parent | c708f96b4d23a1b6b03bed50013dd437ff40e92d (diff) |
ArtifactFactory.findSourceRoot now handles the case where an execPath refers to a remote repository.
--
MOS_MIGRATED_REVID=106051348
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java | 34 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java | 7 |
2 files changed, 34 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java index c4fae04531..67b210e8ca 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java @@ -21,7 +21,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Lists; import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType; +import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.PackageIdentifier; +import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; @@ -318,20 +320,38 @@ public class ArtifactFactory implements ArtifactResolver, ArtifactSerializer, Ar return createArtifactIfNotValid(findSourceRoot(execPath, baseExecPath, baseRoot), execPath); } + /** + * Probe the known packages to find the longest package prefix up until the base, or until the + * root directory if our execPath doesn't start with baseExecPath due to uplevel references. + */ @Nullable private Root findSourceRoot( PathFragment execPath, @Nullable PathFragment baseExecPath, @Nullable Root baseRoot) { - // Probe the known packages to find the longest package prefix up until the base, or until the - // root directory if our execPath doesn't start with baseExecPath due to uplevel references. - PathFragment dir; - for (dir = execPath.getParentDirectory(); - dir != null && !dir.equals(baseExecPath); - dir = dir.getParentDirectory()) { - Root sourceRoot = packageRoots.get(PackageIdentifier.createInDefaultRepo(dir)); + PathFragment dir = execPath.getParentDirectory(); + if (dir == null) { + return null; + } + + // This obviously only works when a repository name does not contain a slash. However, this is + // fine, because LocalRepositoryFunction checks that the name doesn't contain one. + RepositoryName repoName = PackageIdentifier.DEFAULT_REPOSITORY_NAME; + if (dir.segmentCount() >= 2 && dir.getSegment(0).equals("external")) { + try { + repoName = RepositoryName.create("@" + dir.getSegment(1)); + } catch (LabelSyntaxException e) { + return null; + } + dir = dir.subFragment(2, dir.segmentCount()); + } + + while (dir != null && !dir.equals(baseExecPath)) { + Root sourceRoot = packageRoots.get(PackageIdentifier.create(repoName, dir)); if (sourceRoot != null) { return sourceRoot; } + dir = dir.getParentDirectory(); } + return dir != null && dir.equals(baseExecPath) ? baseRoot : null; } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java index fe62852c34..c5b6e3cae4 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalRepositoryFunction.java @@ -48,6 +48,13 @@ public class LocalRepositoryFunction extends RepositoryFunction { return null; } + if (rule.getName().contains("/")) { + throw new RepositoryFunctionException( + new EvalException( + rule.getLocation(), "In " + rule + " the 'name' attribute must not contain slashes"), + Transience.PERSISTENT); + } + AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule); String path = mapper.get("path", Type.STRING); PathFragment pathFragment = new PathFragment(path); |