问题
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)"],
)
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))
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.
Full target:
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)"],
)
回答1:
You're doing it right.
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)
.
来源:https://stackoverflow.com/questions/43982762/location-expansion-in-bazel