访问 BUILD 中当前包的标签

huangapple go评论53阅读模式
英文:

Access current package's label in BUILD

问题

有没有办法在BUILD文件中获取当前包的标签?

假设我有这样一个规则调用:

do_x_or_fail(
    name = "foo",
    <...>
    message_on_error = "Incorrect BarBaz setup for " + ?CURRENT_PACKAGE? + ". Check Xyz."
)

我该如何实现?CURRENT_PACKAGE?

我看到有Label()native.package_relative_label()等函数,但我没能直接从BUILD文件中调用它们。

我尝试在BUILD文件中调用native.package_relative_label(),但出现以下错误:name 'native' is not defined

英文:

Is there a way to obtain the current package's label in the BUILD file?

Imagine I have some rule invocation like this:

do_x_or_fail(
    name = &quot;foo&quot;,
    &lt;...&gt;
    message_on_error = &quot;Incorrect BarBaz setup for &quot; + ?CURRENT_PACKAGE? + &quot;. Check Xyz.&quot;
)

How would I implement ?CURRENT_PACKAGE??

I see there are functions like Label() or native.package_relative_label(), but I didn't manage to call them from the BUILD file directly.

I tried calling native.package_relative_label() from a BUILD file. It failed with the following error: name &#39;native&#39; is not defined.

答案1

得分: 2

BUILD文件可以调用package_name()

英文:

BUILD files can invoke package_name().

huangapple
  • 本文由 发表于 2023年7月13日 23:47:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681244.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定