获取“ name”'不是定义的(您是指规则吗??)。”在.bzl文件中使用GenRule时出错

发布于 2025-01-30 02:02:48 字数 761 浏览 0 评论 0原文

我可以在文档中看到任何地方,所以问题,github等。人们正在使用genrule而没有任何直接load语句,但是当我尝试在任何.bzl 文件,我会收到以下错误,我找不到解决此问题的方法:

未定义的名称“ genrule”(您的意思是“规则”?)

我尝试过这样的调用:

genrule(
    name = "hello20s",
    outs = ["hello20s.txt"],
    cmd_bash = "sleep 20 && echo 'hello20s' >$@",
)

我尝试用cmd_bashcmd替换运气。我认为这是如何或有什么论点称之为的问题,而是更多的负载或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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄意 2025-02-06 02:02:48

.bzl文件中定义的宏中,需要使用native>本机前缀,例如native> atnation.genrule来引用“内置”规则和功能。

但是,不能在另一个规则实现功能的上下文中调用规则,只有您提及调用ctx.actions.shell时提到这一点。

In macros defined in .bzl files, the "builtin" rules and function need to be referenced with the native prefix, eg native.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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文