From 054dea4438506b3df384b127706f8e7b6a228249 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 a037811a8e70e2..a87e170ecf8b2f 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 @@ -490,7 +490,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 02529d8c9de2dc..b487d214e108b9 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 @@ -885,6 +885,36 @@ public void remoteCacheEvictBlobs_whenPrefetchingInputTree_incrementalBuildCanCo /* isLocal= */ true); } + @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(