【发布时间】:2017-12-03 10:57:51
【问题描述】:
我正在使用 bazel 来构建裸机程序。我想在 qemu 上运行 bazel 生成的单元测试。
qemu-system-* -some_args -kernel bazel-bin/whatever/generated.elf
我尝试通过在“.bzl”文件中创建自己的规则来运行这些,但似乎所有规则操作都必须输出。请注意,我需要根据目标架构调用具有不同参数的不同 qemu 命令。我想将这些传递给规则。
有没有办法在没有任何输出的情况下调用 shell 命令?
如果需要,这是我目前所拥有的(但我不确定哪些部分是正确的,因为 bazel 在分析阶段停止了):
# run_tests.bzl
===============
def _impl(ctx):
qemu = ctx.attr.qemu
machine = ctx.attr.machine
cpu = ctx.attr.cpu
target = ctx.attr.target
# The command may only access files declared in inputs.
ctx.actions.run_shell(
arguments = [qemu, machine, cpu, target],
command="$1 -M $2 -cpu $3 -nographic -monitor null -serial null -semihosting -kernel $4")
run_tests = rule(
implementation=_impl,
attrs = {"qemu" : attr.string(),
"machine" : attr.string(),
"cpu" : attr.string(),
"target" : attr.string(),},
executable = True
)
还有我的构建文件:
# BUILD
=======
load("//make:run_tests.bzl", "run_tests")
run_tests(
name = "portos",
qemu = "qemu-system-arm",
machine = "realview-pbx-a9",
cpu = "cortex-a9",
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"]
)
【问题讨论】: