Skip to content

Commit

Permalink
Fix non-declared symlink issue for local actions when BwoB.
Browse files Browse the repository at this point in the history
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 bazelbuild#18772.

PiperOrigin-RevId: 544331900
Change-Id: Ie2a6bac298ab9f81e44d5f505f1b3d83519ba3ca
  • Loading branch information
coeuvre authored and iancha1992 committed Jun 29, 2023
1 parent 3a8c076 commit 054dea4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 054dea4

Please sign in to comment.