Bazel中的$ location扩展 [英] $location expansion in Bazel

查看:207
本文介绍了Bazel中的$ location扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为jvm_flags属性在rules_scala中添加$(location)扩展名,在其中我在data属性中设置了依赖项,但失败了:
label '//src/java/com/google/devtools/build/lib:worker' in $(location) expression is not a declared prerequisite of this rule.
我在目标中的data属性中的标签上定义了依赖项,如下所示:

I want to add $(location) expansion to rules_scala for jvm_flags attribute where I set the dependency in the data attribute but that fails with:
label '//src/java/com/google/devtools/build/lib:worker' in $(location) expression is not a declared prerequisite of this rule.
I define a dependency in my target on that label in the data attribute like this:

scala_specs2_junit_test(
    ...
    data = ["//src/java/com/google/devtools/build/lib:worker"],
    jvm_flags = ["-XX:HeapDumpPath=/some/custom/path", "-Dlocation.expanded=$(location //src/java/com/google/devtools/build/lib:worker)"],
)

我看到,当我在expand_location调用扩展中添加ctx.attr.data时,可以正常工作,但我不确定为什么不是黑客. data确实是特例吗?

I saw that when I add ctx.attr.data to the expand_location call expansion works but I wasn't really sure why this is not a hack. Is data indeed a special case?

    location_expanded_jvm_flags = []
    for jvm_flag in jvm_flags:
        location_expanded_jvm_flags.append(ctx.expand_location(jvm_flag, ctx.attr.data))

还尝试查看java_*规则源以了解其工作原理(由于$(location)扩展支持data属性),但找不到相关的位置.

Also tried looking in the java_* rules sources to see how this works (since $(location) expansion there supports the data attribute) but couldn't find the relevant place.

完整目标:

scala_specs2_junit_test(
    name = "Specs2Tests",
    srcs = ["src/main/scala/scala/test/junit/specs2/Specs2Tests.scala"],
    deps = [":JUnitCompileTimeDep"],
    size = "small",
    suffixes = ["Test"],
    data = ["//src/java/com/google/devtools/build/lib:worker"],
    jvm_flags = ["-XX:HeapDumpPath=/some/custom/path", "-Dlocation.expanded=$(location //src/java/com/google/devtools/build/lib:worker)"],
)

推荐答案

您做对了.

我看了看源代码,您说得对:srcsdepstools(如果在规则上定义)被添加到expand_locations可以理解的标签集中.仅当

I looked at the source code and you're right: srcs, deps, and tools (if defined on the rule) are added to the set of labels that expand_locations understands. data is added only if LocationExpander is created with allowDataAttributeEntriesInLabel=true, which it isn't. That's why you must add it to expand_locations(targets).

这篇关于Bazel中的$ location扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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