Skip to content

Commit 8cc1a74

Browse files
committed
Gracefully handle output symlinks with BwoB
If an action creates output symlinks, `--remote_download_minimal` now falls back to downloading all its outputs rather than failing with an exception, which most of the time led to a broken build.
1 parent 0e8e611 commit 8cc1a74

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,10 @@ public InMemoryOutput downloadOutputs(RemoteAction action, RemoteActionResult re
11421142
||
11431143
// In case the action failed, download all outputs. It might be helpful for debugging
11441144
// and there is no point in injecting output metadata of a failed action.
1145-
result.getExitCode() != 0;
1145+
result.getExitCode() != 0
1146+
||
1147+
// Symlinks in actions output are not yet supported with BwoB.
1148+
!metadata.symlinks().isEmpty();
11461149

11471150
// Download into temporary paths, then move everything at the end.
11481151
// This avoids holding the output lock while downloading, which would prevent the local branch
@@ -1162,12 +1165,8 @@ public InMemoryOutput downloadOutputs(RemoteAction action, RemoteActionResult re
11621165
checkState(
11631166
result.getExitCode() == 0,
11641167
"injecting remote metadata is only supported for successful actions (exit code 0).");
1165-
1166-
if (!metadata.symlinks().isEmpty()) {
1167-
throw new IOException(
1168-
"Symlinks in action outputs are not yet supported by "
1169-
+ "--experimental_remote_download_outputs=minimal");
1170-
}
1168+
checkState(metadata.symlinks.isEmpty(), "Symlinks in action outputs are not yet supported by"
1169+
+ " --experimental_remote_download_outputs=minimal");
11711170
}
11721171

11731172
FileOutErr tmpOutErr = outErr.childOutErr();

src/test/java/com/google/devtools/build/lib/remote/BuildWithoutTheBytesIntegrationTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,37 @@ public void symlinkToNestedDirectory() throws Exception {
433433
buildTarget("//a:one_local", "//a:two_local", "//a:one_remote", "//a:two_remote");
434434
}
435435

436+
@Test
437+
public void outputSymlinkHandledGracefully() throws Exception {
438+
write(
439+
"a/defs.bzl",
440+
"def _impl(ctx):",
441+
" out = ctx.actions.declare_symlink(ctx.label.name)",
442+
" ctx.actions.run_shell(",
443+
" inputs = [],",
444+
" outputs = [out],",
445+
" command = 'ln -s hello $1',",
446+
" arguments = [out.path],",
447+
" )",
448+
" return DefaultInfo(files = depset([out]))",
449+
"",
450+
"my_rule = rule(",
451+
" implementation = _impl,",
452+
")");
453+
454+
write(
455+
"a/BUILD",
456+
"load(':defs.bzl', 'my_rule')",
457+
"",
458+
"my_rule(name = 'hello')");
459+
460+
buildTarget("//a:hello");
461+
462+
Path outputPath = getOutputPath("a/hello");
463+
assertThat(outputPath.exists()).isTrue();
464+
assertThat(outputPath.isSymbolicLink()).isTrue();
465+
}
466+
436467
@Test
437468
public void replaceOutputDirectoryWithFile() throws Exception {
438469
write(

0 commit comments

Comments
 (0)