首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行文件位置替换

运行文件位置替换
EN

Stack Overflow用户
提问于 2017-12-17 22:46:01
回答 1查看 685关注 0票数 2

我正在尝试对cc_binary规则的输出运行qemu。为此,我创建了一个自定义规则,它非常类似于this example,但我希望在cc_binary规则的输出elf文件(":test_portos.elf")上调用qemu,而不是txt-file上的cat命令。我的文件如下:

run_tests.bzl

代码语言:javascript
复制
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)
    },
)

构建

代码语言:javascript
复制
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“运行文件的位置并将其插入到自定义规则的命令中?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-19 20:29:52

似乎运行文件是根据File的short_path进行保护的,所以这就是我需要在run_tests.bzl文件中更改的全部内容:

target = ctx.file.target.short_path

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47856239

复制
相关文章

相似问题

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