获取“ name”'不是定义的(您是指规则吗??)。”在.bzl文件中使用GenRule时出错
我可以在文档中看到任何地方,所以问题,github等。人们正在使用genrule
而没有任何直接load
语句,但是当我尝试在任何.bzl 文件,我会收到以下错误,我找不到解决此问题的方法:
未定义的名称“ genrule”(您的意思是“规则”?)
我尝试过这样的调用:
genrule(
name = "hello20s",
outs = ["hello20s.txt"],
cmd_bash = "sleep 20 && echo 'hello20s' >$@",
)
我尝试用cmd_bash
用cmd
替换运气。我认为这是如何或有什么论点称之为的问题,而是更多的负载或ENV问题。有什么想法吗?
我可以补充说,我能够使用ctx.actions.run_shell
在同一.bzl
文件中运行类似的命令,所以到目前为止,我唯一的小故障是它没有具体识别genrule
。
$ BAZEL VERSON
Bazelisk版本:开发
构建标签:5.1.1
OS:MACOS 12.3.1
I can see everywhere in docs, SO questions, github, etc. that people are using genrule
without any direct load
statement, but when I try to use it in any .bzl
file, I get the following error and I could not find out how to resolve this:
name 'genrule' is not defined (did you mean 'rule'?)
I've tried calling it like this:
genrule(
name = "hello20s",
outs = ["hello20s.txt"],
cmd_bash = "sleep 20 && echo 'hello20s' >$@",
)
and I tried to replace cmd_bash
with cmd
and had no luck either. I don't think it is a matter of how or with what arguments to call it, but more load or env issue. Any ideas?
I can add, that I'm able to run similar commands using ctx.actions.run_shell
within the same .bzl
file, so the only glitch I have so far is that it doesn't recognize genrule
specifically.
$ bazel verson
Bazelisk version: development
Build label: 5.1.1
OS: macOS 12.3.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
.bzl
文件中定义的宏中,需要使用native>本机
前缀,例如native> atnation.genrule
来引用“内置”规则和功能。但是,不能在另一个规则实现功能的上下文中调用规则,只有您提及调用
ctx.actions.shell
时提到这一点。In macros defined in
.bzl
files, the "builtin" rules and function need to be referenced with thenative
prefix, egnative.genrule
.However, rules can't be called in the context of another rules implementation function, only mention this as you mention calling
ctx.actions.shell