perf: improve copy_file.bzl progress_message (#931)
This commit is contained in:
parent
de9fd596fd
commit
4c1267fc27
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
A rule that copies a directory to another place.
|
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
|
The rule uses a precompiled binary to perform the copy, so no shell is required.
|
||||||
on Windows (no Bash is required).
|
|
||||||
|
|
||||||
<a id="copy_directory"></a>
|
<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.
|
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
|
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
|
`--host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1` startup option so that changes
|
||||||
|
|
|
@ -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).
|
`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 `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
|
This rule uses a hermetic uutils/coreutils `cp` binary, no shell is required.
|
||||||
on Windows (no Bash is required).
|
|
||||||
|
|
||||||
This fork of bazel-skylib's copy_file adds `DirectoryPathInfo` support and allows multiple
|
This fork of bazel-skylib's copy_file adds `DirectoryPathInfo` support and allows multiple
|
||||||
`copy_file` rules in the same package.
|
`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.
|
`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
|
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
|
`--host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1` startup option so that changes
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""A rule that copies a directory to another place.
|
"""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
|
The rule uses a precompiled binary to perform the copy, so no shell is required.
|
||||||
on Windows (no Bash is required).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
load(
|
load(
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
`native.genrule()` is sometimes used to copy files (often wishing to rename them).
|
`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 `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
|
This rule uses a hermetic uutils/coreutils `cp` binary, no shell is required.
|
||||||
on Windows (no Bash is required).
|
|
||||||
|
|
||||||
This fork of bazel-skylib's copy_file adds `DirectoryPathInfo` support and allows multiple
|
This fork of bazel-skylib's copy_file adds `DirectoryPathInfo` support and allows multiple
|
||||||
`copy_file` rules in the same package.
|
`copy_file` rules in the same package.
|
||||||
|
|
|
@ -12,15 +12,3 @@ COPY_EXECUTION_REQUIREMENTS = {
|
||||||
# output file/directory so little room for non-hermetic inputs to sneak in to the execution.
|
# output file/directory so little room for non-hermetic inputs to sneak in to the execution.
|
||||||
"no-sandbox": "1",
|
"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("../")
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
"""Implementation of copy_directory macro and underlying rules.
|
"""Implementation of copy_directory macro and underlying rules.
|
||||||
|
|
||||||
This rule copies a directory to another location using Bash (on Linux/macOS) or
|
This rule copies a directory to another location using a precompiled binary.
|
||||||
cmd.exe (on Windows).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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(
|
def copy_directory_bin_action(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -60,7 +59,7 @@ def copy_directory_bin_action(
|
||||||
executable = copy_directory_bin,
|
executable = copy_directory_bin,
|
||||||
arguments = args,
|
arguments = args,
|
||||||
mnemonic = "CopyDirectory",
|
mnemonic = "CopyDirectory",
|
||||||
progress_message = "Copying directory %s" % _progress_path(src),
|
progress_message = "Copying directory %{input}",
|
||||||
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
|
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -123,7 +122,7 @@ def copy_directory(
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Copies a directory to another location.
|
"""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
|
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
|
`--host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1` startup option so that changes
|
||||||
|
|
|
@ -12,19 +12,13 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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.
|
"""Implementation of copy_file macro and underlying rules.
|
||||||
|
|
||||||
These rules copy a file to another location using Bash (on Linux/macOS) or
|
These rules copy a file to another location using hermetic uutils/coreutils `cp`.
|
||||||
cmd.exe (on Windows). `_copy_xfile` marks the resulting file executable,
|
`_copy_xfile` marks the resulting file executable, `_copy_file` does not.
|
||||||
`_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")
|
load(":directory_path.bzl", "DirectoryPathInfo")
|
||||||
|
|
||||||
_COREUTILS_TOOLCHAIN = "@aspect_bazel_lib//lib:coreutils_toolchain_type"
|
_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],
|
inputs = [src],
|
||||||
outputs = [dst],
|
outputs = [dst],
|
||||||
mnemonic = "CopyFile",
|
mnemonic = "CopyFile",
|
||||||
progress_message = "Copying file %s" % _progress_path(src),
|
progress_message = "Copying file %{input}",
|
||||||
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
|
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.
|
`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
|
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
|
`--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`
|
**kwargs: further keyword arguments, e.g. `visibility`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
copy_file_impl = _copy_file
|
copy_file_impl = _copy_xfile if is_executable else _copy_file
|
||||||
if is_executable:
|
|
||||||
copy_file_impl = _copy_xfile
|
|
||||||
|
|
||||||
copy_file_impl(
|
copy_file_impl(
|
||||||
name = name,
|
name = name,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"copy_to_directory implementation"
|
"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(":directory_path.bzl", "DirectoryPathInfo")
|
||||||
load(":paths.bzl", "paths")
|
load(":paths.bzl", "paths")
|
||||||
|
|
||||||
|
@ -497,7 +497,7 @@ def copy_to_directory_bin_action(
|
||||||
executable = copy_to_directory_bin,
|
executable = copy_to_directory_bin,
|
||||||
arguments = [config_file.path, ctx.label.workspace_name],
|
arguments = [config_file.path, ctx.label.workspace_name],
|
||||||
mnemonic = "CopyToDirectory",
|
mnemonic = "CopyToDirectory",
|
||||||
progress_message = "Copying files to directory %s" % _progress_path(dst),
|
progress_message = "Copying files to directory %{output}",
|
||||||
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
|
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue