如何使Bazel Genrule访问传递依赖性?
我在build
文件中有以下内容:
proto_library(
name = "proto_default_library",
srcs = glob(["*.proto"]),
visibility = ["//visibility:public"],
deps = [
"@go_googleapis//google/api:annotations_proto",
"@grpc_ecosystem_grpc_gateway//protoc-gen-openapiv2/options:options_proto",
],
)
genrule(
name = "generate-buf-image",
srcs = [
":buf_yaml",
":buf_breaking_image_json",
":protos",
],
exec_tools = [
":proto_default_library",
"//buf:generate-buf-image-sh",
"//buf:generate-buf-image",
],
outs = ["buf-image.json"],
cmd = "$(location //buf:generate-buf-image-sh) --buf-breaking-image-json=$(location :buf_breaking_image_json) $(location :protos) >$@",
)
执行$(位置// buf:generate-buf-image-sh)
,glob([[“*)。 proto“])
proto_default_library
可以在沙盒中看到,但是@go_googleapis // good>@go_googleapis // google/api:annotations_proto
和@grpc_ecosystem_grpc_gatewayway // protoc-gen-openapiv2/options:options_proto
不能。 // buf的依赖项也是如此:生成buf-image-sh
。
我是否需要明确列出所有传递依赖项,以便可以通过生成buf-image
处理它们?有没有程序化的方法?
I have the following in a BUILD
file:
proto_library(
name = "proto_default_library",
srcs = glob(["*.proto"]),
visibility = ["//visibility:public"],
deps = [
"@go_googleapis//google/api:annotations_proto",
"@grpc_ecosystem_grpc_gateway//protoc-gen-openapiv2/options:options_proto",
],
)
genrule(
name = "generate-buf-image",
srcs = [
":buf_yaml",
":buf_breaking_image_json",
":protos",
],
exec_tools = [
":proto_default_library",
"//buf:generate-buf-image-sh",
"//buf:generate-buf-image",
],
outs = ["buf-image.json"],
cmd = "$(location //buf:generate-buf-image-sh) --buf-breaking-image-json=$(location :buf_breaking_image_json) $(location :protos) >$@",
)
While executing $(location //buf:generate-buf-image-sh)
, glob(["*.proto"])
of proto_default_library
can be seen in the sandbox but the proto files of @go_googleapis//google/api:annotations_proto
and @grpc_ecosystem_grpc_gateway//protoc-gen-openapiv2/options:options_proto
cannot. The same goes for the dependencies of //buf:generate-buf-image-sh
.
Do I need to explicitly list out all transitive dependencies so they can be processed by generate-buf-image
? Is there a programmatic way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于Genrules非常通用,因此Genrule仅看到目标的默认提供商,该提供商通常只有该目标的主要输出(例如,对于Java_library,该库中的一罐该库,对于Proto_library,对于proto_library来说图书馆)。因此,要获取更详细的信息,您将编写一项Starlark规则以访问更多特定的提供商。例如:
workspace
:defs.bzl
:protoinfo
在这里: https://bazel.build/rules/lib/lib/protoinfo构建
:proto_a.a.proto :
proto_b.proto
:proto_c.proto
:tool.sh
:Since genrules are pretty generic, a genrule sees only the default provider of a target, which usually just has the main outputs of that target (e.g., for java_library, a jar of the classes of that library, for proto_library, the proto files of that library). So to get more detailed information, you would write a Starlark rule to access more specific providers. For example:
WORKSPACE
:defs.bzl
:ProtoInfo
is here: https://bazel.build/rules/lib/ProtoInfoBUILD
:proto_a.proto
:proto_b.proto
:proto_c.proto
:tool.sh
: