Skip to content

Commit

Permalink
Fix crash in BwoB when creating symlink to source files.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#18321.

PiperOrigin-RevId: 529656152
Change-Id: I06c60282893ef57dea837864031da0fe522937b8
  • Loading branch information
coeuvre authored and copybara-github committed May 5, 2023
1 parent c72643c commit 03469cc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ private void maybeInjectMetadataForSymlinkOrDownload(PathFragment linkPath, Arti
targetPath.isAbsolute(),
"non-symlink artifact materialized as symlink must point to absolute path");

if (inputFetcher.getRemoteOutputChecker().shouldDownloadOutputDuringActionExecution(output)) {
if (isOutput(targetPath)
&& inputFetcher
.getRemoteOutputChecker()
.shouldDownloadOutputDuringActionExecution(output)) {
var targetActionInput = getInput(targetPath.relativeTo(execRoot).getPathString());
if (targetActionInput != null) {
if (output.isTreeArtifact()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,34 @@ public void downloadToplevel_symlinkFile() throws Exception {
assertValidOutputFile("foo-link", "foo\n");
}

@Test
public void downloadToplevel_symlinkSourceFile() throws Exception {
// TODO(chiwang): Make metadata for downloaded symlink non-remote.
assumeFalse(OS.getCurrent() == OS.WINDOWS);

setDownloadToplevel();
writeSymlinkRule();
write(
"BUILD",
"load(':symlink.bzl', 'symlink')",
"symlink(",
" name = 'foo-link',",
" target = ':foo.txt'",
")");
write("foo.txt", "foo");

buildTarget("//:foo-link");

assertOnlyOutputContent("//:foo-link", "foo-link", "foo" + lineSeparator());

// Delete link, re-plant symlink
getOutputPath("foo-link").delete();

buildTarget("//:foo-link");

assertOnlyOutputContent("//:foo-link", "foo-link", "foo" + lineSeparator());
}

@Test
public void downloadToplevel_symlinkTree() throws Exception {
// TODO(chiwang): Make metadata for downloaded symlink non-remote.
Expand Down

0 comments on commit 03469cc

Please sign in to comment.