perf: improve copy_file.bzl progress_message (#931)

This commit is contained in:
David Zbarsky 2024-09-10 13:08:34 -04:00 committed by GitHub
parent de9fd596fd
commit 4c1267fc27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 18 additions and 43 deletions

View File

@ -2,8 +2,7 @@
A rule that copies a directory to another place.
The rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command
on Windows (no Bash is required).
The rule uses a precompiled binary to perform the copy, so no shell is required.
<a id="copy_directory"></a>
@ -15,7 +14,7 @@ copy_directory(<a href="#copy_directory-name">name</a>, <a href="#copy_directory
Copies a directory to another location.
This rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command on Windows (no Bash is required).
This rule uses a precompiled binary to perform the copy, so no shell is required.
If using this rule with source directories, it is recommended that you use the
`--host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1` startup option so that changes

5
docs/copy_file.md generated
View File

@ -5,8 +5,7 @@ A rule that copies a file to another place.
`native.genrule()` is sometimes used to copy files (often wishing to rename them).
The `copy_file` rule does this with a simpler interface than genrule.
The rule uses a Bash command on Linux/macOS/non-Windows, and a `cmd.exe` command
on Windows (no Bash is required).
This rule uses a hermetic uutils/coreutils `cp` binary, no shell is required.
This fork of bazel-skylib's copy_file adds `DirectoryPathInfo` support and allows multiple
`copy_file` rules in the same package.
@ -23,7 +22,7 @@ Copies a file or directory to another location.
`native.genrule()` is sometimes used to copy files (often wishing to rename them). The 'copy_file' rule does this with a simpler interface than genrule.
This rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command on Windows (no Bash is required).
This rule uses a hermetic uutils/coreutils `cp` binary, no shell is required.
If using this rule with source directories, it is recommended that you use the
`--host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1` startup option so that changes

View File

@ -1,7 +1,6 @@
"""A rule that copies a directory to another place.
The rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command
on Windows (no Bash is required).
The rule uses a precompiled binary to perform the copy, so no shell is required.
"""
load(

View File

@ -22,8 +22,7 @@
`native.genrule()` is sometimes used to copy files (often wishing to rename them).
The `copy_file` rule does this with a simpler interface than genrule.
The rule uses a Bash command on Linux/macOS/non-Windows, and a `cmd.exe` command
on Windows (no Bash is required).
This rule uses a hermetic uutils/coreutils `cp` binary, no shell is required.
This fork of bazel-skylib's copy_file adds `DirectoryPathInfo` support and allows multiple
`copy_file` rules in the same package.

View File

@ -12,15 +12,3 @@ COPY_EXECUTION_REQUIREMENTS = {
# output file/directory so little room for non-hermetic inputs to sneak in to the execution.
"no-sandbox": "1",
}
def progress_path(f):
"""
Convert a file to an appropriate string to display in an action progress message.
Args:
f: a file to show as a path in a progress message
Returns:
The path formatted for use in a progress message
"""
return f.short_path.removeprefix("../")

View File

@ -1,10 +1,9 @@
"""Implementation of copy_directory macro and underlying rules.
This rule copies a directory to another location using Bash (on Linux/macOS) or
cmd.exe (on Windows).
This rule copies a directory to another location using a precompiled binary.
"""
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS", _progress_path = "progress_path")
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS")
def copy_directory_bin_action(
ctx,
@ -60,7 +59,7 @@ def copy_directory_bin_action(
executable = copy_directory_bin,
arguments = args,
mnemonic = "CopyDirectory",
progress_message = "Copying directory %s" % _progress_path(src),
progress_message = "Copying directory %{input}",
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
)
@ -123,7 +122,7 @@ def copy_directory(
**kwargs):
"""Copies a directory to another location.
This rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command on Windows (no Bash is required).
This rule uses a precompiled binary to perform the copy, so no shell is required.
If using this rule with source directories, it is recommended that you use the
`--host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1` startup option so that changes

View File

@ -12,19 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# LOCAL MODIFICATIONS
# this has a PR patched in on top of the original
# https://github.com/bazelbuild/bazel-skylib/blob/7b859037a673db6f606661323e74c5d4751595e6/rules/private/copy_file_private.bzl
# https://github.com/bazelbuild/bazel-skylib/pull/324
"""Implementation of copy_file macro and underlying rules.
These rules copy a file to another location using Bash (on Linux/macOS) or
cmd.exe (on Windows). `_copy_xfile` marks the resulting file executable,
`_copy_file` does not.
These rules copy a file to another location using hermetic uutils/coreutils `cp`.
`_copy_xfile` marks the resulting file executable, `_copy_file` does not.
"""
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS", _progress_path = "progress_path")
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS")
load(":directory_path.bzl", "DirectoryPathInfo")
_COREUTILS_TOOLCHAIN = "@aspect_bazel_lib//lib:coreutils_toolchain_type"
@ -89,7 +83,7 @@ def copy_file_action(ctx, src, dst, dir_path = None):
inputs = [src],
outputs = [dst],
mnemonic = "CopyFile",
progress_message = "Copying file %s" % _progress_path(src),
progress_message = "Copying file %{input}",
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
)
@ -152,7 +146,7 @@ def copy_file(name, src, out, is_executable = False, allow_symlink = False, **kw
`native.genrule()` is sometimes used to copy files (often wishing to rename them). The 'copy_file' rule does this with a simpler interface than genrule.
This rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command on Windows (no Bash is required).
This rule uses a hermetic uutils/coreutils `cp` binary, no shell is required.
If using this rule with source directories, it is recommended that you use the
`--host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1` startup option so that changes
@ -178,9 +172,7 @@ def copy_file(name, src, out, is_executable = False, allow_symlink = False, **kw
**kwargs: further keyword arguments, e.g. `visibility`
"""
copy_file_impl = _copy_file
if is_executable:
copy_file_impl = _copy_xfile
copy_file_impl = _copy_xfile if is_executable else _copy_file
copy_file_impl(
name = name,

View File

@ -1,6 +1,6 @@
"copy_to_directory implementation"
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS", _progress_path = "progress_path")
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS")
load(":directory_path.bzl", "DirectoryPathInfo")
load(":paths.bzl", "paths")
@ -497,7 +497,7 @@ def copy_to_directory_bin_action(
executable = copy_to_directory_bin,
arguments = [config_file.path, ctx.label.workspace_name],
mnemonic = "CopyToDirectory",
progress_message = "Copying files to directory %s" % _progress_path(dst),
progress_message = "Copying files to directory %{output}",
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
)