Skip to content

Commit

Permalink
Don't inject empty tree artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Nov 21, 2022
1 parent 0c4de91 commit c263e67
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
42 changes: 42 additions & 0 deletions src/test/shell/bazel/remote/build_without_the_bytes_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit c263e67

Please sign in to comment.