Skip to content

Commit 7499c62

Browse files
committed
chore: refactor gengapic protov2
* refactor gencli protov2 * remove last remnants * update test script and ci * update bazel deps to proto go v2 * remove unnecessary wkt resolution directives
1 parent 7fdb7aa commit 7499c62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+927
-929
lines changed

.github/workflows/ci.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ jobs:
6666
- name: Install tools and dependencies
6767
run: |
6868
go install golang.org/x/exp/cmd/apidiff@latest
69-
go install github.com/golang/protobuf/protoc-gen-go@latest
69+
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
70+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
7071
curl -sSL https://github.com/googleapis/googleapis/archive/master.zip > googleapis.zip
7172
unzip googleapis.zip -x "googleapis-master/google/ads/*"
7273
mv googleapis-master /tmp/googleapis

BUILD

-7
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,3 @@ gazelle(name = "gazelle")
1111
# gazelle:resolve proto go google/api/annotations.proto @org_golang_google_genproto//googleapis/api/annotations
1212
# gazelle:resolve proto proto google/longrunning/operations.proto @com_google_googleapis//google/longrunning:operations_proto
1313
# gazelle:resolve proto go google/longrunning/operations.proto @com_google_googleapis//google/longrunning:longrunning_go_proto
14-
15-
# Note: Direct gazelle to resolve the protobuf-go v1 module to rules_go well
16-
# known types. This will be removed when we migrate to protobuf-go v2.
17-
#
18-
# gazelle:resolve go go github.com/golang/protobuf/protoc-gen-go/plugin @io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto
19-
# gazelle:resolve go go github.com/golang/protobuf/protoc-gen-go/descriptor @io_bazel_rules_go//proto/wkt:descriptor_go_proto
20-
# gazelle:resolve go go github.com/golang/protobuf/ptypes/duration @io_bazel_rules_go//proto/wkt:duration_go_proto

cmd/protoc-gen-go_cli/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ go_library(
88
visibility = ["//visibility:private"],
99
deps = [
1010
"//internal/gencli",
11-
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
1211
"@org_golang_google_protobuf//proto",
12+
"@org_golang_google_protobuf//types/pluginpb",
1313
],
1414
)
1515

cmd/protoc-gen-go_cli/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ import (
1919
"log"
2020
"os"
2121

22-
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
2322
"github.com/googleapis/gapic-generator-go/internal/gencli"
2423
"google.golang.org/protobuf/proto"
24+
"google.golang.org/protobuf/types/pluginpb"
2525
)
2626

2727
func main() {
2828
reqBytes, err := io.ReadAll(os.Stdin)
2929
if err != nil {
3030
log.Fatal(err)
3131
}
32-
var genReq plugin.CodeGeneratorRequest
32+
var genReq pluginpb.CodeGeneratorRequest
3333
if err := proto.Unmarshal(reqBytes, &genReq); err != nil {
3434
log.Fatal(err)
3535
}
@@ -38,7 +38,7 @@ func main() {
3838
if err != nil {
3939
genResp.Error = proto.String(err.Error())
4040
}
41-
genResp.SupportedFeatures = proto.Uint64(uint64(plugin.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL))
41+
genResp.SupportedFeatures = proto.Uint64(uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL))
4242

4343
outBytes, err := proto.Marshal(genResp)
4444
if err != nil {

cmd/protoc-gen-go_gapic/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ go_library(
88
visibility = ["//visibility:private"],
99
deps = [
1010
"//internal/gengapic",
11-
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
1211
"@org_golang_google_protobuf//proto",
12+
"@org_golang_google_protobuf//types/pluginpb",
1313
],
1414
)
1515

cmd/protoc-gen-go_gapic/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ import (
1919
"log"
2020
"os"
2121

22-
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
2322
"github.com/googleapis/gapic-generator-go/internal/gengapic"
2423
"google.golang.org/protobuf/proto"
24+
"google.golang.org/protobuf/types/pluginpb"
2525
)
2626

2727
func main() {
2828
reqBytes, err := io.ReadAll(os.Stdin)
2929
if err != nil {
3030
log.Fatal(err)
3131
}
32-
var genReq plugin.CodeGeneratorRequest
32+
var genReq pluginpb.CodeGeneratorRequest
3333
if err := proto.Unmarshal(reqBytes, &genReq); err != nil {
3434
log.Fatal(err)
3535
}
@@ -39,7 +39,7 @@ func main() {
3939
genResp.Error = proto.String(err.Error())
4040
}
4141

42-
genResp.SupportedFeatures = proto.Uint64(uint64(plugin.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL))
42+
genResp.SupportedFeatures = proto.Uint64(uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL))
4343

4444
outBytes, err := proto.Marshal(genResp)
4545
if err != nil {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ require (
44
cloud.google.com/go/iam v1.1.7
55
cloud.google.com/go/longrunning v0.5.6
66
github.com/ghodss/yaml v1.0.0
7-
github.com/golang/protobuf v1.5.4
87
github.com/google/go-cmp v0.6.0
98
github.com/jhump/protoreflect v1.15.6
109
gitlab.com/golang-commonmark/markdown v0.0.0-20211110145824-bf3e522c626a
@@ -17,6 +16,7 @@ require (
1716

1817
require (
1918
github.com/bufbuild/protocompile v0.8.0 // indirect
19+
github.com/golang/protobuf v1.5.4 // indirect
2020
gitlab.com/golang-commonmark/html v0.0.0-20191124015941-a22733972181 // indirect
2121
gitlab.com/golang-commonmark/linkify v0.0.0-20191026162114-a0c2df6c8f82 // indirect
2222
gitlab.com/golang-commonmark/mdurl v0.0.0-20191124015652-932350d1cb84 // indirect

internal/gencli/BUILD.bazel

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ go_library(
1818
"//internal/printer",
1919
"@com_github_jhump_protoreflect//desc",
2020
"@com_google_cloud_go_longrunning//autogen/longrunningpb",
21-
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
22-
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
2321
"@org_golang_google_genproto_googleapis_api//annotations",
2422
"@org_golang_google_protobuf//proto",
23+
"@org_golang_google_protobuf//types/descriptorpb",
24+
"@org_golang_google_protobuf//types/pluginpb",
2525
"@org_golang_x_text//cases",
2626
"@org_golang_x_text//language",
2727
],
@@ -42,6 +42,6 @@ go_test(
4242
deps = [
4343
"//internal/pbinfo",
4444
"//internal/txtdiff",
45-
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
45+
"@org_golang_google_protobuf//types/descriptorpb",
4646
],
4747
)

internal/gencli/cmd_file_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
"path/filepath"
1919
"testing"
2020

21-
"github.com/golang/protobuf/protoc-gen-go/descriptor"
2221
"github.com/googleapis/gapic-generator-go/internal/pbinfo"
2322
"github.com/googleapis/gapic-generator-go/internal/txtdiff"
23+
"google.golang.org/protobuf/types/descriptorpb"
2424
)
2525

2626
func TestCommandFile(t *testing.T) {
@@ -46,7 +46,7 @@ func TestCommandFile(t *testing.T) {
4646
Flags: []*Flag{
4747
&Flag{
4848
Name: "task",
49-
Type: descriptor.FieldDescriptorProto_TYPE_STRING,
49+
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING,
5050
Required: true,
5151
FieldName: "Task",
5252
VarName: "CreateTodoInput",
@@ -56,14 +56,14 @@ func TestCommandFile(t *testing.T) {
5656
Name: "done",
5757
FieldName: "Done",
5858
VarName: "CreateTodoInput",
59-
Type: descriptor.FieldDescriptorProto_TYPE_BOOL,
59+
Type: descriptorpb.FieldDescriptorProto_TYPE_BOOL,
6060
Usage: "task completion status",
6161
Optional: true,
6262
},
6363
&Flag{
6464
Name: "priority",
6565
FieldName: "Priority",
66-
Type: descriptor.FieldDescriptorProto_TYPE_ENUM,
66+
Type: descriptorpb.FieldDescriptorProto_TYPE_ENUM,
6767
Usage: "importance of the task",
6868
Message: "Priority",
6969
MessageImport: pbinfo.ImportSpec{Name: "todopb"},
@@ -93,7 +93,7 @@ func TestCommandFile(t *testing.T) {
9393
Name: "id",
9494
FieldName: "Id",
9595
VarName: "StartTodoInput",
96-
Type: descriptor.FieldDescriptorProto_TYPE_INT32,
96+
Type: descriptorpb.FieldDescriptorProto_TYPE_INT32,
9797
Required: true,
9898
Usage: "task to start",
9999
},
@@ -134,7 +134,7 @@ func TestCommandFile(t *testing.T) {
134134
Name: "id",
135135
FieldName: "Id",
136136
VarName: "WatchTodoInput",
137-
Type: descriptor.FieldDescriptorProto_TYPE_INT32,
137+
Type: descriptorpb.FieldDescriptorProto_TYPE_INT32,
138138
Required: true,
139139
Usage: "task to watch",
140140
},

internal/gencli/flag.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ import (
2020
"unicode"
2121
"unicode/utf8"
2222

23-
"github.com/golang/protobuf/protoc-gen-go/descriptor"
2423
"github.com/googleapis/gapic-generator-go/internal/pbinfo"
2524
"github.com/jhump/protoreflect/desc"
25+
"google.golang.org/protobuf/types/descriptorpb"
2626
)
2727

2828
// Flag is used to represent fields as flags
2929
type Flag struct {
3030
Name string
31-
Type descriptor.FieldDescriptorProto_Type
31+
Type descriptorpb.FieldDescriptorProto_Type
3232
Message string
3333
Repeated bool
3434
Required bool
@@ -61,7 +61,7 @@ func (f *Flag) GenFlag() string {
6161
fType := toTitle(tStr)
6262

6363
if f.Repeated {
64-
if f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE {
64+
if f.Type == descriptorpb.FieldDescriptorProto_TYPE_MESSAGE {
6565
// repeated Messages are entered as JSON strings and unmarshaled into the Message type later
6666
return fmt.Sprintf(`StringArrayVar(&%s, "%s", []string{}, "%s")`, f.VarName, f.Name, f.Usage)
6767
}
@@ -111,17 +111,17 @@ func (f *Flag) GenFlag() string {
111111

112112
// IsMessage is a template helper that reports if the flag is a message type
113113
func (f *Flag) IsMessage() bool {
114-
return f.Type == descriptor.FieldDescriptorProto_TYPE_MESSAGE
114+
return f.Type == descriptorpb.FieldDescriptorProto_TYPE_MESSAGE
115115
}
116116

117117
// IsEnum is a template helper that reports if the flag is of an enum type
118118
func (f *Flag) IsEnum() bool {
119-
return f.Type == descriptor.FieldDescriptorProto_TYPE_ENUM
119+
return f.Type == descriptorpb.FieldDescriptorProto_TYPE_ENUM
120120
}
121121

122122
// IsBytes is a helper that reports if the flag is of a type bytes
123123
func (f *Flag) IsBytes() bool {
124-
return f.Type == descriptor.FieldDescriptorProto_TYPE_BYTES
124+
return f.Type == descriptorpb.FieldDescriptorProto_TYPE_BYTES
125125
}
126126

127127
// EnumFieldAccess constructs the input message field accessor for an enum

internal/gencli/flag_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package gencli
1717
import (
1818
"testing"
1919

20-
"github.com/golang/protobuf/protoc-gen-go/descriptor"
20+
"google.golang.org/protobuf/types/descriptorpb"
2121
)
2222

2323
func TestGenFlag(t *testing.T) {
@@ -30,7 +30,7 @@ func TestGenFlag(t *testing.T) {
3030
Name: "field",
3131
FieldName: "Field",
3232
VarName: "ClientInput",
33-
Type: descriptor.FieldDescriptorProto_TYPE_STRING,
33+
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING,
3434
Usage: "this is the usage",
3535
},
3636
want: `StringVar(&ClientInput.Field, "field", "", "this is the usage")`,
@@ -40,7 +40,7 @@ func TestGenFlag(t *testing.T) {
4040
Name: "field",
4141
FieldName: "Field",
4242
VarName: "ClientInput",
43-
Type: descriptor.FieldDescriptorProto_TYPE_BOOL,
43+
Type: descriptorpb.FieldDescriptorProto_TYPE_BOOL,
4444
Usage: "this is the usage",
4545
},
4646
want: `BoolVar(&ClientInput.Field, "field", false, "this is the usage")`,
@@ -50,7 +50,7 @@ func TestGenFlag(t *testing.T) {
5050
Name: "field",
5151
FieldName: "Field",
5252
VarName: "ClientInput",
53-
Type: descriptor.FieldDescriptorProto_TYPE_INT32,
53+
Type: descriptorpb.FieldDescriptorProto_TYPE_INT32,
5454
Usage: "this is the usage",
5555
},
5656
want: `Int32Var(&ClientInput.Field, "field", 0, "this is the usage")`,
@@ -60,7 +60,7 @@ func TestGenFlag(t *testing.T) {
6060
Name: "field",
6161
FieldName: "Field",
6262
VarName: "ClientInput",
63-
Type: descriptor.FieldDescriptorProto_TYPE_FLOAT,
63+
Type: descriptorpb.FieldDescriptorProto_TYPE_FLOAT,
6464
Usage: "this is the usage",
6565
},
6666
want: `Float32Var(&ClientInput.Field, "field", 0.0, "this is the usage")`,
@@ -70,7 +70,7 @@ func TestGenFlag(t *testing.T) {
7070
Name: "field",
7171
FieldName: "Field",
7272
VarName: "ClientInput",
73-
Type: descriptor.FieldDescriptorProto_TYPE_DOUBLE,
73+
Type: descriptorpb.FieldDescriptorProto_TYPE_DOUBLE,
7474
Usage: "this is the usage",
7575
},
7676
want: `Float64Var(&ClientInput.Field, "field", 0.0, "this is the usage")`,
@@ -80,7 +80,7 @@ func TestGenFlag(t *testing.T) {
8080
Name: "field",
8181
FieldName: "Field",
8282
VarName: "ClientInput",
83-
Type: descriptor.FieldDescriptorProto_TYPE_BYTES,
83+
Type: descriptorpb.FieldDescriptorProto_TYPE_BYTES,
8484
Usage: "this is the usage",
8585
},
8686
want: `BytesHexVar(&ClientInput.Field, "field", []byte{}, "this is the usage")`,
@@ -90,7 +90,7 @@ func TestGenFlag(t *testing.T) {
9090
Name: "field",
9191
FieldName: "Field",
9292
VarName: "ClientInput",
93-
Type: descriptor.FieldDescriptorProto_TYPE_STRING,
93+
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING,
9494
Usage: "this is the usage",
9595
Repeated: true,
9696
},
@@ -100,7 +100,7 @@ func TestGenFlag(t *testing.T) {
100100
f: &Flag{
101101
Name: "field",
102102
FieldName: "Field",
103-
Type: descriptor.FieldDescriptorProto_TYPE_MESSAGE,
103+
Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE,
104104
Usage: "this is the usage",
105105
Repeated: true,
106106
VarName: "ClientInputField",
@@ -111,7 +111,7 @@ func TestGenFlag(t *testing.T) {
111111
f: &Flag{
112112
Name: "field",
113113
FieldName: "Field",
114-
Type: descriptor.FieldDescriptorProto_TYPE_ENUM,
114+
Type: descriptorpb.FieldDescriptorProto_TYPE_ENUM,
115115
Usage: "this is the usage",
116116
VarName: "ClientInputField",
117117
},
@@ -121,7 +121,7 @@ func TestGenFlag(t *testing.T) {
121121
f: &Flag{
122122
Name: "oneof.field",
123123
FieldName: "Field",
124-
Type: descriptor.FieldDescriptorProto_TYPE_STRING,
124+
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING,
125125
Usage: "this is the usage",
126126
VarName: "ClientInputOneofField",
127127
IsOneOfField: true,
@@ -132,7 +132,7 @@ func TestGenFlag(t *testing.T) {
132132
f: &Flag{
133133
Name: "oneof_selector",
134134
VarName: "ClientInputOneofSelector",
135-
Type: descriptor.FieldDescriptorProto_TYPE_STRING,
135+
Type: descriptorpb.FieldDescriptorProto_TYPE_STRING,
136136
Usage: "this is the usage",
137137
OneOfs: map[string]*Flag{"test": &Flag{}},
138138
},
@@ -151,11 +151,11 @@ func TestIsMessage(t *testing.T) {
151151
want bool
152152
}{
153153
{
154-
f: &Flag{Type: descriptor.FieldDescriptorProto_TYPE_MESSAGE},
154+
f: &Flag{Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE},
155155
want: true,
156156
},
157157
{
158-
f: &Flag{Type: descriptor.FieldDescriptorProto_TYPE_STRING},
158+
f: &Flag{Type: descriptorpb.FieldDescriptorProto_TYPE_STRING},
159159
want: false,
160160
},
161161
} {
@@ -171,11 +171,11 @@ func TestIsEnum(t *testing.T) {
171171
want bool
172172
}{
173173
{
174-
f: &Flag{Type: descriptor.FieldDescriptorProto_TYPE_ENUM},
174+
f: &Flag{Type: descriptorpb.FieldDescriptorProto_TYPE_ENUM},
175175
want: true,
176176
},
177177
{
178-
f: &Flag{Type: descriptor.FieldDescriptorProto_TYPE_STRING},
178+
f: &Flag{Type: descriptorpb.FieldDescriptorProto_TYPE_STRING},
179179
want: false,
180180
},
181181
} {

0 commit comments

Comments
 (0)