Skip to content

Commit

Permalink
feat: add an option to not include copy_to_directory output in runfil…
Browse files Browse the repository at this point in the history
…es (#886)

* feat: add an option to not include copy_to_directory output in runfiles

* chore: docs update

* chore: don't repeat default

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
  • Loading branch information
kormide and alexeagle authored Sep 19, 2024
1 parent fa58318 commit 716af22
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 5 additions & 3 deletions docs/copy_to_directory.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion lib/private/copy_to_directory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ _copy_to_directory_attr_doc = {
If not set, the name of the target is used.
""",
"add_directory_to_runfiles": """Whether to add the outputted directory to the target's runfiles.""",
# root_paths
"root_paths": """List of paths (with glob support) that are roots in the output directory.
Expand Down Expand Up @@ -222,6 +223,12 @@ _copy_to_directory_attr = {
"out": attr.string(
doc = _copy_to_directory_attr_doc["out"],
),
# TODO(3.0): Remove this attribute and do not add directory to runfiles by default.
# https://github.com/aspect-build/bazel-lib/issues/748
"add_directory_to_runfiles": attr.bool(
default = True,
doc = _copy_to_directory_attr_doc["add_directory_to_runfiles"],
),
"root_paths": attr.string_list(
default = ["."],
doc = _copy_to_directory_attr_doc["root_paths"],
Expand Down Expand Up @@ -296,10 +303,12 @@ def _copy_to_directory_impl(ctx):
verbose = ctx.attr.verbose,
)

runfiles = ctx.runfiles([dst]) if ctx.attr.add_directory_to_runfiles else None

return [
DefaultInfo(
files = depset([dst]),
runfiles = ctx.runfiles([dst]),
runfiles = runfiles,
),
]

Expand Down
4 changes: 4 additions & 0 deletions lib/tests/copy_to_directory/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ copy_to_directory(
include_external_repositories = ["external_test_repo"],
)

# TODO: This test is a false positive. sh_test always includes default
# outputs in runfiles, so even if copy_to_directory did not add its output
# to its runfiles this test would still pass.
# See https://github.com/bazelbuild/bazel/issues/4519.
sh_test(
name = "case_6_test",
timeout = "short",
Expand Down

0 comments on commit 716af22

Please sign in to comment.