From 03469cc788d7f4895bfea3ea202dd0f53393f2fb Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 5 May 2023 02:02:59 -0700 Subject: [PATCH] Fix crash in BwoB when creating symlink to source files. Fixes https://github.com/bazelbuild/bazel/issues/18321. PiperOrigin-RevId: 529656152 Change-Id: I06c60282893ef57dea837864031da0fe522937b8 --- .../lib/remote/RemoteActionFileSystem.java | 5 +++- .../BuildWithoutTheBytesIntegrationTest.java | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionFileSystem.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionFileSystem.java index 295c70ec7771f8..7e4096b7fb3e5d 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteActionFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteActionFileSystem.java @@ -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()) { diff --git a/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTest.java index a1aa27e5573579..ffecdfb109b082 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTest.java @@ -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.