Skip to content

Commit

Permalink
Add test in java
Browse files Browse the repository at this point in the history
  • Loading branch information
coeuvre committed Nov 25, 2022
1 parent 05d1b03 commit 384edf6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,36 @@ public void downloadToplevel_treeArtifacts() throws Exception {
assertValidOutputFile("foo/file-3", "file-3\n");
}

@Test
public void treeOutputsFromLocalFileSystem_works() throws Exception {
// Test that tree artifact generated locally can be consumed by other actions.
// See https://github.com/bazelbuild/bazel/issues/16789

// Disable remote execution so tree outputs are generated locally
addOptions("--modify_execution_info=OutputDir=+no-remote-exec");
setDownloadToplevel();
writeOutputDirRule();
write(
"BUILD",
"load(':output_dir.bzl', 'output_dir')",
"output_dir(",
" name = 'foo',",
" manifest = ':manifest',",
")",
"genrule(",
" name = 'foobar',",
" srcs = [':foo'],",
" outs = ['out/foobar.txt'],",
" cmd = 'cat $(location :foo)/file-1 > $@ && echo bar >> $@',",
")");
write("manifest", "file-1");

buildTarget("//:foobar");
waitDownloads();

assertValidOutputFile("out/foobar.txt", "file-1\nbar\n");
}

@Test
public void incrementalBuild_deleteOutputsInUnwritableParentDirectory() throws Exception {
write(
Expand Down Expand Up @@ -695,6 +725,7 @@ protected void writeOutputDirRule() throws IOException {
"def _output_dir_impl(ctx):",
" output_dir = ctx.actions.declare_directory(ctx.attr.name)",
" ctx.actions.run_shell(",
" mnemonic = 'OutputDir',",
" inputs = [ctx.file.manifest],",
" outputs = [output_dir],",
" arguments = [ctx.file.manifest.path, output_dir.path],",
Expand Down
42 changes: 0 additions & 42 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,46 +1341,4 @@ 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 384edf6

Please sign in to comment.