From 1cd2eb7e0a9fe0eae4c0deaa1adf10ed19e11fa5 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Fri, 6 Oct 2023 10:17:33 -0700 Subject: [PATCH] refactor: remove exclude_prefixes from copy_to_directory and copy_to_directory_bin_action (#591) --- docs/copy_to_directory.md | 11 ++++----- lib/private/copy_to_directory.bzl | 40 ------------------------------- 2 files changed, 4 insertions(+), 47 deletions(-) diff --git a/docs/copy_to_directory.md b/docs/copy_to_directory.md index 141e7bc..36e23bd 100644 --- a/docs/copy_to_directory.md +++ b/docs/copy_to_directory.md @@ -8,10 +8,9 @@ Copy files and directories to an output directory. ## copy_to_directory
-copy_to_directory(name, allow_overwrites, exclude_prefixes, exclude_srcs_packages,
-                  exclude_srcs_patterns, hardlink, include_external_repositories,
-                  include_srcs_packages, include_srcs_patterns, out, replace_prefixes, root_paths,
-                  srcs, verbose)
+copy_to_directory(name, allow_overwrites, exclude_srcs_packages, exclude_srcs_patterns, hardlink,
+                  include_external_repositories, include_srcs_packages, include_srcs_patterns, out,
+                  replace_prefixes, root_paths, srcs, verbose)
 
Copies files and directories to an output directory. @@ -53,7 +52,6 @@ for more information on supported globbing patterns. | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | | allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.

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 | -| 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). | List of strings | optional | [] | | 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). | List of strings | optional | [] | | 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). | List of strings | optional | [] | | hardlink | Controls when to use hardlinks to files instead of making copies.

Creating hardlinks is much faster than making copies of files with the caveat that hardlinks share file permissions with their source.

Since Bazel removes write permissions on files in the output tree after an action completes, hardlinks to source files are not recommended since write permissions will be inadvertently removed from sources files.

- auto: hardlinks are used for generated files already in the output tree - off: all files are copied - on: hardlinks are used for all files (not recommended) | String | optional | "auto" | @@ -75,7 +73,7 @@ for more information on supported globbing patterns. copy_to_directory_bin_action(ctx, name, dst, copy_to_directory_bin, files, targets, root_paths, include_external_repositories, include_srcs_packages, exclude_srcs_packages, include_srcs_patterns, exclude_srcs_patterns, - exclude_prefixes, replace_prefixes, allow_overwrites, hardlink, verbose) + replace_prefixes, allow_overwrites, hardlink, verbose) Factory function to copy files to a directory using a tool binary. @@ -104,7 +102,6 @@ other rule implementations where additional_files can also be passed in. | exclude_srcs_packages | List of Bazel packages (with glob support) to exclude from output directory.

See copy_to_directory rule documentation for more details. | [] | | include_srcs_patterns | List of paths (with glob support) to include in output directory.

See copy_to_directory rule documentation for more details. | ["**"] | | exclude_srcs_patterns | List of paths (with glob support) to exclude from output directory.

See copy_to_directory rule documentation for more details. | [] | -| exclude_prefixes | List of path prefixes to exclude from output directory.

See copy_to_directory rule documentation for more details. | [] | | replace_prefixes | Map of paths prefixes to replace in the output directory path when copying files.

See copy_to_directory rule documentation for more details. | {} | | allow_overwrites | If True, allow files to be overwritten if the same output file is copied to twice.

See copy_to_directory rule documentation for more details. | False | | hardlink | Controls when to use hardlinks to files instead of making copies.

See copy_to_directory rule documentation for more details. | "auto" | diff --git a/lib/private/copy_to_directory.bzl b/lib/private/copy_to_directory.bzl index 160f777..1bb265a 100644 --- a/lib/private/copy_to_directory.bzl +++ b/lib/private/copy_to_directory.bzl @@ -164,23 +164,6 @@ 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 @@ -257,9 +240,6 @@ _copy_to_directory_attr = { "exclude_srcs_patterns": attr.string_list( doc = _copy_to_directory_attr_doc["exclude_srcs_patterns"], ), - "exclude_prefixes": attr.string_list( - doc = _copy_to_directory_attr_doc["exclude_prefixes"], - ), "replace_prefixes": attr.string_dict( doc = _copy_to_directory_attr_doc["replace_prefixes"], ), @@ -302,7 +282,6 @@ def _copy_to_directory_impl(ctx): exclude_srcs_packages = ctx.attr.exclude_srcs_packages, include_srcs_patterns = ctx.attr.include_srcs_patterns, exclude_srcs_patterns = ctx.attr.exclude_srcs_patterns, - exclude_prefixes = ctx.attr.exclude_prefixes, replace_prefixes = ctx.attr.replace_prefixes, allow_overwrites = ctx.attr.allow_overwrites, hardlink = ctx.attr.hardlink, @@ -342,7 +321,6 @@ def copy_to_directory_bin_action( exclude_srcs_packages = [], include_srcs_patterns = ["**"], exclude_srcs_patterns = [], - exclude_prefixes = [], replace_prefixes = {}, allow_overwrites = False, hardlink = "auto", @@ -392,10 +370,6 @@ def copy_to_directory_bin_action( See copy_to_directory rule documentation for more details. - exclude_prefixes: List of path prefixes to exclude from output directory. - - See copy_to_directory rule documentation for more details. - replace_prefixes: Map of paths prefixes to replace in the output directory path when copying files. See copy_to_directory rule documentation for more details. @@ -418,20 +392,6 @@ def copy_to_directory_bin_action( include_srcs_packages = _expand_src_packages_patterns(include_srcs_packages, ctx.label.package) exclude_srcs_packages = _expand_src_packages_patterns(exclude_srcs_packages, ctx.label.package) - # Convert and append exclude_prefixes to exclude_srcs_patterns - # TODO(2.0): remove exclude_prefixes this block and in a future breaking release - for exclude_prefix in exclude_prefixes: - if exclude_prefix.endswith("**"): - exclude_srcs_patterns.append(exclude_prefix) - elif exclude_prefix.endswith("*"): - exclude_srcs_patterns.append(exclude_prefix + "/**") - exclude_srcs_patterns.append(exclude_prefix) - elif exclude_prefix.endswith("/"): - exclude_srcs_patterns.append(exclude_prefix + "**") - else: - exclude_srcs_patterns.append(exclude_prefix + "*/**") - exclude_srcs_patterns.append(exclude_prefix + "*") - if not include_srcs_packages: fail("An empty 'include_srcs_packages' list will exclude all srcs and result in an empty directory")