首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义规则不生成依赖的目标。

自定义规则不生成依赖的目标。
EN

Stack Overflow用户
提问于 2017-12-13 19:15:06
回答 1查看 822关注 0票数 2

我想在qemu上运行单元测试。我已经创建了一个自定义规则,它用规则中指定的参数调用qemu。其中一个参数是由qemu作为内核使用的qemu文件(规则属性"target")。

当我使用以下命令调用我的自定义规则时,精灵文件("kernel.elf")不会被编译:

代码语言:javascript
复制
 bazel build //test:custom_rule

即使bazel query 'deps(//test:custom_rule)'将目标":kernel.elf“列为依赖项,也会发生这种情况。

此外,我对自定义规则还有另一个问题。当我手动构建":kernel.elf“并在之后调用自定义规则时,qemu告诉我,它无法加载内核文件。手动调用shell中的qemu命令是可行的,所以我想问题不存在于"kernel.elf“文件中。

有人能回答我的问题吗?

提前感谢!

run_tests.bzl

代码语言:javascript
复制
def _impl(ctx):
  qemu = ctx.attr.qemu
  machine = ctx.attr.machine
  cpu = ctx.attr.cpu
  target = ctx.file.target.path
  output = ctx.outputs.out
  # The command may only access files declared in inputs.
  ctx.actions.run_shell(
      arguments = [qemu, machine, cpu, target],
      outputs=[output],
      command="$1 -M $2 -cpu $3 -nographic -monitor null 
               -serial null -semihosting -kernel $4 > %s" % (output.path))


run_tests = rule(
    implementation=_impl,
    attrs = {"qemu" : attr.string(),
             "machine" : attr.string(),
             "cpu" : attr.string(),
             "target" : attr.label(allow_files=True, single_file=True,
                        mandatory=True)},
    outputs={"out": "run_tests.log"}
)

构建

代码语言:javascript
复制
load("//make:run_tests.bzl", "run_tests")

run_tests(
    name = "custom_rule",
    qemu = "qemu-system-arm",
    machine = "xilinx-zynq-a9",
    cpu = "cortex-a9",
    target = ":kernel.elf"
)

cc_binary(
    name = "kernel.elf",
    srcs = glob(["*.cc"]),
    deps = ["//src:portos", 
            "@unity//:unity"],
    copts = ["-Isrc", 
             "-Iexternal/unity/src",
             "-Iexternal/unity/extras/fixture/src"] 
)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-13 19:36:47

问题可能是需要为操作指定输入,请参阅shell.inputs

您还可能需要将qemu作为标签,并将其作为操作的输入(如果这是qemu需要的文件,也需要机器)。

例如,类似:

代码语言:javascript
复制
def _impl(ctx):
  qemu = ctx.attr.qemu
  machine = ctx.attr.machine
  cpu = ctx.attr.cpu
  target = ctx.file.target.path
  output = ctx.outputs.out
  # The command may only access files declared in inputs.
  ctx.actions.run_shell(
      inputs = [qemu, target],
      outputs=[output],
      arguments = [qemu, machine, cpu, target],
      command="$1 -M $2 -cpu $3 -nographic -monitor null 
               -serial null -semihosting -kernel $4 > %s" % (output.path))


run_tests = rule(
    implementation=_impl,
    attrs = {
        "qemu" : attr.label(allow_files=True, single_file=True,
                            mandatory=True),
        "machine" : attr.string(),
        "cpu" : attr.string(),
        "target" : attr.label(allow_files=True, single_file=True,
                              mandatory=True)
    },
    outputs={"out": "run_tests.log"}
)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47800571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档