bazel - 如何从 repository_ctx 运行 bazel 二进制可执行文件
问题描述
在 Bazel 中,是否有一种等效的方法来运行如下所述的二进制可执行文件,但在repository_rule
实现函数中使用 repository_ctx?
# def _impl
ctx.actions.run(
...
executable = ctx.executable.foo_binary,
)
# Is doing the ff also possible for a repository_rule?
bar = rule(
implementation = _impl,
attrs = {
"foo_binary": attr.label(
default = Label("//actions_run:foo"),
executable = True,
cfg = "exec",
allow_files = True,
),
},
)
repository_ctx的文档表明有一个execute()
函数,但我不确定如何使用它运行另一个 bazel 构建的二进制文件。任何示例都会有所帮助。
PS:我是Bazel的新手。如果这不是目的,请重定向repository_ctx.execute
。
解决方案
repository_ctx.execute()
相似但不一样...根本区别在于它们何时发生。
repository_ctx
可用于存储库规则的实施:
外部存储库是只能在 WORKSPACE 文件中使用的规则,并在 Bazel 的加载阶段启用非封闭操作
换句话说。repository_ctx.execute()
确实是为了在您的主机上运行(非密封)工具(当然可以位于存储库中),但这仍然是在从树构建任何东西并且可以访问执行之前。如果可执行文件在 repo 树中,您可以通过标签引用它(它将被解析),但它必须已经可用。
推荐阅读
- java - java将java httpClient参数注入自动装配的类构造函数
- javascript - 如何在 vega-lite 中更改饼图文本标签的颜色
- angular - 如何动态更改离子手势参考元素
- kubernetes - amazon-efs 失败,服务器给出的原因:没有这样的文件或目录
- python - 模型实例设置 || 未找到带有参数 '('',)' 的 '' 的反向操作。已尝试 1 种模式
- json - JSONDecodeError:期望','分隔符:第 9051348 行第 27 列(字符 226492416)
- java - 如何将两个不同的数组变成一个二维数组
- apache-kafka - 未提交消息的计数 kafka
- php - 如何以多页重力形式将用户重定向到最后一页
- xamarin.forms - Xamarin.Forms.Svg.SvgImageSource.FromSvgUri() 不适用于 file:// URI