Skip to content

Commit 1ab752b

Browse files
committed
Disable echoing CMD code in copy_directory and copy_file rules on Windows
1 parent 31ab4c8 commit 1ab752b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

rules/private/copy_directory_private.bzl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ def _copy_cmd(ctx, src, dst):
3434
# https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
3535
# NB: robocopy return non-zero exit codes on success so we must exit 0 after calling it
3636
cmd_tmpl = """\
37-
if not exist \"{src}\\\" (
38-
echo Error: \"{src}\" is not a directory
39-
@exit 1
40-
)
41-
@robocopy \"{src}\" \"{dst}\" /E /MIR >NUL & @exit 0
42-
"""
37+
@ECHO OFF
38+
if not exist \"{src}\\\" (
39+
echo Error: \"{src}\" is not a directory
40+
@exit 1
41+
)
42+
@robocopy \"{src}\" \"{dst}\" /E /MIR >NUL & @exit 0
43+
"""
4344
mnemonic = "CopyDirectory"
4445
progress_message = "Copying directory %{input}"
4546

rules/private/copy_file_private.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ def copy_cmd(ctx, src, dst):
2828
# To fix that we write the command to a .bat file so no command line
2929
# quoting or escaping is required.
3030
bat = ctx.actions.declare_file(ctx.label.name + "-cmd.bat")
31+
32+
cmd_tmpl = """\
33+
@ECHO OFF
34+
@copy /Y \"%s\" \"%s\" >NUL
35+
"""
36+
3137
ctx.actions.write(
3238
output = bat,
3339
# Do not use lib/shell.bzl's shell.quote() method, because that uses
3440
# Bash quoting syntax, which is different from cmd.exe's syntax.
35-
content = "@copy /Y \"%s\" \"%s\" >NUL" % (
41+
content = cmd_tmpl.format(
3642
src.path.replace("/", "\\"),
3743
dst.path.replace("/", "\\"),
3844
),

0 commit comments

Comments
 (0)