Bazel中的$ location扩展 [英] $location expansion in Bazel
问题描述
我想为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)"],
)
推荐答案
您做对了.
我看了看源代码,您说得对:srcs
,deps
和tools
(如果在规则上定义)被添加到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屋!