bazel-skylib
bazel-skylib copied to clipboard
fix: allow multiple copy_file in the same package
Previously this failed on windows, as we wrote colliding batch files
Ping @tetromino
Yes I mentioned it in https://github.com/bazelbuild/bazel-skylib/pull/324#discussion_r840723348 the particular rule in this case is https://github.com/bazelbuild/rules_nodejs/blob/stable/internal/js_library/js_library.bzl#L34-L38
Granted, that rule uses the private API of copy_file
and therefore there's no support guarantee for doing this. You could just say no. However I think it's nice to fix it anyway.
I'm wondering if we should instead bite the bullet and fix run_shell
to support .bat and powershell commands. Then we wouldn't need to write temporary bat files at all, here and elsewhere.
Wrote up my thoughts in https://github.com/bazelbuild/bazel/issues/15194
That looks interesting, but it's totally orthogonal to this fix, right?
If run_shell
supported command_bat
, we wouldn't need copy_cmd and copy_bat at all: the implementation would be unified into
args = ctx.actions.args()
args.add_all(src.path, dst.path)
ctx.actions.run_shell(
tools = [src],
outputs = [dst],
command = "cp -f \"$1\" \"$2\"",
command_bat = "copy /Y \"%1\" \"%2\" >NUL",
arguments = [args],
mnemonic = "CopyFile",
progress_message = "Copying files",
use_default_shell_env = True,
)