2

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

有谁知道问题是什么?

4

1 回答 1

3

这是将字符串传递commandrun_shell. 像这样的东西应该工作:

    ctx.actions.run_shell(
        outputs = [dst],
        inputs = [src],
        command = "cp $1 $2",
        arguments = [src.path, dst.path]
    )
于 2020-04-17T04:34:14.330 回答