Skip to content

Commit d418245

Browse files
Wyveraldcoeuvre
andauthored
Remote: Don't check declared outputs for failed action (bazelbuild#15181)
Fix a bug that Bazel print message ``` Invalid action cache entry ...: expected output ... does not exist. ``` instead of the underlying error message when remote action failed. Closes bazelbuild#15151. PiperOrigin-RevId: 438815494 Co-authored-by: Chi Wang <[email protected]>
1 parent df153df commit d418245

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

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

+21-19
Original file line numberDiff line numberDiff line change
@@ -1010,26 +1010,28 @@ public InMemoryOutput downloadOutputs(RemoteAction action, RemoteActionResult re
10101010
metadata = parseActionResultMetadata(action, result);
10111011
}
10121012

1013-
// Check that all mandatory outputs are created.
1014-
for (ActionInput output : action.spawn.getOutputFiles()) {
1015-
if (action.spawn.isMandatoryOutput(output)) {
1016-
// Don't check output that is tree artifact since spawn could generate nothing under that
1017-
// directory. Remote server typically doesn't create directory ahead of time resulting in
1018-
// empty tree artifact missing from action cache entry.
1019-
if (output instanceof Artifact && ((Artifact) output).isTreeArtifact()) {
1020-
continue;
1021-
}
1013+
if (result.success()) {
1014+
// Check that all mandatory outputs are created.
1015+
for (ActionInput output : action.spawn.getOutputFiles()) {
1016+
if (action.spawn.isMandatoryOutput(output)) {
1017+
// Don't check output that is tree artifact since spawn could generate nothing under that
1018+
// directory. Remote server typically doesn't create directory ahead of time resulting in
1019+
// empty tree artifact missing from action cache entry.
1020+
if (output instanceof Artifact && ((Artifact) output).isTreeArtifact()) {
1021+
continue;
1022+
}
10221023

1023-
Path localPath = execRoot.getRelative(output.getExecPath());
1024-
if (!metadata.files.containsKey(localPath)
1025-
&& !metadata.directories.containsKey(localPath)
1026-
&& !metadata.symlinks.containsKey(localPath)) {
1027-
throw new IOException(
1028-
"Invalid action cache entry "
1029-
+ action.actionKey.getDigest().getHash()
1030-
+ ": expected output "
1031-
+ prettyPrint(output)
1032-
+ " does not exist.");
1024+
Path localPath = execRoot.getRelative(output.getExecPath());
1025+
if (!metadata.files.containsKey(localPath)
1026+
&& !metadata.directories.containsKey(localPath)
1027+
&& !metadata.symlinks.containsKey(localPath)) {
1028+
throw new IOException(
1029+
"Invalid action cache entry "
1030+
+ action.actionKey.getDigest().getHash()
1031+
+ ": expected output "
1032+
+ prettyPrint(output)
1033+
+ " does not exist.");
1034+
}
10331035
}
10341036
}
10351037
}

src/test/shell/bazel/remote/remote_execution_test.sh

+19
Original file line numberDiff line numberDiff line change
@@ -3579,4 +3579,23 @@ EOF
35793579
[[ "$remote_ac_files" == 0 ]] || fail "Expected 0 remote action cache entries, not $remote_ac_files"
35803580
}
35813581

3582+
function test_failed_action_dont_check_declared_outputs() {
3583+
# Test that if action failed, outputs are not checked
3584+
3585+
mkdir -p a
3586+
cat > a/BUILD <<EOF
3587+
genrule(
3588+
name = 'foo',
3589+
outs = ["foo.txt"],
3590+
cmd = "exit 1",
3591+
)
3592+
EOF
3593+
3594+
bazel build \
3595+
--remote_executor=grpc://localhost:${worker_port} \
3596+
//a:foo >& $TEST_log && fail "Should failed to build"
3597+
3598+
expect_log "Executing genrule .* failed: (Exit 1):"
3599+
}
3600+
35823601
run_suite "Remote execution and remote cache tests"

0 commit comments

Comments
 (0)