chore: cleanup copy_to_directory docs and expose attr docstrings via lib for use downstream (#330)

This commit is contained in:
Greg Magolan 2023-01-15 13:24:15 -08:00 committed by GitHub
parent e84d97a161
commit 1d3f04f7b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 245 additions and 218 deletions

View File

@ -1,9 +1,6 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->
Copies files and directories to an output directory.
Files and directories can be arranged as needed in the output directory using
the `root_paths`, `include_srcs_patters`, `exclude_srcs_patters` and `replace_prefixes` attributes.
Copy files and directories to an output directory.
<a id="copy_to_directory"></a>
@ -16,6 +13,36 @@ copy_to_directory(<a href="#copy_to_directory-name">name</a>, <a href="#copy_to_
<a href="#copy_to_directory-include_srcs_patterns">include_srcs_patterns</a>, <a href="#copy_to_directory-out">out</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-srcs">srcs</a>, <a href="#copy_to_directory-verbose">verbose</a>)
</pre>
Copies files and directories to an output directory.
Files and directories can be arranged as needed in the output directory using
the `root_paths`, `include_srcs_patters`, `exclude_srcs_patters` and `replace_prefixes` attributes.
Filters and transformations are applied in the following order:
1. `include_external_repositories`
2. `include_srcs_packages`
3. `exclude_srcs_packages`
4. `root_paths`
5. `include_srcs_patterns`
6. `exclude_srcs_patterns`
7. `replace_prefixes`
For more information each filters / transformations applied, see
the documentation for the specific filter / transformation attribute.
Glob patterns are supported. Standard wildcards (globbing patterns) plus the `**` doublestar (aka. super-asterisk)
are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same
globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns
for more information on supported globbing patterns.
**ATTRIBUTES**
@ -24,17 +51,17 @@ copy_to_directory(<a href="#copy_to_directory-name">name</a>, <a href="#copy_to_
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="copy_to_directory-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <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> If set, then the order of srcs matters as the last copy of a particular file will win.<br><br> This setting has no effect on Windows where overwrites are always allowed. | Boolean | optional | False |
| <a id="copy_to_directory-exclude_prefixes"></a>exclude_prefixes | List of path prefixes (with glob support) to exclude from output directory.<br><br> DEPRECATED: use <code>exclude_srcs_patterns</code> instead<br><br> Files in srcs are not copied to the output directory if their output directory path, after applying <code>root_paths</code>, starts with or fully matches one of the patterns specified.<br><br> Forward slashes (<code>/</code>) 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> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | 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 (<code>/</code>) should be used as path separators. A first character of <code>"."</code> 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> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | 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 <code>root_paths</code>, matches one of the patterns specified.<br><br> Forward slashes (<code>/</code>) 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> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | List of strings | optional | [] |
| <a id="copy_to_directory-include_external_repositories"></a>include_external_repositories | List of external repository names (with glob support) to include in the output directory.<br><br> Files from external repositories are only copied into the output directory if the external repository they come from matches one of the external repository patterns specified.<br><br> When copied from an external repository, the file path in the output directory defaults to the file's path within the external repository. The external repository name is _not_ included in that path.<br><br> For example, the following copies <code>@external_repo//path/to:file</code> to <code>path/to/file</code> within the output directory.<br><br> <pre><code> copy_to_directory( name = "dir", include_external_repositories = ["external_*"], srcs = ["@external_repo//path/to:file"], ) </code></pre><br><br> Files that come from matching external are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be. The external repository name of the file from an external repository is not included in the output directory path and is considered in subsequent filters and transformations.<br><br> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | List of strings | optional | [] |
| <a id="copy_to_directory-include_srcs_packages"></a>include_srcs_packages | List of Bazel packages (with glob support) to include in output directory.<br><br> Files in srcs are only copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br> Forward slashes (<code>/</code>) should be used as path separators. A first character of <code>"."</code> will be replaced by the target's package path.<br><br> Defaults to <code>["**"]</code> which includes sources from all packages.<br><br> Files that 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> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | List of strings | optional | ["**"] |
| <a id="copy_to_directory-include_srcs_patterns"></a>include_srcs_patterns | List of paths (with glob support) to include in output directory.<br><br> Files in srcs are only copied to the output directory if their output directory path, after applying <code>root_paths</code>, matches one of the patterns specified.<br><br> Forward slashes (<code>/</code>) should be used as path separators.<br><br> Defaults to ["**"] which includes all sources.<br><br> Files that 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> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | List of strings | 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-replace_prefixes"></a>replace_prefixes | Map of paths prefixes (with glob support) to replace in the output directory path when copying files.<br><br> If the output directory path for a file starts with or fully matches a a key in the dict then the matching portion of the output directory path is replaced with the dict value for that key. The final path segment matched can be a partial match of that segment and only the matching portion will be replaced. If there are multiple keys that match, the longest match wins.<br><br> Forward slashes (<code>/</code>) should be used as path separators. <br><br> Replace prefix transformation are the final step in the list of filters and transformations. The final output path of a file being copied into the output directory is determined at this step.<br><br> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="copy_to_directory-root_paths"></a>root_paths | List of paths (with glob support) that are roots in the output directory.<br><br> If any parent directory of a file being copied matches one of the root paths patterns specified, the output directory path will be the path relative to the root path instead of the path relative to the file's workspace. If there are multiple root paths that match, the longest match wins.<br><br> Matching is done on the parent directory of the output file path so a trailing '**' glob patterm will match only up to the last path segment of the dirname and will not include the basename. Only complete path segments are matched. Partial matches on the last segment of the root path are ignored.<br><br> Forward slashes (<code>/</code>) should be used as path separators.<br><br> A "." value expands to the target's package path (<code>ctx.label.package</code>).<br><br> Defaults to ["."] which results in the output directory path of files in the target's package and and sub-packages are relative to the target's package and files outside of that retain their full workspace relative paths.<br><br> Glob patterns are supported. Standard wildcards (globbing patterns) plus the <code>**</code> doublestar (aka. super-asterisk) are supported with the underlying globbing library, https://github.com/bmatcuk/doublestar. This is the same globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle). See https://github.com/bmatcuk/doublestar#patterns for more information on supported globbing patterns.<br><br> Filters and transformations are applied in the following order:<br><br>1. <code>include_external_repositories</code><br><br>2. <code>include_srcs_packages</code><br><br>3. <code>exclude_srcs_packages</code><br><br>4. <code>root_paths</code><br><br>5. <code>include_srcs_patterns</code><br><br>6. <code>exclude_srcs_patterns</code><br><br>7. <code>replace_prefixes</code><br><br>For more information each filters / transformations applied, see the documentation for the specific filter / transformation attribute. | List of strings | 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/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <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>If set, then the order of srcs matters as the last copy of a particular file will win.<br><br>This setting has no effect on Windows where overwrites are always allowed. | Boolean | optional | False |
| <a id="copy_to_directory-exclude_prefixes"></a>exclude_prefixes | List of path prefixes (with glob support) to exclude from output directory.<br><br>DEPRECATED: use <code>exclude_srcs_patterns</code> instead<br><br>Files in srcs are not copied to the output directory if their output directory path, after applying <code>root_paths</code>, starts with or fully matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) 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_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 (<code>/</code>) should be used as path separators. A first character of <code>"."</code> 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 <code>root_paths</code>, matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) 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-include_external_repositories"></a>include_external_repositories | List of external repository names (with glob support) to include in the output directory.<br><br>Files from external repositories are only copied into the output directory if the external repository they come from matches one of the external repository patterns specified.<br><br>When copied from an external repository, the file path in the output directory defaults to the file's path within the external repository. The external repository name is _not_ included in that path.<br><br>For example, the following copies <code>@external_repo//path/to:file</code> to <code>path/to/file</code> within the output directory.<br><br><pre><code> copy_to_directory( name = "dir", include_external_repositories = ["external_*"], srcs = ["@external_repo//path/to:file"], ) </code></pre><br><br>Files that come from matching external are subject to subsequent filters and transformations to determine if they are copied and what their path in the output directory will be. The external repository name of the file from an external repository is not included in the output directory path and is considered in subsequent filters and transformations.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | [] |
| <a id="copy_to_directory-include_srcs_packages"></a>include_srcs_packages | List of Bazel packages (with glob support) to include in output directory.<br><br>Files in srcs are only copied to the output directory if the Bazel package of the file matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators. A first character of <code>"."</code> will be replaced by the target's package path.<br><br>Defaults to <code>["**"]</code> which includes sources from all packages.<br><br>Files that 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-include_srcs_patterns"></a>include_srcs_patterns | List of paths (with glob support) to include in output directory.<br><br>Files in srcs are only copied to the output directory if their output directory path, after applying <code>root_paths</code>, matches one of the patterns specified.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>Defaults to <code>["**"]</code> which includes all sources.<br><br>Files that 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-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-replace_prefixes"></a>replace_prefixes | Map of paths prefixes (with glob support) to replace in the output directory path when copying files.<br><br>If the output directory path for a file starts with or fully matches a a key in the dict then the matching portion of the output directory path is replaced with the dict value for that key. The final path segment matched can be a partial match of that segment and only the matching portion will be replaced. If there are multiple keys that match, the longest match wins.<br><br>Forward slashes (<code>/</code>) should be used as path separators. <br><br>Replace prefix transformation are the final step in the list of filters and transformations. The final output path of a file being copied into the output directory is determined at this step.<br><br>Globs are supported (see rule docstring above). | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="copy_to_directory-root_paths"></a>root_paths | List of paths (with glob support) that are roots in the output directory.<br><br>If any parent directory of a file being copied matches one of the root paths patterns specified, the output directory path will be the path relative to the root path instead of the path relative to the file's workspace. If there are multiple root paths that match, the longest match wins.<br><br>Matching is done on the parent directory of the output file path so a trailing '**' glob patterm will match only up to the last path segment of the dirname and will not include the basename. Only complete path segments are matched. Partial matches on the last segment of the root path are ignored.<br><br>Forward slashes (<code>/</code>) should be used as path separators.<br><br>A <code>"."</code> value expands to the target's package path (<code>ctx.label.package</code>).<br><br>Defaults to <code>["."]</code> which results in the output directory path of files in the target's package and and sub-packages are relative to the target's package and files outside of that retain their full workspace relative paths.<br><br>Globs are supported (see rule docstring above). | List of strings | optional | ["."] |
| <a id="copy_to_directory-srcs"></a>srcs | Files and/or directories or targets that provide <code>DirectoryPathInfo</code> to copy into the output directory. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="copy_to_directory-verbose"></a>verbose | If true, prints out verbose logs to stdout | Boolean | optional | False |
@ -67,9 +94,9 @@ other rule implementations where additional_files can also be passed in.
| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="copy_to_directory_action-ctx"></a>ctx | The rule context. | none |
| <a id="copy_to_directory_action-srcs"></a>srcs | Files and/or directories or targets that provide DirectoryPathInfo to copy into the output directory. | none |
| <a id="copy_to_directory_action-srcs"></a>srcs | Files and/or directories or targets that provide <code>DirectoryPathInfo</code> to copy into the output directory. | none |
| <a id="copy_to_directory_action-dst"></a>dst | The directory to copy to. Must be a TreeArtifact. | none |
| <a id="copy_to_directory_action-additional_files"></a>additional_files | List or depset of additional files to copy that are not in the DefaultInfo or DirectoryPathInfo of srcs | <code>[]</code> |
| <a id="copy_to_directory_action-additional_files"></a>additional_files | List or depset of additional files to copy that are not in the <code>DefaultInfo</code> or <code>DirectoryPathInfo</code> of srcs | <code>[]</code> |
| <a id="copy_to_directory_action-root_paths"></a>root_paths | List of paths that are roots in the output directory.<br><br>See copy_to_directory rule documentation for more details. | <code>["."]</code> |
| <a id="copy_to_directory_action-include_external_repositories"></a>include_external_repositories | List of external repository names to include in the output directory.<br><br>See copy_to_directory rule documentation for more details. | <code>[]</code> |
| <a id="copy_to_directory_action-include_srcs_packages"></a>include_srcs_packages | List of Bazel packages to include in output directory.<br><br>See copy_to_directory rule documentation for more details. | <code>["**"]</code> |
@ -112,7 +139,7 @@ other rule implementations where additional_files can also be passed in.
| <a id="copy_to_directory_bin_action-dst"></a>dst | The directory to copy to. Must be a TreeArtifact. | none |
| <a id="copy_to_directory_bin_action-copy_to_directory_bin"></a>copy_to_directory_bin | Copy to directory tool binary. | none |
| <a id="copy_to_directory_bin_action-files"></a>files | List of files to copy into the output directory. | <code>[]</code> |
| <a id="copy_to_directory_bin_action-targets"></a>targets | List of targets that provide DirectoryPathInfo to copy into the output directory. | <code>[]</code> |
| <a id="copy_to_directory_bin_action-targets"></a>targets | List of targets that provide <code>DirectoryPathInfo</code> to copy into the output directory. | <code>[]</code> |
| <a id="copy_to_directory_bin_action-root_paths"></a>root_paths | List of paths that are roots in the output directory.<br><br>See copy_to_directory rule documentation for more details. | <code>["."]</code> |
| <a id="copy_to_directory_bin_action-include_external_repositories"></a>include_external_repositories | List of external repository names to include in the output directory.<br><br>See copy_to_directory rule documentation for more details. | <code>[]</code> |
| <a id="copy_to_directory_bin_action-include_srcs_packages"></a>include_srcs_packages | List of Bazel packages to include in output directory.<br><br>See copy_to_directory rule documentation for more details. | <code>["**"]</code> |

View File

@ -1,7 +1,4 @@
"""Copies files and directories to an output directory.
Files and directories can be arranged as needed in the output directory using
the `root_paths`, `include_srcs_patters`, `exclude_srcs_patters` and `replace_prefixes` attributes.
"""Copy files and directories to an output directory.
"""
load(
@ -17,6 +14,7 @@ copy_to_directory_action = _copy_to_directory_action
copy_to_directory_bin_action = _copy_to_directory_bin_action
copy_to_directory = rule(
doc = _copy_to_directory_lib.doc,
implementation = _copy_to_directory_lib.impl,
provides = _copy_to_directory_lib.provides,
attrs = _copy_to_directory_lib.attrs,

View File

@ -33,229 +33,229 @@ globbing library used by [gazelle](https://github.com/bazelbuild/bazel-gazelle).
for more information on supported globbing patterns.
"""
_copy_to_directory_doc = """Copies files and directories to an output directory.
Files and directories can be arranged as needed in the output directory using
the `root_paths`, `include_srcs_patters`, `exclude_srcs_patters` and `replace_prefixes` attributes.
{filters_transform_order_docstring}
{glob_support_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
)
_copy_to_directory_attr_doc = {
# srcs
"srcs": """Files and/or directories or targets that provide `DirectoryPathInfo` to copy into the output directory.""",
# out
"out": """Path of the output directory, relative to this package.
If not set, the name of the target is used.
""",
# root_paths
"root_paths": """List of paths (with glob support) that are roots in the output directory.
If any parent directory of a file being copied matches one of the root paths
patterns specified, the output directory path will be the path relative to the root path
instead of the path relative to the file's workspace. If there are multiple
root paths that match, the longest match wins.
Matching is done on the parent directory of the output file path so a trailing '**' glob patterm
will match only up to the last path segment of the dirname and will not include the basename.
Only complete path segments are matched. Partial matches on the last segment of the root path
are ignored.
Forward slashes (`/`) should be used as path separators.
A `"."` value expands to the target's package path (`ctx.label.package`).
Defaults to `["."]` which results in the output directory path of files in the
target's package and and sub-packages are relative to the target's package and
files outside of that retain their full workspace relative paths.
Globs are supported (see rule docstring above).
""",
# include_external_repositories
"include_external_repositories": """List of external repository names (with glob support) to include in the output directory.
Files from external repositories are only copied into the output directory if
the external repository they come from matches one of the external repository patterns
specified.
When copied from an external repository, the file path in the output directory
defaults to the file's path within the external repository. The external repository
name is _not_ included in that path.
For example, the following copies `@external_repo//path/to:file` to
`path/to/file` within the output directory.
```
copy_to_directory(
name = "dir",
include_external_repositories = ["external_*"],
srcs = ["@external_repo//path/to:file"],
)
```
Files that come from matching external are subject to subsequent filters and
transformations to determine if they are copied and what their path in the output
directory will be. The external repository name of the file from an external
repository is not included in the output directory path and is considered in subsequent
filters and transformations.
Globs are supported (see rule docstring above).
""",
# include_srcs_packages
"include_srcs_packages": """List of Bazel packages (with glob support) to include in output directory.
Files in srcs are only copied to the output directory if
the Bazel package of the file matches one of the patterns specified.
Forward slashes (`/`) should be used as path separators. A first character of `"."`
will be replaced by the target's package path.
Defaults to `["**"]` which includes sources from all packages.
Files that 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.
Globs are supported (see rule docstring above).
""",
# exclude_srcs_packages
"exclude_srcs_packages": """List of Bazel packages (with glob support) to exclude from output directory.
Files in srcs are not copied to the output directory if
the Bazel package of the file matches one of the patterns specified.
Forward slashes (`/`) should be used as path separators. A first character of `"."`
will be replaced by the target's package path.
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.
Globs are supported (see rule docstring above).
""",
# include_srcs_patterns
"include_srcs_patterns": """List of paths (with glob support) to include in output directory.
Files in srcs are only copied to the output directory if their output
directory path, after applying `root_paths`, matches one of the patterns specified.
Forward slashes (`/`) should be used as path separators.
Defaults to `["**"]` which includes all sources.
Files that 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.
Globs are supported (see rule docstring above).
""",
# exclude_srcs_patterns
"exclude_srcs_patterns": """List of paths (with glob support) to exclude from output directory.
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.
Forward slashes (`/`) should be used as path separators.
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.
Globs are supported (see rule docstring above).
""",
# exclude_prefixes
"exclude_prefixes": """List of path prefixes (with glob support) to exclude from output directory.
DEPRECATED: use `exclude_srcs_patterns` instead
Files in srcs are not copied to the output directory if their output
directory path, after applying `root_paths`, starts with or fully matches one of the
patterns specified.
Forward slashes (`/`) should be used as path separators.
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.
Globs are supported (see rule docstring above).
""",
# replace_prefixes
"replace_prefixes": """Map of paths prefixes (with glob support) to replace in the output directory path when copying files.
If the output directory path for a file starts with or fully matches a
a key in the dict then the matching portion of the output directory path is
replaced with the dict value for that key. The final path segment
matched can be a partial match of that segment and only the matching portion will
be replaced. If there are multiple keys that match, the longest match wins.
Forward slashes (`/`) should be used as path separators.
Replace prefix transformation are the final step in the list of filters and transformations.
The final output path of a file being copied into the output directory
is determined at this step.
Globs are supported (see rule docstring above).
""",
# allow_overwrites
"allow_overwrites": """If True, allow files to be overwritten if the same output file is copied to twice.
If set, then the order of srcs matters as the last copy of a particular file will win.
This setting has no effect on Windows where overwrites are always allowed.
""",
# verbose
"verbose": """If true, prints out verbose logs to stdout""",
}
_copy_to_directory_attr = {
"srcs": attr.label_list(
allow_files = True,
doc = """Files and/or directories or targets that provide DirectoryPathInfo to copy
into the output directory.""",
doc = _copy_to_directory_attr_doc["srcs"],
),
# Cannot declare out as an output here, because there's no API for declaring
# TreeArtifact outputs.
"out": attr.string(
doc = """Path of the output directory, relative to this package.
If not set, the name of the target is used.
""",
doc = _copy_to_directory_attr_doc["out"],
),
"root_paths": attr.string_list(
default = ["."],
doc = """List of paths (with glob support) that are roots in the output directory.
If any parent directory of a file being copied matches one of the root paths
patterns specified, the output directory path will be the path relative to the root path
instead of the path relative to the file's workspace. If there are multiple
root paths that match, the longest match wins.
Matching is done on the parent directory of the output file path so a trailing '**' glob patterm
will match only up to the last path segment of the dirname and will not include the basename.
Only complete path segments are matched. Partial matches on the last segment of the root path
are ignored.
Forward slashes (`/`) should be used as path separators.
A "." value expands to the target's package path (`ctx.label.package`).
Defaults to ["."] which results in the output directory path of files in the
target's package and and sub-packages are relative to the target's package and
files outside of that retain their full workspace relative paths.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["root_paths"],
),
"include_external_repositories": attr.string_list(
doc = """List of external repository names (with glob support) to include in the output directory.
Files from external repositories are only copied into the output directory if
the external repository they come from matches one of the external repository patterns
specified.
When copied from an external repository, the file path in the output directory
defaults to the file's path within the external repository. The external repository
name is _not_ included in that path.
For example, the following copies `@external_repo//path/to:file` to
`path/to/file` within the output directory.
```
copy_to_directory(
name = "dir",
include_external_repositories = ["external_*"],
srcs = ["@external_repo//path/to:file"],
)
```
Files that come from matching external are subject to subsequent filters and
transformations to determine if they are copied and what their path in the output
directory will be. The external repository name of the file from an external
repository is not included in the output directory path and is considered in subsequent
filters and transformations.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["include_external_repositories"],
),
"include_srcs_packages": attr.string_list(
default = ["**"],
doc = """List of Bazel packages (with glob support) to include in output directory.
Files in srcs are only copied to the output directory if
the Bazel package of the file matches one of the patterns specified.
Forward slashes (`/`) should be used as path separators. A first character of `"."`
will be replaced by the target's package path.
Defaults to `["**"]` which includes sources from all packages.
Files that 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.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["include_srcs_packages"],
),
"exclude_srcs_packages": attr.string_list(
doc = """List of Bazel packages (with glob support) to exclude from output directory.
Files in srcs are not copied to the output directory if
the Bazel package of the file matches one of the patterns specified.
Forward slashes (`/`) should be used as path separators. A first character of `"."`
will be replaced by the target's package path.
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.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["exclude_srcs_packages"],
),
"include_srcs_patterns": attr.string_list(
default = ["**"],
doc = """List of paths (with glob support) to include in output directory.
Files in srcs are only copied to the output directory if their output
directory path, after applying `root_paths`, matches one of the patterns specified.
Forward slashes (`/`) should be used as path separators.
Defaults to ["**"] which includes all sources.
Files that 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.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["include_srcs_patterns"],
),
"exclude_srcs_patterns": attr.string_list(
doc = """List of paths (with glob support) to exclude from output directory.
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.
Forward slashes (`/`) should be used as path separators.
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.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["exclude_srcs_patterns"],
),
"exclude_prefixes": attr.string_list(
doc = """List of path prefixes (with glob support) to exclude from output directory.
DEPRECATED: use `exclude_srcs_patterns` instead
Files in srcs are not copied to the output directory if their output
directory path, after applying `root_paths`, starts with or fully matches one of the
patterns specified.
Forward slashes (`/`) should be used as path separators.
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.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["exclude_prefixes"],
),
"replace_prefixes": attr.string_dict(
doc = """Map of paths prefixes (with glob support) to replace in the output directory path when copying files.
If the output directory path for a file starts with or fully matches a
a key in the dict then the matching portion of the output directory path is
replaced with the dict value for that key. The final path segment
matched can be a partial match of that segment and only the matching portion will
be replaced. If there are multiple keys that match, the longest match wins.
Forward slashes (`/`) should be used as path separators.
Replace prefix transformation are the final step in the list of filters and transformations.
The final output path of a file being copied into the output directory
is determined at this step.
{glob_support_docstring}
{filters_transform_order_docstring}
""".format(
filters_transform_order_docstring = _filter_transforms_order_docstring,
glob_support_docstring = _glob_support_docstring,
),
doc = _copy_to_directory_attr_doc["replace_prefixes"],
),
"allow_overwrites": attr.bool(
doc = """If True, allow files to be overwritten if the same output file is copied to twice.
If set, then the order of srcs matters as the last copy of a particular file will win.
This setting has no effect on Windows where overwrites are always allowed.""",
doc = _copy_to_directory_attr_doc["allow_overwrites"],
),
"verbose": attr.bool(
doc = """If true, prints out verbose logs to stdout""",
doc = _copy_to_directory_attr_doc["verbose"],
),
# use '_tool' attribute for development only; do not commit with this attribute active since it
# propagates a dependency on rules_go which would be breaking for users
@ -651,7 +651,7 @@ def copy_to_directory_bin_action(
files: List of files to copy into the output directory.
targets: List of targets that provide DirectoryPathInfo to copy into the output directory.
targets: List of targets that provide `DirectoryPathInfo` to copy into the output directory.
root_paths: List of paths that are roots in the output directory.
@ -838,11 +838,11 @@ def copy_to_directory_action(
Args:
ctx: The rule context.
srcs: Files and/or directories or targets that provide DirectoryPathInfo to copy into the output directory.
srcs: Files and/or directories or targets that provide `DirectoryPathInfo` to copy into the output directory.
dst: The directory to copy to. Must be a TreeArtifact.
additional_files: List or depset of additional files to copy that are not in the DefaultInfo or DirectoryPathInfo of srcs
additional_files: List or depset of additional files to copy that are not in the `DefaultInfo` or `DirectoryPathInfo` of srcs
root_paths: List of paths that are roots in the output directory.
@ -965,6 +965,8 @@ def copy_to_directory_action(
_copy_to_dir_bash(ctx, copy_paths, dst, allow_overwrites)
copy_to_directory_lib = struct(
doc = _copy_to_directory_doc,
attr_doc = _copy_to_directory_attr_doc,
attrs = _copy_to_directory_attr,
impl = _copy_to_directory_impl,
provides = [DefaultInfo],