aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java54
1 files changed, 15 insertions, 39 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
index e0bb6ce79e..0de1b2d513 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
@@ -417,19 +417,6 @@ public final class Runfiles {
return newManifest;
}
- private static PathFragment getRootRelativePath(Artifact artifact) {
- Preconditions.checkArgument(artifact != null);
- if (artifact.isInMainRepo()) {
- return artifact.getRootRelativePath();
- }
-
- return new PathFragment(Label.EXTERNAL_PATH_PREFIX)
- .getRelative(artifact.isSourceArtifact()
- ? artifact.getRoot().getPath().getBaseName()
- : artifact.getRoot().getExecRoot().getBaseName())
- .getRelative(artifact.getRootRelativePath());
- }
-
/**
* Returns the symlinks as a map from PathFragment to Artifact.
*
@@ -446,7 +433,7 @@ public final class Runfiles {
Map<PathFragment, Artifact> manifest = getSymlinksAsMap(checker);
// Add unconditional artifacts (committed to inclusion on construction of runfiles).
for (Artifact artifact : getUnconditionalArtifactsWithoutMiddlemen()) {
- checker.put(manifest, Runfiles.getRootRelativePath(artifact), artifact);
+ checker.put(manifest, artifact.getRootRelativePath(), artifact);
}
// Add conditional artifacts (only included if they appear in a pruning manifest).
@@ -503,7 +490,7 @@ public final class Runfiles {
// workspace.
private boolean sawWorkspaceName;
- ManifestBuilder(
+ public ManifestBuilder(
PathFragment workspaceName, boolean legacyExternalRunfiles) {
this.manifest = new HashMap<>();
this.workspaceName = workspaceName;
@@ -514,27 +501,19 @@ public final class Runfiles {
/**
* Adds a map under the workspaceName.
*/
- void addUnderWorkspace(
+ public void addUnderWorkspace(
Map<PathFragment, Artifact> inputManifest, ConflictChecker checker) {
for (Map.Entry<PathFragment, Artifact> entry : inputManifest.entrySet()) {
PathFragment path = entry.getKey();
- if (isUnderWorkspace(entry.getValue())) {
- // For empty files (e.g., ../repo/__init__.py), we don't have an artifact so
- // isUnderWorkspace returns true.
- checker.put(manifest, workspaceName.getRelative(path).normalize(), entry.getValue());
+ if (isUnderWorkspace(path)) {
sawWorkspaceName = true;
+ checker.put(manifest, workspaceName.getRelative(path), entry.getValue());
} else {
- PathFragment root = entry.getValue().getRoot().getPath().asFragment();
if (legacyExternalRunfiles) {
- // external/repo
- PathFragment repoDir = root.subFragment(root.segmentCount() - 2, root.segmentCount());
- // Turn ../repo/foo info wsname/external/repo/foo.
- checker.put(
- manifest, workspaceName.getRelative(repoDir).getRelative(path).normalize(),
- entry.getValue());
+ checker.put(manifest, workspaceName.getRelative(path), entry.getValue());
}
- checker.put(
- manifest, workspaceName.getRelative(entry.getKey()).normalize(), entry.getValue());
+ // Always add the non-legacy .runfiles/repo/whatever path.
+ checker.put(manifest, getExternalPath(path), entry.getValue());
}
}
}
@@ -562,20 +541,17 @@ public final class Runfiles {
return manifest;
}
+ private PathFragment getExternalPath(PathFragment path) {
+ return checkForWorkspace(path.relativeTo(Label.EXTERNAL_PACKAGE_NAME));
+ }
+
private PathFragment checkForWorkspace(PathFragment path) {
- sawWorkspaceName = sawWorkspaceName
- || path.getSegment(0).equals(workspaceName.getPathString());
+ sawWorkspaceName = sawWorkspaceName || path.getSegment(0).equals(workspaceName);
return path;
}
- private static boolean isUnderWorkspace(@Nullable Artifact artifact) {
- if (artifact == null) {
- return true;
- }
- PathFragment root = artifact.getRoot().getPath().asFragment();
- return root.segmentCount() < 2
- || !root.getSegment(root.segmentCount() - 2).equals(
- Label.EXTERNAL_PACKAGE_NAME.getPathString());
+ private static boolean isUnderWorkspace(PathFragment path) {
+ return !path.startsWith(Label.EXTERNAL_PACKAGE_NAME);
}
}