bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

fix: allow multiple copy_file in the same package

Open alexeagle opened this issue 2 years ago • 5 comments

Previously this failed on windows, as we wrote colliding batch files

alexeagle avatar Oct 09 '21 19:10 alexeagle

Ping @tetromino

alexeagle avatar Apr 01 '22 15:04 alexeagle

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.

alexeagle avatar Apr 07 '22 20:04 alexeagle

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

tetromino avatar Apr 07 '22 21:04 tetromino

That looks interesting, but it's totally orthogonal to this fix, right?

alexeagle avatar Apr 07 '22 21:04 alexeagle

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,
    )

tetromino avatar Apr 07 '22 21:04 tetromino