Skip to content

Commit 5c4cf47

Browse files
coeuvrecopybara-github
authored andcommitted
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
1 parent 09188a9 commit 5c4cf47

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
@@ -436,7 +436,7 @@ private Completable downloadFileNoCheckRx(
436436
Priority priority) {
437437
if (path.isSymbolicLink()) {
438438
try {
439-
path = path.getRelative(path.readSymbolicLink());
439+
path = path.resolveSymbolicLinks();
440440
} catch (IOException e) {
441441
return Completable.error(e);
442442
}

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
@@ -1395,6 +1395,36 @@ public void remoteTreeFilesExpiredBetweenBuilds_rerunGeneratingActions() throws
13951395
assertValidOutputFile("a/bar.out", "file-inside\nupdated bar" + lineSeparator());
13961396
}
13971397

1398+
@Test
1399+
public void nonDeclaredSymlinksFromLocalActions() throws Exception {
1400+
write(
1401+
"BUILD",
1402+
"genrule(",
1403+
" name = 'foo',",
1404+
" srcs = [],",
1405+
" outs = ['foo.txt'],",
1406+
" cmd = 'echo foo > $@',",
1407+
")",
1408+
"genrule(",
1409+
" name = 'foo-link',",
1410+
" srcs = [':foo'],",
1411+
" outs = ['foo.link'],",
1412+
" cmd = 'ln -s foo.txt $@',",
1413+
" local = True,",
1414+
")",
1415+
"genrule(",
1416+
" name = 'foobar',",
1417+
" srcs = [':foo-link'],",
1418+
" outs = ['foobar.txt'],",
1419+
" cmd = 'cat $(location :foo-link) > $@ && echo bar >> $@',",
1420+
" local = True,",
1421+
")");
1422+
1423+
buildTarget("//:foobar");
1424+
1425+
assertValidOutputFile("foobar.txt", "foo\nbar\n");
1426+
}
1427+
13981428
protected void assertOutputsDoNotExist(String target) throws Exception {
13991429
for (Artifact output : getArtifacts(target)) {
14001430
assertWithMessage(

0 commit comments

Comments
 (0)