copy_file: expose the copying logic (#151)
I plan to use these functions in native_binary() and native_test(). See https://github.com/bazelbuild/bazel-skylib/issues/148
This commit is contained in:
parent
6bf6443975
commit
6126842e3d
|
@ -19,8 +19,7 @@ cmd.exe (on Windows). '_copy_xfile' marks the resulting file executable,
|
|||
'_copy_file' does not.
|
||||
"""
|
||||
|
||||
def _common_impl(ctx, is_executable):
|
||||
if ctx.attr.is_windows:
|
||||
def copy_cmd(ctx, src, dst):
|
||||
# Most Windows binaries built with MSVC use a certain argument quoting
|
||||
# scheme. Bazel uses that scheme too to quote arguments. However,
|
||||
# cmd.exe uses different semantics, so Bazel's quoting is wrong here.
|
||||
|
@ -32,31 +31,38 @@ def _common_impl(ctx, is_executable):
|
|||
# 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 = "@copy /Y \"%s\" \"%s\" >NUL" % (
|
||||
ctx.file.src.path.replace("/", "\\"),
|
||||
ctx.outputs.out.path.replace("/", "\\"),
|
||||
src.path.replace("/", "\\"),
|
||||
dst.path.replace("/", "\\"),
|
||||
),
|
||||
is_executable = True,
|
||||
)
|
||||
ctx.actions.run(
|
||||
inputs = [ctx.file.src, bat],
|
||||
outputs = [ctx.outputs.out],
|
||||
inputs = [src, bat],
|
||||
outputs = [dst],
|
||||
executable = "cmd.exe",
|
||||
arguments = ["/C", bat.path.replace("/", "\\")],
|
||||
mnemonic = "CopyFile",
|
||||
progress_message = "Copying files",
|
||||
use_default_shell_env = True,
|
||||
)
|
||||
else:
|
||||
|
||||
def copy_bash(ctx, src, dst):
|
||||
ctx.actions.run_shell(
|
||||
inputs = [ctx.file.src],
|
||||
outputs = [ctx.outputs.out],
|
||||
inputs = [src],
|
||||
outputs = [dst],
|
||||
command = "cp -f \"$1\" \"$2\"",
|
||||
arguments = [ctx.file.src.path, ctx.outputs.out.path],
|
||||
arguments = [src.path, dst.path],
|
||||
mnemonic = "CopyFile",
|
||||
progress_message = "Copying files",
|
||||
use_default_shell_env = True,
|
||||
)
|
||||
|
||||
def _common_impl(ctx, is_executable):
|
||||
if ctx.attr.is_windows:
|
||||
copy_cmd(ctx, ctx.file.src, ctx.outputs.out)
|
||||
else:
|
||||
copy_bash(ctx, ctx.file.src, ctx.outputs.out)
|
||||
|
||||
files = depset(direct = [ctx.outputs.out])
|
||||
runfiles = ctx.runfiles(files = [ctx.outputs.out])
|
||||
if is_executable:
|
||||
|
|
Loading…
Reference in New Issue