Skip to content

Commit 376cd47

Browse files
Remote: Don't check TreeArtifact output (bazelbuild#15085)
With a151116, we ignore action cache entry when checking the remote cache if a mandatory output of the Spawn is missing. However, this breaks Spawns that declare a directory output but don't generate anything under it. Since remote servers typically don't create directory ahead of time, and if the action itself doesn't create files under the directory, that directory will be eliminated from the action cache entry. This PR fixes that by not checking TreeArtifact output. Closes bazelbuild#15077. PiperOrigin-RevId: 436163970 (cherry picked from commit f585783) Co-authored-by: Chi Wang <[email protected]>
1 parent 6d26dc7 commit 376cd47

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,13 @@ public InMemoryOutput downloadOutputs(RemoteAction action, RemoteActionResult re
10131013
// Check that all mandatory outputs are created.
10141014
for (ActionInput output : action.spawn.getOutputFiles()) {
10151015
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+
}
1022+
10161023
Path localPath = execRoot.getRelative(output.getExecPath());
10171024
if (!metadata.files.containsKey(localPath)
10181025
&& !metadata.directories.containsKey(localPath)

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

+57
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,63 @@ EOF
966966
|| fail "Failed to run //a:starlark_output_dir_test with remote execution"
967967
}
968968

969+
function generate_empty_treeartifact_build() {
970+
mkdir -p a
971+
cat > a/BUILD <<'EOF'
972+
load(":output_dir.bzl", "gen_output_dir")
973+
gen_output_dir(
974+
name = "output-dir",
975+
outdir = "dir",
976+
)
977+
EOF
978+
cat > a/output_dir.bzl <<'EOF'
979+
def _gen_output_dir_impl(ctx):
980+
output_dir = ctx.actions.declare_directory(ctx.attr.outdir)
981+
ctx.actions.run_shell(
982+
outputs = [output_dir],
983+
inputs = [],
984+
command = "",
985+
arguments = [output_dir.path],
986+
)
987+
return [
988+
DefaultInfo(files = depset(direct = [output_dir])),
989+
]
990+
991+
gen_output_dir = rule(
992+
implementation = _gen_output_dir_impl,
993+
attrs = {
994+
"outdir": attr.string(mandatory = True),
995+
},
996+
)
997+
EOF
998+
}
999+
1000+
function test_empty_treeartifact_works_with_remote_execution() {
1001+
# Test that empty tree artifact works with remote execution
1002+
generate_empty_treeartifact_build
1003+
1004+
bazel build \
1005+
--remote_executor=grpc://localhost:${worker_port} \
1006+
//a:output-dir >& $TEST_log || fail "Failed to build"
1007+
}
1008+
1009+
function test_empty_treeartifact_works_with_remote_cache() {
1010+
# Test that empty tree artifact works with remote cache
1011+
generate_empty_treeartifact_build
1012+
1013+
bazel build \
1014+
--remote_cache=grpc://localhost:${worker_port} \
1015+
//a:output-dir >& $TEST_log || fail "Failed to build"
1016+
1017+
bazel clean
1018+
1019+
bazel build \
1020+
--remote_cache=grpc://localhost:${worker_port} \
1021+
//a:output-dir >& $TEST_log || fail "Failed to build"
1022+
1023+
expect_log "remote cache hit"
1024+
}
1025+
9691026
function test_downloads_minimal() {
9701027
# Test that genrule outputs are not downloaded when using
9711028
# --remote_download_minimal

0 commit comments

Comments
 (0)