为什么Bazel run_shell无法正确放置参数?

时间:2020-04-16 07:52:33

标签: bazel bazel-rules

我有规则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)
)

有人知道是什么问题吗?

1 个答案:

答案 0 :(得分:2)

这是将字符串传递到command的{​​{1}}参数的documented semantics。这样的事情应该起作用:

run_shell
相关问题