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 b7f31149f9f46f..faf54ba6844826 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 @@ -154,7 +154,12 @@ void flush() throws IOException { } }); - metadataInjector.injectTree(parent, tree.build()); + var metadata = tree.build(); + // Don't inject empty tree metadata, in case that tree files are generated locally, + // skyframe has the change to read metadata from local filesystem. + if (!metadata.getChildren().isEmpty()) { + metadataInjector.injectTree(parent, metadata); + } } } else { RemoteFileInfo remoteFile = diff --git a/src/test/shell/bazel/remote/build_without_the_bytes_test.sh b/src/test/shell/bazel/remote/build_without_the_bytes_test.sh index 477a2f0bd8335f..e0c4bb09fe9eef 100755 --- a/src/test/shell/bazel/remote/build_without_the_bytes_test.sh +++ b/src/test/shell/bazel/remote/build_without_the_bytes_test.sh @@ -1341,4 +1341,46 @@ EOF expect_log "bin-message" } +function test_tree_artifact_from_local_file_system() { + # Test that tree artifact generated locally can be consumed by other actions. + # See https://github.com/bazelbuild/bazel/issues/16789 + + mkdir -p a + cat > a/my_rule.bzl <<'EOF' +def _impl(ctx): + out = ctx.actions.declare_directory(ctx.label.name) + ctx.actions.run_shell( + outputs = [out], + command = "echo '1' > {out}/my_file".format(out = out.path), + ) + return DefaultInfo( + files = depset([out]), + runfiles = ctx.runfiles(files = [out]) + ) +my_rule = rule( + implementation = _impl, + attrs = {}, +) +EOF + cat > a/out_dir_test.sh <<'EOF' +cat $1/my_file +EOF + chmod a+x a/out_dir_test.sh + cat > a/BUILD <<'EOF' +load(":my_rule.bzl", "my_rule") +my_rule(name = "out_dir") +sh_test( + name = "out_dir_test", + srcs = ["out_dir_test.sh"], + args = ["$(rootpath :out_dir)"], + data = [":out_dir"], +) +EOF + + bazel test \ + --remote_cache=grpc://localhost:${worker_port} \ + --remote_download_minimal \ + //a:out_dir_test >& $TEST_log || fail "Failed to test //a:out_dir_test" +} + run_suite "Build without the Bytes tests"