From ffe283f6888e601bd12e66d417b369b1743d5259 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Thu, 27 Jan 2022 00:31:13 -0800 Subject: [PATCH] fix: use robocopy in copy_file#is_directory and copy_to_directory so we don't hit the file path length limit of xcopy --- lib/private/copy_file.bzl | 17 +++++++++-------- lib/private/copy_to_directory.bzl | 7 +++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/private/copy_file.bzl b/lib/private/copy_file.bzl index 2d8ce74e9..d920e4159 100644 --- a/lib/private/copy_file.bzl +++ b/lib/private/copy_file.bzl @@ -50,23 +50,24 @@ def copy_cmd(ctx, src, dst): # Flags are documented at # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/copy - # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy + # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy + # NB: robocopy return non-zero exit codes on success so we must exit 0 after calling it if dst.is_directory: - cmd_tmpl = "@xcopy \"%s\" \"%s\\\" /V /E /H /Y /Q >NUL" + cmd_tmpl = "@robocopy \"{src}\" \"{dst}\" /E >NUL & @exit 0" mnemonic = "CopyDirectory" - progress_message = "Copying directory" + progress_message = "Copying directory %s" % src.path else: - cmd_tmpl = "@copy /Y \"%s\" \"%s\" >NUL" + cmd_tmpl = "@copy /Y \"{src}\" \"{dst}\" >NUL" mnemonic = "CopyFile" - progress_message = "Copying file" + progress_message = "Copying file %s" % src.path ctx.actions.write( output = bat, # Do not use lib/shell.bzl's shell.quote() method, because that uses # Bash quoting syntax, which is different from cmd.exe's syntax. - content = cmd_tmpl % ( - src.path.replace("/", "\\"), - dst.path.replace("/", "\\"), + content = cmd_tmpl.format( + src = src.path.replace("/", "\\"), + dst = dst.path.replace("/", "\\"), ), is_executable = True, ) diff --git a/lib/private/copy_to_directory.bzl b/lib/private/copy_to_directory.bzl index a2537055a..8e72ac5f5 100644 --- a/lib/private/copy_to_directory.bzl +++ b/lib/private/copy_to_directory.bzl @@ -197,7 +197,7 @@ mkdir "%s" >NUL 2>NUL # copy & xcopy flags are documented at # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/copy - # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy + # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy cmds.append(""" if not exist "{src}" ( echo file "{src}" does not exist @@ -205,7 +205,7 @@ if not exist "{src}" ( ) if exist "{src}\\*" ( mkdir "{dst}" >NUL 2>NUL - xcopy "{src}\\*" "{dst}" /V /E /H /Y /Q >NUL + robocopy "{src}" "{dst}" /E >NUL ) else ( mkdir "{dst_dir}" >NUL 2>NUL copy /Y "{src}" "{dst}" >NUL @@ -216,6 +216,9 @@ if exist "{src}\\*" ( dst = dst_path.replace("/", "\\"), )) + # robocopy return non-zero exit codes on success so we must exit 0 when we are done + cmds.append("exit 0") + ctx.actions.write( output = bat, # Do not use lib/shell.bzl's shell.quote() method, because that uses