我正在尝试对cc_binary规则的输出运行qemu。为此,我创建了一个自定义规则,它非常类似于this example,但我希望在cc_binary规则的输出elf文件(":test_portos.elf")上调用qemu,而不是txt-file上的cat命令。我的文件如下:
run_tests.bzl
def _impl(ctx):
# The path of ctx.file.target.path is:
'bazel-out/cortex-a9-fastbuild/bin/test/test_portos.elf'
target = ctx.file.target.path
command = "qemu-system-arm -M xilinx-zynq-a9 -cpu cortex-a9 -nographic
-monitor null -serial null -semihosting
-kernel %s" % (target)
ctx.actions.write(
output=ctx.outputs.executable,
content=command,
is_executable=True)
return [DefaultInfo(
runfiles=ctx.runfiles(files=[ctx.file.target])
)]
execute = rule(
implementation=_impl,
executable=True,
attrs={
"command": attr.string(),
"target" : attr.label(cfg="data", allow_files=True,
single_file=True, mandatory=True)
},
)构建
load("//make:run_tests.bzl", "execute")
execute(
name = "portos",
target = ":test_portos.elf"
)
cc_binary(
name = "test_portos.elf",
srcs = glob(["*.cc"]),
deps = ["//src:portos",
"@unity//:unity"],
copts = ["-Isrc",
"-Iexternal/unity/src",
"-Iexternal/unity/extras/fixture/src"]
)问题是,在(自定义规则的)命令中,使用的是":test_portos.elf“的位置,而不是运行文件的位置。我也尝试过(如example中所示)将$(location :test_portos.elf)与ctx.expand_location一起使用,但结果是相同的。
如何获取"test_portos.elf“运行文件的位置并将其插入到自定义规则的命令中?
发布于 2017-12-19 20:29:52
似乎运行文件是根据File的short_path进行保护的,所以这就是我需要在run_tests.bzl文件中更改的全部内容:
target = ctx.file.target.short_path
https://stackoverflow.com/questions/47856239
复制相似问题