aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2015-08-07 22:41:45 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2015-08-10 10:09:45 +0000
commit4d9def6cdea94c1d68319e2bd1e45b26b8796431 (patch)
treef8231ab82ebae2dc47590936c3f9f6a18ff6f274 /src
parent3f53fbb930a59f37d83d283ebd1cfca8384b0f38 (diff)
Don't assume that relative inclusion is under same package root as the original artifact.
This adds artifact resolution costs to relative inclusions, but hopefully not too much. -- MOS_MIGRATED_REVID=100164755
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java44
1 files changed, 33 insertions, 11 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 487de35735..30ead6e517 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
@@ -283,35 +283,57 @@ public class ArtifactFactory implements ArtifactResolver, ArtifactSerializer, Ar
}
}
- @Override
- public synchronized Artifact resolveSourceArtifact(PathFragment execPath) {
+ /**
+ * Returns an {@link Artifact} with exec path formed by composing {@param baseExecPath} and
+ * {@param relativePath} (via {@code baseExecPath.getRelative(relativePath)} if baseExecPath is
+ * not null). That Artifact will have root determined by the package roots of this factory if it
+ * lives in a subpackage distinct from that of baseExecPath, and {@param baseRoot} otherwise.
+ */
+ public synchronized Artifact resolveSourceArtifactWithAncestor(
+ PathFragment relativePath, PathFragment baseExecPath, Root baseRoot) {
+ Preconditions.checkState(
+ (baseExecPath == null) == (baseRoot == null),
+ "%s %s %s",
+ relativePath,
+ baseExecPath,
+ baseRoot);
+ PathFragment execPath =
+ baseExecPath == null ? relativePath : baseExecPath.getRelative(relativePath);
execPath = execPath.normalize();
- Artifact artifact = sourceArtifactCache.getArtifactIfValid(execPath);
- if (artifact != null) {
- return artifact;
- }
if (execPath.containsUplevelReferences()) {
// Source exec paths cannot escape the source root.
return null;
}
+ Artifact artifact = sourceArtifactCache.getArtifactIfValid(execPath);
+ if (artifact != null) {
+ return artifact;
+ }
// Don't create an artifact if it's derived.
if (findDerivedRoot(execRoot.getRelative(execPath)) != null) {
return null;
}
- return createArtifactIfNotValid(findSourceRoot(execPath), execPath);
+ return createArtifactIfNotValid(findSourceRoot(execPath, baseExecPath, baseRoot), execPath);
}
- private Root findSourceRoot(PathFragment execPath) {
- // Probe the known packages to find the longest package prefix.
- for (PathFragment dir = execPath.getParentDirectory(); dir != null;
+ @Nullable
+ private Root findSourceRoot(
+ PathFragment execPath, PathFragment baseExecPath, @Nullable Root baseRoot) {
+ // Probe the known packages to find the longest package prefix up until the base.
+ for (PathFragment dir = execPath.getParentDirectory();
+ !Objects.equals(dir, baseExecPath);
dir = dir.getParentDirectory()) {
Root sourceRoot = packageRoots.get(PackageIdentifier.createInDefaultRepo(dir));
if (sourceRoot != null) {
return sourceRoot;
}
}
- return null;
+ return baseRoot;
+ }
+
+ @Override
+ public Artifact resolveSourceArtifact(PathFragment execPath) {
+ return resolveSourceArtifactWithAncestor(execPath, null, null);
}
@Override