Skip to content

Commit

Permalink
fix: show directory being copied to in copy_to_directory progress mes…
Browse files Browse the repository at this point in the history
…sage (#345)

* fix: use formatted short_path in copy progress messages

* fix: display destination directory in copy_to_directory progress message
  • Loading branch information
jbedard authored Feb 6, 2023
1 parent d413641 commit 05a92b8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
12 changes: 12 additions & 0 deletions lib/private/copy_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ COPY_EXECUTION_REQUIREMENTS = {
"no-sandbox": "1",
"local": "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("../")
8 changes: 4 additions & 4 deletions lib/private/copy_directory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This rule copies a directory to another location using Bash (on Linux/macOS) or
cmd.exe (on Windows).
"""

load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS")
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS", _progress_path = "progress_path")
load(":platform_utils.bzl", _platform_utils = "platform_utils")

def _copy_cmd(ctx, src, dst):
Expand All @@ -22,7 +22,7 @@ def _copy_cmd(ctx, src, dst):
# NB: robocopy return non-zero exit codes on success so we must exit 0 after calling it
cmd_tmpl = "@robocopy \"{src}\" \"{dst}\" /E >NUL & @exit 0"
mnemonic = "CopyDirectory"
progress_message = "Copying directory %{input}"
progress_message = "Copying directory %s" % _progress_path(src)

ctx.actions.write(
output = bat,
Expand All @@ -49,7 +49,7 @@ def _copy_cmd(ctx, src, dst):
def _copy_bash(ctx, src, dst):
cmd = "rm -Rf \"$2\" && cp -fR \"$1/\" \"$2\""
mnemonic = "CopyDirectory"
progress_message = "Copying directory %{input}"
progress_message = "Copying directory %s" % _progress_path(src)

ctx.actions.run_shell(
tools = [src],
Expand Down Expand Up @@ -145,7 +145,7 @@ def copy_directory_bin_action(
executable = copy_directory_bin,
arguments = args,
mnemonic = "CopyDirectory",
progress_message = "Copying directory %{input}",
progress_message = "Copying directory %s" % _progress_path(src),
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
)

Expand Down
6 changes: 3 additions & 3 deletions lib/private/copy_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cmd.exe (on Windows). `_copy_xfile` marks the resulting file executable,
`_copy_file` does not.
"""

load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS")
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS", _progress_path = "progress_path")
load(":directory_path.bzl", "DirectoryPathInfo")
load(":platform_utils.bzl", _platform_utils = "platform_utils")

Expand All @@ -44,7 +44,7 @@ def _copy_cmd(ctx, src, src_path, dst):
# https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/copy
cmd_tmpl = "@copy /Y \"{src}\" \"{dst}\" >NUL"
mnemonic = "CopyFile"
progress_message = "Copying file %{input}"
progress_message = "Copying file %s" % _progress_path(src)

ctx.actions.write(
output = bat,
Expand All @@ -71,7 +71,7 @@ def _copy_cmd(ctx, src, src_path, dst):
def _copy_bash(ctx, src, src_path, dst):
cmd_tmpl = "cp -f \"$1\" \"$2\""
mnemonic = "CopyFile"
progress_message = "Copying file %{input}"
progress_message = "Copying file %s" % _progress_path(src)

ctx.actions.run_shell(
tools = [src],
Expand Down
8 changes: 4 additions & 4 deletions lib/private/copy_to_directory.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"copy_to_directory implementation"

load("@bazel_skylib//lib:paths.bzl", skylib_paths = "paths")
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS")
load(":copy_common.bzl", _COPY_EXECUTION_REQUIREMENTS = "COPY_EXECUTION_REQUIREMENTS", _progress_path = "progress_path")
load(":paths.bzl", "paths")
load(":directory_path.bzl", "DirectoryPathInfo")
load(":glob_match.bzl", "glob_match", "is_glob")
Expand Down Expand Up @@ -518,7 +518,7 @@ fi
outputs = [dst_dir],
command = "\n".join(cmds),
mnemonic = "CopyToDirectory",
progress_message = "Copying files to directory",
progress_message = "Copying files to directory %s" % _progress_path(dst_dir),
use_default_shell_env = True,
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
)
Expand Down Expand Up @@ -586,7 +586,7 @@ if exist "{src}\\*" (
executable = "cmd.exe",
arguments = ["/C", bat.path.replace("/", "\\")],
mnemonic = "CopyToDirectory",
progress_message = "Copying files to directory",
progress_message = "Copying files to directory %s" % _progress_path(dst_dir),
use_default_shell_env = True,
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
)
Expand Down Expand Up @@ -838,7 +838,7 @@ def copy_to_directory_bin_action(
executable = copy_to_directory_bin,
arguments = [config_file.path],
mnemonic = "CopyToDirectory",
progress_message = "Copying files to directory",
progress_message = "Copying files to directory %s" % _progress_path(dst),
execution_requirements = _COPY_EXECUTION_REQUIREMENTS,
)

Expand Down

0 comments on commit 05a92b8

Please sign in to comment.