From 5c4cf47a131c84506aad9ce0e014c6643c31a4ac Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 29 Jun 2023 05:53:47 -0700 Subject: [PATCH] Fix non-declared symlink issue for local actions when BwoB. When prefetching non-declared symlink for local actions, we want to download the target artifact if they haven't been downloaded. Currently, the code use `path.getRelativePath(path.readSymbolicLink())` to mimic resolving relative symlink which is not correct. Replacing it with `path.readSymbolicLink()`. Fixes #18772. PiperOrigin-RevId: 544331900 Change-Id: Ie2a6bac298ab9f81e44d5f505f1b3d83519ba3ca --- .../remote/AbstractActionInputPrefetcher.java | 2 +- ...ildWithoutTheBytesIntegrationTestBase.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/AbstractActionInputPrefetcher.java b/src/main/java/com/google/devtools/build/lib/remote/AbstractActionInputPrefetcher.java index d4533595848f76..f1700d6bd9be87 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/AbstractActionInputPrefetcher.java +++ b/src/main/java/com/google/devtools/build/lib/remote/AbstractActionInputPrefetcher.java @@ -436,7 +436,7 @@ private Completable downloadFileNoCheckRx( Priority priority) { if (path.isSymbolicLink()) { try { - path = path.getRelative(path.readSymbolicLink()); + path = path.resolveSymbolicLinks(); } catch (IOException e) { return Completable.error(e); } diff --git a/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTestBase.java b/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTestBase.java index 7039d757d14bd7..8f6c0b3ad77610 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTestBase.java +++ b/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTestBase.java @@ -1395,6 +1395,36 @@ public void remoteTreeFilesExpiredBetweenBuilds_rerunGeneratingActions() throws assertValidOutputFile("a/bar.out", "file-inside\nupdated bar" + lineSeparator()); } + @Test + public void nonDeclaredSymlinksFromLocalActions() throws Exception { + write( + "BUILD", + "genrule(", + " name = 'foo',", + " srcs = [],", + " outs = ['foo.txt'],", + " cmd = 'echo foo > $@',", + ")", + "genrule(", + " name = 'foo-link',", + " srcs = [':foo'],", + " outs = ['foo.link'],", + " cmd = 'ln -s foo.txt $@',", + " local = True,", + ")", + "genrule(", + " name = 'foobar',", + " srcs = [':foo-link'],", + " outs = ['foobar.txt'],", + " cmd = 'cat $(location :foo-link) > $@ && echo bar >> $@',", + " local = True,", + ")"); + + buildTarget("//:foobar"); + + assertValidOutputFile("foobar.txt", "foo\nbar\n"); + } + protected void assertOutputsDoNotExist(String target) throws Exception { for (Artifact output : getArtifacts(target)) { assertWithMessage(