aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/actions
diff options
context:
space:
mode:
authorGravatar Philipp Wollermann <philwo@google.com>2015-10-22 13:12:58 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-10-22 15:17:31 +0000
commitd262fa501bcd6fff6de9e3fa3d71ae58a1daad27 (patch)
tree26d2a31532b81f60b9a72987d77a0d92b95d4a02 /src/main/java/com/google/devtools/build/lib/actions
parentc708f96b4d23a1b6b03bed50013dd437ff40e92d (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/build/lib/actions')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java34
1 files changed, 27 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;
}