Bazel 的选择未被解释
我试图在当前操作系统上设置一个条件(在 Bazel 4.2.2 中):
is_darwin = select({
"@bazel_tools//src/conditions:darwin": True,
"//conditions:default": False,
})
if is_darwin:
# a
else:
# b
但是,即使我在 Linux 上,我也会陷入 a
。
我尝试打印它,但似乎没有被评估:
DEBUG: WORKSPACE:65:6: select({"@bazel_tools//src/conditions:darwin": True, "//conditions:default": False})
我应该如何检查它是否正确?
I'm trying to set a conditional (in Bazel 4.2.2) over the current operating system:
is_darwin = select({
"@bazel_tools//src/conditions:darwin": True,
"//conditions:default": False,
})
if is_darwin:
# a
else:
# b
However I fall into a
, even if I'm on Linux.
I've tried to print it, but it seems to not be evaluated:
DEBUG: WORKSPACE:65:6: select({"@bazel_tools//src/conditions:darwin": True, "//conditions:default": False})
How should I check it correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Select 仅在规则实现函数中进行评估,而不是在您使用的宏中进行评估。您需要使用 attr.bool 创建属性,传递选择它,然后基于它执行你的逻辑。
您还可以使用 ctx.target_platform_has_constraint 直接执行此操作,不带 select:
查看差异的另一种方法是加载 BUILD 文件和运行宏发生在 加载阶段,但评估选择发生在加载和分析阶段之间。相关步骤是:
Select is only evaluated in rule implementation functions, not macros like you're using. You'll need to use attr.bool to create an attribute, pass the select to it, and then perform your logic based on that.
You can also use ctx.target_platform_has_constraint to do this directly, without select:
Another way to look at the difference is that loading BUILD files and running macros happens in the loading phase, but evaluating selects happens between the loading and analysis phases. The relevant steps are: