运行文件位置替换 [英] Runfiles location substitution

查看:55
本文介绍了运行文件位置替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在cc_binary规则的输出上运行qemu.为此,我创建了一个自定义规则,它非常类似于cat命令.我的文件如下:

I'm trying to run qemu on the output of a cc_binary rule. For that I have created a custom rule, which is pretty similiar to this example, but instead of the cat command on the txt-file, I want to invoke qemu on the output elf-file (":test_portos.elf") of the cc_binary rule. My files are the following:

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"的位置,而不是运行文件的位置.我也尝试过,如示例中所示,将$(location :test_portos.elf)ctx.expand_location一起使用,但结果相同.

The problem is, that in the command (of the custom rule) the location of the ":test_portos.elf" is used and not the location of the runfile. I have also tried, like shown in the example, to use $(location :test_portos.elf) together with ctx.expand_location but the result was the same.

如何获取"test_portos.elf"运行文件的位置并将其插入自定义规则的命令中?

How can I get the location of the "test_portos.elf" runfile and insert it into the command of my custom rule?

推荐答案

似乎根据

Seems that the runfiles are safed according to the short_path of the File, so this was all I needed to change in my run_tests.bzl file:

target = ctx.file.target.short_path

这篇关于运行文件位置替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆