Improve error message slightly
PiperOrigin-RevId: 199118944
diff --git a/src/main/java/com/google/devtools/build/lib/exec/FilesetManifest.java b/src/main/java/com/google/devtools/build/lib/exec/FilesetManifest.java
index 05dee2b..c48674a 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/FilesetManifest.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/FilesetManifest.java
@@ -93,7 +93,10 @@
private int lineNum;
private final LinkedHashMap<PathFragment, String> entries = new LinkedHashMap<>();
- private final Map<PathFragment, String> relativeLinks = new HashMap<>();
+ // Resolution order of relative links can affect the outcome of the resolution. In particular,
+ // if there's a symlink to a symlink, then resolution fails if the first symlink is resolved
+ // first, but works if the second symlink is resolved first.
+ private final LinkedHashMap<PathFragment, String> relativeLinks = new LinkedHashMap<>();
ManifestLineProcessor(
String workspaceName,
@@ -178,12 +181,17 @@
String value = e.getValue();
PathFragment actualLocation = location.getParentDirectory().getRelative(value);
String actual = entries.get(actualLocation);
- boolean isActualAcceptable = actual == null || actual.startsWith("/");
- if (!entries.containsKey(actualLocation) || !isActualAcceptable) {
+ if (actual == null) {
throw new IllegalStateException(
String.format(
- "runfiles target '%s' is not absolute, and could not be resolved in the same "
- + "Fileset",
+ "runfiles target '%s' is a relative symlink, and could not be resolved within the "
+ + "same Fileset",
+ value));
+ }
+ if (!actual.startsWith("/")) {
+ throw new IllegalStateException(
+ String.format(
+ "runfiles target '%s' is a relative symlink, and points to another symlink",
value));
}
entries.put(location, actual);
diff --git a/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java b/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java
index 36fb420..2db666e 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java
@@ -279,8 +279,31 @@
} catch (IOException e) {
assertThat(e).hasMessageThat()
.isEqualTo(
- "runfiles target 'foo' is not absolute, and could not be resolved in the same "
- + "Fileset");
+ "runfiles target 'foo' is a relative symlink, and could not be resolved within the "
+ + "same Fileset");
+ }
+ }
+
+ @Test
+ public void testManifestWithUnresolvableRelativeSymlinkToRelativeSymlink() throws Exception {
+ // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST".
+ scratchFile(
+ "/root/out/_foo/MANIFEST",
+ "workspace/bar foo",
+ "<some digest>",
+ "workspace/foo baz",
+ "<some digest>");
+
+ ArtifactRoot outputRoot =
+ ArtifactRoot.asDerivedRoot(fs.getPath("/root"), fs.getPath("/root/out"));
+ Artifact artifact = new Artifact(fs.getPath("/root/out/foo"), outputRoot);
+ try {
+ FilesetManifest.parseManifestFile(artifact.getExecPath(), execRoot, "workspace", RESOLVE);
+ fail();
+ } catch (IOException e) {
+ assertThat(e).hasMessageThat()
+ .isEqualTo(
+ "runfiles target 'foo' is a relative symlink, and points to another symlink");
}
}