Skip to content

Commit 11bdf92

Browse files
authored
fix(bazel): allow CustomProtoInfo in gapic_compat_proto_library (#18417)
In #17882 gapic_compat_proto_library was introduced to wrap srcs passed to py_gapic_library and adapt modern @rules_proto StarlarkProtoInfo (ProtoInfo) targets into CustomProtoInfo expected by @rules_gapic//:gapic.bzl's proto_custom_library. However, several targets pass `srcs = [":<api>_proto_with_info"]` (a proto_library_with_info rule from @rules_gapic//:gapic.bzl which returns CustomProtoInfo rather than StarlarkProtoInfo). Because gapic_compat_proto_library strictly mandated `providers = [StarlarkProtoInfo]`, Bazel analysis failed on those targets with: `'<target>_proto_with_info' does not have mandatory providers: 'ProtoInfo'`. Updated gapic_compat_proto_library_impl to check if CustomProtoInfo in dep: and return [dep[DefaultInfo], dep[CustomProtoInfo]] directly without re-wrapping. Updated gapic_compat_proto_library attrs["dep"] to accept either provider: providers = [[StarlarkProtoInfo], [CustomProtoInfo]]. Tested against several afflicted targets in googleapis manually and running entire workspace presubmit in cl/983453303. Fixes regression blocking b/559815865.
1 parent 773373e commit 11bdf92

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

packages/gapic-generator/rules_python_gapic/py_gapic.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ load("@rules_proto//proto:defs.bzl", StarlarkProtoInfo = "ProtoInfo")
2525
# into rules_gapic CustomProtoInfo provider required by proto_custom_library.
2626
def _gapic_compat_proto_library_impl(ctx):
2727
dep = ctx.attr.dep
28+
if CustomProtoInfo in dep:
29+
return [
30+
dep[DefaultInfo],
31+
dep[CustomProtoInfo],
32+
]
2833
starlark_proto = dep[StarlarkProtoInfo]
2934
return [
3035
dep[DefaultInfo],
@@ -41,7 +46,7 @@ def _gapic_compat_proto_library_impl(ctx):
4146
gapic_compat_proto_library = rule(
4247
implementation = _gapic_compat_proto_library_impl,
4348
attrs = {
44-
"dep": attr.label(mandatory = True, providers = [StarlarkProtoInfo]),
49+
"dep": attr.label(mandatory = True, providers = [[StarlarkProtoInfo], [CustomProtoInfo]]),
4550
}
4651
)
4752

0 commit comments

Comments
 (0)