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 #18772.

PiperOrigin-RevId: 544331900
Change-Id: Ie2a6bac298ab9f81e44d5f505f1b3d83519ba3ca
  • Loading branch information
coeuvre authored and copybara-github committed Jun 29, 2023
1 parent 09188a9 commit 5c4cf47
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 @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5c4cf47

Please sign in to comment.