Skip to content

Commit 2b92a31

Browse files
coeuvrecopybara-github
authored andcommitted
Remote: Don't check declared outputs for failed action
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
1 parent 2770799 commit 2b92a31

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
@@ -1011,26 +1011,28 @@ public InMemoryOutput downloadOutputs(RemoteAction action, RemoteActionResult re
10111011
metadata = parseActionResultMetadata(action, result);
10121012
}
10131013

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

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

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

+19
Original file line numberDiff line numberDiff line change
@@ -3649,4 +3649,23 @@ EOF
36493649
[[ "$remote_ac_files" == 0 ]] || fail "Expected 0 remote action cache entries, not $remote_ac_files"
36503650
}
36513651

3652+
function test_failed_action_dont_check_declared_outputs() {
3653+
# Test that if action failed, outputs are not checked
3654+
3655+
mkdir -p a
3656+
cat > a/BUILD <<EOF
3657+
genrule(
3658+
name = 'foo',
3659+
outs = ["foo.txt"],
3660+
cmd = "exit 1",
3661+
)
3662+
EOF
3663+
3664+
bazel build \
3665+
--remote_executor=grpc://localhost:${worker_port} \
3666+
//a:foo >& $TEST_log && fail "Should failed to build"
3667+
3668+
expect_log "Executing genrule .* failed: (Exit 1):"
3669+
}
3670+
36523671
run_suite "Remote execution and remote cache tests"

0 commit comments

Comments
 (0)