Skip to content

Commit d2724ba

Browse files
iancha1992coeuvre
andauthored
Fix non-declared symlink issue for local actions when BwoB. (#18817)
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 Co-authored-by: Googler <[email protected]>
1 parent ca74d17 commit d2724ba

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/main/java/com/google/devtools/build/lib/remote/AbstractActionInputPrefetcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private Completable downloadFileNoCheckRx(
493493
Priority priority) {
494494
if (path.isSymbolicLink()) {
495495
try {
496-
path = path.getRelative(path.readSymbolicLink());
496+
path = path.resolveSymbolicLinks();
497497
} catch (IOException e) {
498498
return Completable.error(e);
499499
}

src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTestBase.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,36 @@ public void remoteCacheEvictBlobs_whenPrefetchingInputTree_incrementalBuildCanCo
885885
/* isLocal= */ true);
886886
}
887887

888+
@Test
889+
public void nonDeclaredSymlinksFromLocalActions() throws Exception {
890+
write(
891+
"BUILD",
892+
"genrule(",
893+
" name = 'foo',",
894+
" srcs = [],",
895+
" outs = ['foo.txt'],",
896+
" cmd = 'echo foo > $@',",
897+
")",
898+
"genrule(",
899+
" name = 'foo-link',",
900+
" srcs = [':foo'],",
901+
" outs = ['foo.link'],",
902+
" cmd = 'ln -s foo.txt $@',",
903+
" local = True,",
904+
")",
905+
"genrule(",
906+
" name = 'foobar',",
907+
" srcs = [':foo-link'],",
908+
" outs = ['foobar.txt'],",
909+
" cmd = 'cat $(location :foo-link) > $@ && echo bar >> $@',",
910+
" local = True,",
911+
")");
912+
913+
buildTarget("//:foobar");
914+
915+
assertValidOutputFile("foobar.txt", "foo\nbar\n");
916+
}
917+
888918
protected void assertOutputsDoNotExist(String target) throws Exception {
889919
for (Artifact output : getArtifacts(target)) {
890920
assertWithMessage(

0 commit comments

Comments
 (0)