@@ -546,6 +546,51 @@ def _gentree(ctx):
546546 )
547547 return DefaultInfo(files = depset([out]))
548548
549+ gentree = rule(implementation = _gentree)
550+ EOF
551+
552+ cat > a/BUILD << 'EOF '
553+ load(":gentree.bzl", "gentree")
554+ gentree(name = "tree")
555+ cc_binary(name = "main", srcs = [":tree"])
556+ EOF
557+
558+ bazel build \
559+ --remote_executor=grpc://localhost:${worker_port} \
560+ --remote_download_toplevel \
561+ --output_groups=compilation_outputs \
562+ //a:main || fail " Failed to build //a:main"
563+
564+ if [[ " $PLATFORM " == " darwin" ]]; then
565+ expected_object_file=bazel-bin/a/_objs/main/dir/foo.o
566+ else
567+ expected_object_file=bazel-bin/a/_pic_objs/main/dir/foo.pic.o
568+ fi
569+ if ! [[ -f " $expected_object_file " ]]; then
570+ fail " Expected toplevel output $expected_object_file to be downloaded"
571+ fi
572+ }
573+
574+ function test_download_minimal_templated_tree_artifact_downloaded_later() {
575+ mkdir -p a
576+
577+ # We need the top-level output to be a tree artifact generated by a template
578+ # action. This is one way to do that: generate a tree artifact of C++ source
579+ # files, and then compile them with a cc_library / cc_binary rule.
580+ #
581+ # The default top-level output of a cc_binary is the final binary, which is
582+ # not what we want. Instead, we use --output_groups=compilation_outputs to
583+ # fetch the .o files as the top-level outputs.
584+
585+ cat > a/gentree.bzl << 'EOF '
586+ def _gentree(ctx):
587+ out = ctx.actions.declare_directory("dir.cc")
588+ ctx.actions.run_shell(
589+ outputs = [out],
590+ command = "echo 'int main(){return 0;}' > %s/foo.cc" % out.path,
591+ )
592+ return DefaultInfo(files = depset([out]))
593+
549594gentree = rule(implementation = _gentree)
550595EOF
551596
0 commit comments