From 76031febac2376a4634396f94c1d0ab9bf799744 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 15:46:02 +0000 Subject: [PATCH] vendor: bump google.golang.org/grpc/cmd/protoc-gen-go-grpc Bumps the golang-dependencies group in /tools with 1 update: [google.golang.org/grpc/cmd/protoc-gen-go-grpc](https://github.com/grpc/grpc-go). Updates `google.golang.org/grpc/cmd/protoc-gen-go-grpc` from 1.3.0 to 1.4.0 - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.3.0...v1.4.0) --- updated-dependencies: - dependency-name: google.golang.org/grpc/cmd/protoc-gen-go-grpc dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang-dependencies ... Signed-off-by: dependabot[bot] --- internal/proto/networkfence_grpc.pb.go | 18 ++- internal/proto/reclaimspace_grpc.pb.go | 18 ++- internal/proto/replication_grpc.pb.go | 30 ++-- tools/go.mod | 2 +- tools/go.sum | 4 +- .../grpc/cmd/protoc-gen-go-grpc/README.md | 4 +- .../grpc/cmd/protoc-gen-go-grpc/grpc.go | 138 ++++++++++++++---- .../grpc/cmd/protoc-gen-go-grpc/main.go | 4 +- .../protoc-gen-go-grpc_test.sh | 50 +++++++ tools/vendor/modules.txt | 4 +- 10 files changed, 220 insertions(+), 52 deletions(-) create mode 100644 tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh diff --git a/internal/proto/networkfence_grpc.pb.go b/internal/proto/networkfence_grpc.pb.go index 12d21258c..65277b4f4 100644 --- a/internal/proto/networkfence_grpc.pb.go +++ b/internal/proto/networkfence_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.3.0 +// - protoc-gen-go-grpc v1.4.0 // - protoc v3.19.6 // source: networkfence.proto @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 const ( NetworkFence_FenceClusterNetwork_FullMethodName = "/proto.NetworkFence/FenceClusterNetwork" @@ -26,6 +26,9 @@ const ( // NetworkFenceClient is the client API for NetworkFence service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// NetworkFence holds the RPC method for allowing the communication between +// the CSIAddons controller and the sidecar for fencing operations. type NetworkFenceClient interface { // FenceClusterNetwork RPC call to fence the cluster network. FenceClusterNetwork(ctx context.Context, in *NetworkFenceRequest, opts ...grpc.CallOption) (*NetworkFenceResponse, error) @@ -42,8 +45,9 @@ func NewNetworkFenceClient(cc grpc.ClientConnInterface) NetworkFenceClient { } func (c *networkFenceClient) FenceClusterNetwork(ctx context.Context, in *NetworkFenceRequest, opts ...grpc.CallOption) (*NetworkFenceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(NetworkFenceResponse) - err := c.cc.Invoke(ctx, NetworkFence_FenceClusterNetwork_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, NetworkFence_FenceClusterNetwork_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -51,8 +55,9 @@ func (c *networkFenceClient) FenceClusterNetwork(ctx context.Context, in *Networ } func (c *networkFenceClient) UnFenceClusterNetwork(ctx context.Context, in *NetworkFenceRequest, opts ...grpc.CallOption) (*NetworkFenceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(NetworkFenceResponse) - err := c.cc.Invoke(ctx, NetworkFence_UnFenceClusterNetwork_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, NetworkFence_UnFenceClusterNetwork_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -62,6 +67,9 @@ func (c *networkFenceClient) UnFenceClusterNetwork(ctx context.Context, in *Netw // NetworkFenceServer is the server API for NetworkFence service. // All implementations must embed UnimplementedNetworkFenceServer // for forward compatibility +// +// NetworkFence holds the RPC method for allowing the communication between +// the CSIAddons controller and the sidecar for fencing operations. type NetworkFenceServer interface { // FenceClusterNetwork RPC call to fence the cluster network. FenceClusterNetwork(context.Context, *NetworkFenceRequest) (*NetworkFenceResponse, error) diff --git a/internal/proto/reclaimspace_grpc.pb.go b/internal/proto/reclaimspace_grpc.pb.go index 459f01682..22154db38 100644 --- a/internal/proto/reclaimspace_grpc.pb.go +++ b/internal/proto/reclaimspace_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.3.0 +// - protoc-gen-go-grpc v1.4.0 // - protoc v3.19.6 // source: reclaimspace.proto @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 const ( ReclaimSpace_ControllerReclaimSpace_FullMethodName = "/proto.ReclaimSpace/ControllerReclaimSpace" @@ -26,6 +26,9 @@ const ( // ReclaimSpaceClient is the client API for ReclaimSpace service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// ReclaimSpace holds the RPC method for allowing the +// communication between the CSIAddons controller and the sidecar. type ReclaimSpaceClient interface { // ControllerReclaimSpace is a procedure that gets called on the CSI // sidecar. @@ -44,8 +47,9 @@ func NewReclaimSpaceClient(cc grpc.ClientConnInterface) ReclaimSpaceClient { } func (c *reclaimSpaceClient) ControllerReclaimSpace(ctx context.Context, in *ReclaimSpaceRequest, opts ...grpc.CallOption) (*ReclaimSpaceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(ReclaimSpaceResponse) - err := c.cc.Invoke(ctx, ReclaimSpace_ControllerReclaimSpace_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ReclaimSpace_ControllerReclaimSpace_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -53,8 +57,9 @@ func (c *reclaimSpaceClient) ControllerReclaimSpace(ctx context.Context, in *Rec } func (c *reclaimSpaceClient) NodeReclaimSpace(ctx context.Context, in *ReclaimSpaceRequest, opts ...grpc.CallOption) (*ReclaimSpaceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(ReclaimSpaceResponse) - err := c.cc.Invoke(ctx, ReclaimSpace_NodeReclaimSpace_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, ReclaimSpace_NodeReclaimSpace_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -64,6 +69,9 @@ func (c *reclaimSpaceClient) NodeReclaimSpace(ctx context.Context, in *ReclaimSp // ReclaimSpaceServer is the server API for ReclaimSpace service. // All implementations must embed UnimplementedReclaimSpaceServer // for forward compatibility +// +// ReclaimSpace holds the RPC method for allowing the +// communication between the CSIAddons controller and the sidecar. type ReclaimSpaceServer interface { // ControllerReclaimSpace is a procedure that gets called on the CSI // sidecar. diff --git a/internal/proto/replication_grpc.pb.go b/internal/proto/replication_grpc.pb.go index 41e8e7fb6..38ba39355 100644 --- a/internal/proto/replication_grpc.pb.go +++ b/internal/proto/replication_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.3.0 +// - protoc-gen-go-grpc v1.4.0 // - protoc v3.19.6 // source: replication.proto @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 const ( Replication_EnableVolumeReplication_FullMethodName = "/proto.Replication/EnableVolumeReplication" @@ -30,6 +30,9 @@ const ( // ReplicationClient is the client API for Replication service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// Replication holds the RPC method for allowing the communication between +// the CSIAddons controller and the sidecar for replication operation. type ReplicationClient interface { // EnableVolumeReplication RPC call to enable the volume replication. EnableVolumeReplication(ctx context.Context, in *EnableVolumeReplicationRequest, opts ...grpc.CallOption) (*EnableVolumeReplicationResponse, error) @@ -54,8 +57,9 @@ func NewReplicationClient(cc grpc.ClientConnInterface) ReplicationClient { } func (c *replicationClient) EnableVolumeReplication(ctx context.Context, in *EnableVolumeReplicationRequest, opts ...grpc.CallOption) (*EnableVolumeReplicationResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(EnableVolumeReplicationResponse) - err := c.cc.Invoke(ctx, Replication_EnableVolumeReplication_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Replication_EnableVolumeReplication_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -63,8 +67,9 @@ func (c *replicationClient) EnableVolumeReplication(ctx context.Context, in *Ena } func (c *replicationClient) DisableVolumeReplication(ctx context.Context, in *DisableVolumeReplicationRequest, opts ...grpc.CallOption) (*DisableVolumeReplicationResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(DisableVolumeReplicationResponse) - err := c.cc.Invoke(ctx, Replication_DisableVolumeReplication_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Replication_DisableVolumeReplication_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -72,8 +77,9 @@ func (c *replicationClient) DisableVolumeReplication(ctx context.Context, in *Di } func (c *replicationClient) PromoteVolume(ctx context.Context, in *PromoteVolumeRequest, opts ...grpc.CallOption) (*PromoteVolumeResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(PromoteVolumeResponse) - err := c.cc.Invoke(ctx, Replication_PromoteVolume_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Replication_PromoteVolume_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -81,8 +87,9 @@ func (c *replicationClient) PromoteVolume(ctx context.Context, in *PromoteVolume } func (c *replicationClient) DemoteVolume(ctx context.Context, in *DemoteVolumeRequest, opts ...grpc.CallOption) (*DemoteVolumeResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(DemoteVolumeResponse) - err := c.cc.Invoke(ctx, Replication_DemoteVolume_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Replication_DemoteVolume_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -90,8 +97,9 @@ func (c *replicationClient) DemoteVolume(ctx context.Context, in *DemoteVolumeRe } func (c *replicationClient) ResyncVolume(ctx context.Context, in *ResyncVolumeRequest, opts ...grpc.CallOption) (*ResyncVolumeResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(ResyncVolumeResponse) - err := c.cc.Invoke(ctx, Replication_ResyncVolume_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Replication_ResyncVolume_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -99,8 +107,9 @@ func (c *replicationClient) ResyncVolume(ctx context.Context, in *ResyncVolumeRe } func (c *replicationClient) GetVolumeReplicationInfo(ctx context.Context, in *GetVolumeReplicationInfoRequest, opts ...grpc.CallOption) (*GetVolumeReplicationInfoResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(GetVolumeReplicationInfoResponse) - err := c.cc.Invoke(ctx, Replication_GetVolumeReplicationInfo_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Replication_GetVolumeReplicationInfo_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -110,6 +119,9 @@ func (c *replicationClient) GetVolumeReplicationInfo(ctx context.Context, in *Ge // ReplicationServer is the server API for Replication service. // All implementations must embed UnimplementedReplicationServer // for forward compatibility +// +// Replication holds the RPC method for allowing the communication between +// the CSIAddons controller and the sidecar for replication operation. type ReplicationServer interface { // EnableVolumeReplication RPC call to enable the volume replication. EnableVolumeReplication(context.Context, *EnableVolumeReplicationRequest) (*EnableVolumeReplicationResponse, error) diff --git a/tools/go.mod b/tools/go.mod index b408f62f7..172c196a2 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/operator-framework/operator-sdk v1.34.2 - google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0 google.golang.org/protobuf v1.34.1 sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240102165319-7f316f1309b1 sigs.k8s.io/controller-tools v0.15.0 diff --git a/tools/go.sum b/tools/go.sum index 50e1022e3..1f324b7d8 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -735,8 +735,8 @@ google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0 h1:9SxA29VM43MF5Z9dQu694wmY5t8E/Gxr7s+RSxiIDmc= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0/go.mod h1:yZOK5zhQMiALmuweVdIVoQPa6eIJyXn2B9g5dJDhqX4= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/README.md b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/README.md index 4758125de..95635ce76 100644 --- a/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/README.md +++ b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/README.md @@ -13,8 +13,8 @@ change from the grpc code generator previously included with `protoc-gen-go`. To restore this behavior, set the option `require_unimplemented_servers=false`. E.g.: -``` - protoc --go-grpc_out=require_unimplemented_servers=false[,other options...]:. \ +```sh + protoc --go-grpc_out=. --go-grpc_opt=require_unimplemented_servers=false[,other options...] \ ``` Note that this is not recommended, and the option is only provided to restore diff --git a/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go index 9e15d2d8d..9088bc2a1 100644 --- a/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go +++ b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go @@ -52,6 +52,10 @@ func (serviceGenerateHelper) formatFullMethodSymbol(service *protogen.Service, m } func (serviceGenerateHelper) genFullMethods(g *protogen.GeneratedFile, service *protogen.Service) { + if len(service.Methods) == 0 { + return + } + g.P("const (") for _, method := range service.Methods { fmSymbol := helper.formatFullMethodSymbol(service, method) @@ -170,14 +174,30 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. g.P("// This is a compile-time assertion to ensure that this generated file") g.P("// is compatible with the grpc package it is being compiled against.") - g.P("// Requires gRPC-Go v1.32.0 or later.") - g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion7")) // When changing, update version number above. + if *useGenericStreams { + g.P("// Requires gRPC-Go v1.64.0 or later.") + g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion9")) + } else { + g.P("// Requires gRPC-Go v1.62.0 or later.") + g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion8")) // When changing, update version number above. + } g.P() for _, service := range file.Services { genService(gen, file, g, service) } } +// genServiceComments copies the comments from the RPC proto definitions +// to the corresponding generated interface file. +func genServiceComments(g *protogen.GeneratedFile, service *protogen.Service) { + if service.Comments.Leading != "" { + // Add empty comment line to attach this service's comments to + // the godoc comments previously output for all services. + g.P("//") + g.P(strings.TrimSpace(service.Comments.Leading.String())) + } +} + func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service) { // Full methods constants. helper.genFullMethods(g, service) @@ -189,14 +209,17 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P("//") g.P("// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.") + // Copy comments from proto file. + genServiceComments(g, service) + if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { g.P("//") g.P(deprecationComment) } - g.Annotate(clientName, service.Location) + g.AnnotateSymbol(clientName, protogen.Annotation{Location: service.Location}) g.P("type ", clientName, " interface {") for _, method := range service.Methods { - g.Annotate(clientName+"."+method.GoName, method.Location) + g.AnnotateSymbol(clientName+"."+method.GoName, protogen.Annotation{Location: method.Location}) if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() { g.P(deprecationComment) } @@ -242,14 +265,18 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P("// ", serverType, " is the server API for ", service.GoName, " service.") g.P("// All implementations ", mustOrShould, " embed Unimplemented", serverType) g.P("// for forward compatibility") + + // Copy comments from proto file. + genServiceComments(g, service) + if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { g.P("//") g.P(deprecationComment) } - g.Annotate(serverType, service.Location) + g.AnnotateSymbol(serverType, protogen.Annotation{Location: service.Location}) g.P("type ", serverType, " interface {") for _, method := range service.Methods { - g.Annotate(serverType+"."+method.GoName, method.Location) + g.AnnotateSymbol(serverType+"."+method.GoName, protogen.Annotation{Location: method.Location}) if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() { g.P(deprecationComment) } @@ -295,12 +322,27 @@ func clientSignature(g *protogen.GeneratedFile, method *protogen.Method) string if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { s += "*" + g.QualifiedGoIdent(method.Output.GoIdent) } else { - s += method.Parent.GoName + "_" + method.GoName + "Client" + if *useGenericStreams { + s += clientStreamInterface(g, method) + } else { + s += method.Parent.GoName + "_" + method.GoName + "Client" + } } s += ", error)" return s } +func clientStreamInterface(g *protogen.GeneratedFile, method *protogen.Method) string { + typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) + if method.Desc.IsStreamingClient() && method.Desc.IsStreamingServer() { + return g.QualifiedGoIdent(grpcPackage.Ident("BidiStreamingClient")) + "[" + typeParam + "]" + } else if method.Desc.IsStreamingClient() { + return g.QualifiedGoIdent(grpcPackage.Ident("ClientStreamingClient")) + "[" + typeParam + "]" + } else { // i.e. if method.Desc.IsStreamingServer() + return g.QualifiedGoIdent(grpcPackage.Ident("ServerStreamingClient")) + "[" + g.QualifiedGoIdent(method.Output.GoIdent) + "]" + } +} + func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, method *protogen.Method, index int) { service := method.Parent fmSymbol := helper.formatFullMethodSymbol(service, method) @@ -309,20 +351,27 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene g.P(deprecationComment) } g.P("func (c *", unexport(service.GoName), "Client) ", clientSignature(g, method), "{") + g.P("cOpts := append([]", grpcPackage.Ident("CallOption"), "{", grpcPackage.Ident("StaticMethod()"), "}, opts...)") if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() { g.P("out := new(", method.Output.GoIdent, ")") - g.P(`err := c.cc.Invoke(ctx, `, fmSymbol, `, in, out, opts...)`) + g.P(`err := c.cc.Invoke(ctx, `, fmSymbol, `, in, out, cOpts...)`) g.P("if err != nil { return nil, err }") g.P("return out, nil") g.P("}") g.P() return } - streamType := unexport(service.GoName) + method.GoName + "Client" + + streamImpl := unexport(service.GoName) + method.GoName + "Client" + if *useGenericStreams { + typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) + streamImpl = g.QualifiedGoIdent(grpcPackage.Ident("GenericClientStream")) + "[" + typeParam + "]" + } + serviceDescVar := service.GoName + "_ServiceDesc" - g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], `, fmSymbol, `, opts...)`) + g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], `, fmSymbol, `, cOpts...)`) g.P("if err != nil { return nil, err }") - g.P("x := &", streamType, "{stream}") + g.P("x := &", streamImpl, "{ClientStream: stream}") if !method.Desc.IsStreamingClient() { g.P("if err := x.ClientStream.SendMsg(in); err != nil { return nil, err }") g.P("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }") @@ -331,11 +380,20 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene g.P("}") g.P() + // Auxiliary types aliases, for backwards compatibility. + if *useGenericStreams { + g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.") + g.P("type ", service.GoName, "_", method.GoName, "Client = ", clientStreamInterface(g, method)) + g.P() + return + } + + // Stream auxiliary types and methods, if we're not taking advantage of the + // pre-implemented generic types and their methods. genSend := method.Desc.IsStreamingClient() genRecv := method.Desc.IsStreamingServer() genCloseAndRecv := !method.Desc.IsStreamingServer() - // Stream auxiliary types and methods. g.P("type ", service.GoName, "_", method.GoName, "Client interface {") if genSend { g.P("Send(*", method.Input.GoIdent, ") error") @@ -350,19 +408,19 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene g.P("}") g.P() - g.P("type ", streamType, " struct {") + g.P("type ", streamImpl, " struct {") g.P(grpcPackage.Ident("ClientStream")) g.P("}") g.P() if genSend { - g.P("func (x *", streamType, ") Send(m *", method.Input.GoIdent, ") error {") + g.P("func (x *", streamImpl, ") Send(m *", method.Input.GoIdent, ") error {") g.P("return x.ClientStream.SendMsg(m)") g.P("}") g.P() } if genRecv { - g.P("func (x *", streamType, ") Recv() (*", method.Output.GoIdent, ", error) {") + g.P("func (x *", streamImpl, ") Recv() (*", method.Output.GoIdent, ", error) {") g.P("m := new(", method.Output.GoIdent, ")") g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }") g.P("return m, nil") @@ -370,7 +428,7 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene g.P() } if genCloseAndRecv { - g.P("func (x *", streamType, ") CloseAndRecv() (*", method.Output.GoIdent, ", error) {") + g.P("func (x *", streamImpl, ") CloseAndRecv() (*", method.Output.GoIdent, ", error) {") g.P("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }") g.P("m := new(", method.Output.GoIdent, ")") g.P("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }") @@ -391,7 +449,11 @@ func serverSignature(g *protogen.GeneratedFile, method *protogen.Method) string reqArgs = append(reqArgs, "*"+g.QualifiedGoIdent(method.Input.GoIdent)) } if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() { - reqArgs = append(reqArgs, method.Parent.GoName+"_"+method.GoName+"Server") + if *useGenericStreams { + reqArgs = append(reqArgs, serverStreamInterface(g, method)) + } else { + reqArgs = append(reqArgs, method.Parent.GoName+"_"+method.GoName+"Server") + } } return method.GoName + "(" + strings.Join(reqArgs, ", ") + ") " + ret } @@ -437,6 +499,17 @@ func genServiceDesc(file *protogen.File, g *protogen.GeneratedFile, serviceDescV g.P() } +func serverStreamInterface(g *protogen.GeneratedFile, method *protogen.Method) string { + typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) + if method.Desc.IsStreamingClient() && method.Desc.IsStreamingServer() { + return g.QualifiedGoIdent(grpcPackage.Ident("BidiStreamingServer")) + "[" + typeParam + "]" + } else if method.Desc.IsStreamingClient() { + return g.QualifiedGoIdent(grpcPackage.Ident("ClientStreamingServer")) + "[" + typeParam + "]" + } else { // i.e. if method.Desc.IsStreamingServer() + return g.QualifiedGoIdent(grpcPackage.Ident("ServerStreamingServer")) + "[" + g.QualifiedGoIdent(method.Output.GoIdent) + "]" + } +} + func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, method *protogen.Method, hnameFuncNameFormatter func(string) string) string { service := method.Parent hname := fmt.Sprintf("_%s_%s_Handler", service.GoName, method.GoName) @@ -459,23 +532,38 @@ func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene g.P() return hname } - streamType := unexport(service.GoName) + method.GoName + "Server" + + streamImpl := unexport(service.GoName) + method.GoName + "Server" + if *useGenericStreams { + typeParam := g.QualifiedGoIdent(method.Input.GoIdent) + ", " + g.QualifiedGoIdent(method.Output.GoIdent) + streamImpl = g.QualifiedGoIdent(grpcPackage.Ident("GenericServerStream")) + "[" + typeParam + "]" + } + g.P("func ", hnameFuncNameFormatter(hname), "(srv interface{}, stream ", grpcPackage.Ident("ServerStream"), ") error {") if !method.Desc.IsStreamingClient() { g.P("m := new(", method.Input.GoIdent, ")") g.P("if err := stream.RecvMsg(m); err != nil { return err }") - g.P("return srv.(", service.GoName, "Server).", method.GoName, "(m, &", streamType, "{stream})") + g.P("return srv.(", service.GoName, "Server).", method.GoName, "(m, &", streamImpl, "{ServerStream: stream})") } else { - g.P("return srv.(", service.GoName, "Server).", method.GoName, "(&", streamType, "{stream})") + g.P("return srv.(", service.GoName, "Server).", method.GoName, "(&", streamImpl, "{ServerStream: stream})") } g.P("}") g.P() + // Auxiliary types aliases, for backwards compatibility. + if *useGenericStreams { + g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.") + g.P("type ", service.GoName, "_", method.GoName, "Server = ", serverStreamInterface(g, method)) + g.P() + return hname + } + + // Stream auxiliary types and methods, if we're not taking advantage of the + // pre-implemented generic types and their methods. genSend := method.Desc.IsStreamingServer() genSendAndClose := !method.Desc.IsStreamingServer() genRecv := method.Desc.IsStreamingClient() - // Stream auxiliary types and methods. g.P("type ", service.GoName, "_", method.GoName, "Server interface {") if genSend { g.P("Send(*", method.Output.GoIdent, ") error") @@ -490,25 +578,25 @@ func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene g.P("}") g.P() - g.P("type ", streamType, " struct {") + g.P("type ", streamImpl, " struct {") g.P(grpcPackage.Ident("ServerStream")) g.P("}") g.P() if genSend { - g.P("func (x *", streamType, ") Send(m *", method.Output.GoIdent, ") error {") + g.P("func (x *", streamImpl, ") Send(m *", method.Output.GoIdent, ") error {") g.P("return x.ServerStream.SendMsg(m)") g.P("}") g.P() } if genSendAndClose { - g.P("func (x *", streamType, ") SendAndClose(m *", method.Output.GoIdent, ") error {") + g.P("func (x *", streamImpl, ") SendAndClose(m *", method.Output.GoIdent, ") error {") g.P("return x.ServerStream.SendMsg(m)") g.P("}") g.P() } if genRecv { - g.P("func (x *", streamType, ") Recv() (*", method.Input.GoIdent, ", error) {") + g.P("func (x *", streamImpl, ") Recv() (*", method.Input.GoIdent, ", error) {") g.P("m := new(", method.Input.GoIdent, ")") g.P("if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err }") g.P("return m, nil") diff --git a/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go index 340eaf3ee..0cb6a0212 100644 --- a/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go +++ b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go @@ -41,9 +41,10 @@ import ( "google.golang.org/protobuf/types/pluginpb" ) -const version = "1.3.0" +const version = "1.4.0" var requireUnimplemented *bool +var useGenericStreams *bool func main() { showVersion := flag.Bool("version", false, "print the version and exit") @@ -55,6 +56,7 @@ func main() { var flags flag.FlagSet requireUnimplemented = flags.Bool("require_unimplemented_servers", true, "set to false to match legacy behavior") + useGenericStreams = flags.Bool("use_generic_streams_experimental", false, "set to true to use generic types for streaming client and server objects; this flag is EXPERIMENTAL and may be changed or removed in a future release") protogen.Options{ ParamFunc: flags.Set, diff --git a/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh new file mode 100644 index 000000000..32e8e26ec --- /dev/null +++ b/tools/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/protoc-gen-go-grpc_test.sh @@ -0,0 +1,50 @@ +#!/bin/bash -e + +# Copyright 2024 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Uncomment to enable debugging. +# set -x + +WORKDIR="$(dirname $0)" +TEMPDIR=$(mktemp -d) + +trap "rm -rf ${TEMPDIR}" EXIT + +# Build protoc-gen-go-grpc binary and add to $PATH. +pushd "${WORKDIR}" +go build -o "${TEMPDIR}" . +PATH="${TEMPDIR}:${PATH}" +popd + +protoc \ + --go-grpc_out="${TEMPDIR}" \ + --go-grpc_opt=paths=source_relative,use_generic_streams_experimental=true \ + "examples/route_guide/routeguide/route_guide.proto" + +GOLDENFILE="examples/route_guide/routeguide/route_guide_grpc.pb.go" +GENFILE="${TEMPDIR}/examples/route_guide/routeguide/route_guide_grpc.pb.go" + +# diff is piped to [[ $? == 1 ]] to avoid exiting on diff but exit on error +# (like if the file was not found). See man diff for more info. +DIFF=$(diff "${GOLDENFILE}" "${GENFILE}" || [[ $? == 1 ]]) +if [[ -n "${DIFF}" ]]; then + echo -e "ERROR: Generated file differs from golden file:\n${DIFF}" + echo -e "If you have made recent changes to protoc-gen-go-grpc," \ + "please regenerate the golden files by running:" \ + "\n\t go generate google.golang.org/grpc/..." >&2 + exit 1 +fi + +echo SUCCESS diff --git a/tools/vendor/modules.txt b/tools/vendor/modules.txt index 5c1753d3e..77013cf5e 100644 --- a/tools/vendor/modules.txt +++ b/tools/vendor/modules.txt @@ -1201,8 +1201,8 @@ google.golang.org/grpc/serviceconfig google.golang.org/grpc/stats google.golang.org/grpc/status google.golang.org/grpc/tap -# google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 -## explicit; go 1.17 +# google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0 +## explicit; go 1.21 google.golang.org/grpc/cmd/protoc-gen-go-grpc # google.golang.org/protobuf v1.34.1 ## explicit; go 1.17