为什么 Bazel run_shell 没有正确放置参数?

Why is Bazel run_shell not placing arguments correctly?

我有规则a

def _a_impl(ctx):
    src = ctx.actions.declare_file("src.txt")
    ctx.actions.write(src, "nothin")
    dst = ctx.actions.declare_file("dst.txt")
    ctx.actions.run_shell(
        outputs = [dst],
        inputs = [src],
        command = "cp",
        arguments = [src.path, dst.path]
    )
    return [DefaultInfo(files = depset([dst]))]

a = rule(
    implementation = _a_impl,
)

出于某种原因,我收到以下错误:

ERROR: /home/erran/example/out_dir/BUILD:9:1: error executing shell command: '/bin/bash -c cp  bazel-out/k8-fastbuild/bin/src.txt bazel-out/k8-fastbuild/bin/dst.txt' failed (Exit 1) bash failed: error executing command /bin/bash -c cp '' bazel-out/k8-fastbuild/bin/src.txt bazel-out/k8-fastbuild/bin/dst.txt

Bazel 似乎没有正确解析参数。如您所见,实际的 bash 命令尝试 cp '' <src> <dst>

我也试过只格式化复制命令本身,效果很好:

ctx.actions.run_shell(
    outputs = [dst],
    inputs = [src],
    command = "cp {} {}".format(src.path, dst.path)
)

有人知道问题出在哪里吗?

也就是给run_shellcommand参数传字符串的documented semantics。这样的事情应该有效:

    ctx.actions.run_shell(
        outputs = [dst],
        inputs = [src],
        command = "cp  ",
        arguments = [src.path, dst.path]
    )