Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading