feat: add an option to not include copy_to_directory output in runfiles (#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>
This commit is contained in:
parent
fa583181ff
commit
716af223c2
|
@ -7,9 +7,10 @@ Copy files and directories to an output directory.
|
||||||
## copy_to_directory
|
## copy_to_directory
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
copy_to_directory(<a href="#copy_to_directory-name">name</a>, <a href="#copy_to_directory-srcs">srcs</a>, <a href="#copy_to_directory-out">out</a>, <a href="#copy_to_directory-allow_overwrites">allow_overwrites</a>, <a href="#copy_to_directory-exclude_srcs_packages">exclude_srcs_packages</a>, <a href="#copy_to_directory-exclude_srcs_patterns">exclude_srcs_patterns</a>,
|
copy_to_directory(<a href="#copy_to_directory-name">name</a>, <a href="#copy_to_directory-srcs">srcs</a>, <a href="#copy_to_directory-out">out</a>, <a href="#copy_to_directory-add_directory_to_runfiles">add_directory_to_runfiles</a>, <a href="#copy_to_directory-allow_overwrites">allow_overwrites</a>,
|
||||||
<a href="#copy_to_directory-hardlink">hardlink</a>, <a href="#copy_to_directory-include_external_repositories">include_external_repositories</a>, <a href="#copy_to_directory-include_srcs_packages">include_srcs_packages</a>,
|
<a href="#copy_to_directory-exclude_srcs_packages">exclude_srcs_packages</a>, <a href="#copy_to_directory-exclude_srcs_patterns">exclude_srcs_patterns</a>, <a href="#copy_to_directory-hardlink">hardlink</a>,
|
||||||
<a href="#copy_to_directory-include_srcs_patterns">include_srcs_patterns</a>, <a href="#copy_to_directory-preserve_mtime">preserve_mtime</a>, <a href="#copy_to_directory-replace_prefixes">replace_prefixes</a>, <a href="#copy_to_directory-root_paths">root_paths</a>, <a href="#copy_to_directory-verbose">verbose</a>)
|
<a href="#copy_to_directory-include_external_repositories">include_external_repositories</a>, <a href="#copy_to_directory-include_srcs_packages">include_srcs_packages</a>, <a href="#copy_to_directory-include_srcs_patterns">include_srcs_patterns</a>,
|
||||||
|
<a href="#copy_to_directory-preserve_mtime">preserve_mtime</a>, <a href="#copy_to_directory-replace_prefixes">replace_prefixes</a>, <a href="#copy_to_directory-root_paths">root_paths</a>, <a href="#copy_to_directory-verbose">verbose</a>)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Copies files and directories to an output directory.
|
Copies files and directories to an output directory.
|
||||||
|
@ -50,6 +51,7 @@ for more information on supported globbing patterns.
|
||||||
| <a id="copy_to_directory-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
|
| <a id="copy_to_directory-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
|
||||||
| <a id="copy_to_directory-srcs"></a>srcs | Files and/or directories or targets that provide `DirectoryPathInfo` to copy into the output directory. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
|
| <a id="copy_to_directory-srcs"></a>srcs | Files and/or directories or targets that provide `DirectoryPathInfo` to copy into the output directory. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
|
||||||
| <a id="copy_to_directory-out"></a>out | Path of the output directory, relative to this package.<br><br>If not set, the name of the target is used. | String | optional | `""` |
|
| <a id="copy_to_directory-out"></a>out | Path of the output directory, relative to this package.<br><br>If not set, the name of the target is used. | String | optional | `""` |
|
||||||
|
| <a id="copy_to_directory-add_directory_to_runfiles"></a>add_directory_to_runfiles | Whether to add the outputted directory to the target's runfiles. | Boolean | optional | `True` |
|
||||||
| <a id="copy_to_directory-allow_overwrites"></a>allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.<br><br>The order of srcs matters as the last copy of a particular file will win when overwriting. Performance of copy_to_directory will be slightly degraded when allow_overwrites is True since copies cannot be parallelized out as they are calculated. Instead all copy paths must be calculated before any copies can be started. | Boolean | optional | `False` |
|
| <a id="copy_to_directory-allow_overwrites"></a>allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.<br><br>The order of srcs matters as the last copy of a particular file will win when overwriting. Performance of copy_to_directory will be slightly degraded when allow_overwrites is True since copies cannot be parallelized out as they are calculated. Instead all copy paths must be calculated before any copies can be started. | Boolean | optional | `False` |
|
||||||
| <a id="copy_to_directory-exclude_srcs_packages"></a>exclude_srcs_packages | List of Bazel packages (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br>Forward slashes (`/`) should be used as path separators. A first character of `"."` will be replaced by the target's package path.<br><br>Files that have do not have matching Bazel packages are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | `[]` |
|
| <a id="copy_to_directory-exclude_srcs_packages"></a>exclude_srcs_packages | List of Bazel packages (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br>Forward slashes (`/`) should be used as path separators. A first character of `"."` will be replaced by the target's package path.<br><br>Files that have do not have matching Bazel packages are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | `[]` |
|
||||||
| <a id="copy_to_directory-exclude_srcs_patterns"></a>exclude_srcs_patterns | List of paths (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if their output directory path, after applying `root_paths`, matches one of the patterns specified.<br><br>Forward slashes (`/`) should be used as path separators.<br><br>Files that do not have matching output directory paths are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | `[]` |
|
| <a id="copy_to_directory-exclude_srcs_patterns"></a>exclude_srcs_patterns | List of paths (with glob support) to exclude from output directory.<br><br>Files in srcs are not copied to the output directory if their output directory path, after applying `root_paths`, matches one of the patterns specified.<br><br>Forward slashes (`/`) should be used as path separators.<br><br>Files that do not have matching output directory paths are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | `[]` |
|
||||||
|
|
|
@ -51,6 +51,7 @@ _copy_to_directory_attr_doc = {
|
||||||
|
|
||||||
If not set, the name of the target is used.
|
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
|
||||||
"root_paths": """List of paths (with glob support) that are roots in the output directory.
|
"root_paths": """List of paths (with glob support) that are roots in the output directory.
|
||||||
|
|
||||||
|
@ -222,6 +223,12 @@ _copy_to_directory_attr = {
|
||||||
"out": attr.string(
|
"out": attr.string(
|
||||||
doc = _copy_to_directory_attr_doc["out"],
|
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(
|
"root_paths": attr.string_list(
|
||||||
default = ["."],
|
default = ["."],
|
||||||
doc = _copy_to_directory_attr_doc["root_paths"],
|
doc = _copy_to_directory_attr_doc["root_paths"],
|
||||||
|
@ -296,10 +303,12 @@ def _copy_to_directory_impl(ctx):
|
||||||
verbose = ctx.attr.verbose,
|
verbose = ctx.attr.verbose,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
runfiles = ctx.runfiles([dst]) if ctx.attr.add_directory_to_runfiles else None
|
||||||
|
|
||||||
return [
|
return [
|
||||||
DefaultInfo(
|
DefaultInfo(
|
||||||
files = depset([dst]),
|
files = depset([dst]),
|
||||||
runfiles = ctx.runfiles([dst]),
|
runfiles = runfiles,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,10 @@ copy_to_directory(
|
||||||
include_external_repositories = ["external_test_repo"],
|
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(
|
sh_test(
|
||||||
name = "case_6_test",
|
name = "case_6_test",
|
||||||
timeout = "short",
|
timeout = "short",
|
||||||
|
|
Loading…
Reference in New Issue