From 636bf0302bc95575d69441b25a2603156ffdddf1 Mon Sep 17 00:00:00 2001 From: jmarais Date: Tue, 17 Jul 2018 16:19:46 +0200 Subject: [PATCH] fix #427 consistent import naming between the import declaration and the vars in grpc * consistent import naming between the import declaration and the vars. This is more consistant with golang/protobuf. * moved issue427 test to the 'testall' make target to avoid grpc/context dependency --- Makefile | 1 + protoc-gen-gogo/grpc/grpc.go | 9 ++++----- .../testdata/deprecated/deprecated.pb.go | 4 ++-- protoc-gen-gogo/testdata/grpc/grpc.pb.go | 4 ++-- test/issue427/.gitignore | 2 ++ test/issue427/Makefile | 7 +++++++ test/issue427/README.md | 11 +++++++++++ test/issue427/issue427.proto | 18 ++++++++++++++++++ 8 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 test/issue427/.gitignore create mode 100644 test/issue427/Makefile create mode 100644 test/issue427/README.md create mode 100644 test/issue427/issue427.proto diff --git a/Makefile b/Makefile index f07eaa6e8b..43f6e6940f 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,7 @@ testall: make -C vanity/test test make -C test/registration test make -C conformance test + make -C test/issue427 test make tests bench: diff --git a/protoc-gen-gogo/grpc/grpc.go b/protoc-gen-gogo/grpc/grpc.go index 5b9e894eaf..85bed20684 100644 --- a/protoc-gen-gogo/grpc/grpc.go +++ b/protoc-gen-gogo/grpc/grpc.go @@ -36,6 +36,7 @@ package grpc import ( "fmt" + "path" "strconv" "strings" @@ -128,11 +129,9 @@ func (g *grpc) GenerateImports(file *generator.FileDescriptor) { if len(file.FileDescriptorProto.Service) == 0 { return } - imports := generator.NewPluginImports(g.gen) - for _, i := range []string{contextPkgPath, grpcPkgPath} { - imports.NewImport(i).Use() - } - imports.GenerateImports(file) + g.P("import ", contextPkg, " ", generator.GoImportPath(path.Join(string(g.gen.ImportPrefix), contextPkgPath))) + g.P("import ", grpcPkg, " ", generator.GoImportPath(path.Join(string(g.gen.ImportPrefix), grpcPkgPath))) + g.P() } // reservedClientName records whether a client name is reserved on the client side. diff --git a/protoc-gen-gogo/testdata/deprecated/deprecated.pb.go b/protoc-gen-gogo/testdata/deprecated/deprecated.pb.go index 0e18fbfcbf..dd9d4cbc91 100644 --- a/protoc-gen-gogo/testdata/deprecated/deprecated.pb.go +++ b/protoc-gen-gogo/testdata/deprecated/deprecated.pb.go @@ -11,8 +11,8 @@ import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" -import golang_org_x_net_context "golang.org/x/net/context" -import google_golang_org_grpc "google.golang.org/grpc" +import context "golang.org/x/net/context" +import grpc "google.golang.org/grpc" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal diff --git a/protoc-gen-gogo/testdata/grpc/grpc.pb.go b/protoc-gen-gogo/testdata/grpc/grpc.pb.go index dba256fc94..fe4a5ab7fc 100644 --- a/protoc-gen-gogo/testdata/grpc/grpc.pb.go +++ b/protoc-gen-gogo/testdata/grpc/grpc.pb.go @@ -7,8 +7,8 @@ import proto "github.com/gogo/protobuf/proto" import fmt "fmt" import math "math" -import golang_org_x_net_context "golang.org/x/net/context" -import google_golang_org_grpc "google.golang.org/grpc" +import context "golang.org/x/net/context" +import grpc "google.golang.org/grpc" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal diff --git a/test/issue427/.gitignore b/test/issue427/.gitignore new file mode 100644 index 0000000000..f66be03838 --- /dev/null +++ b/test/issue427/.gitignore @@ -0,0 +1,2 @@ +*.pb.go +*_test.go \ No newline at end of file diff --git a/test/issue427/Makefile b/test/issue427/Makefile new file mode 100644 index 0000000000..5eb2c16859 --- /dev/null +++ b/test/issue427/Makefile @@ -0,0 +1,7 @@ +test: + go install github.com/gogo/protobuf/protoc-gen-gogo + go install github.com/gogo/protobuf/protoc-min-version + go get -u golang.org/x/net/context + go get -u google.golang.org/grpc + protoc-min-version --version="3.0.0" --gogo_out=plugins=grpc:. --proto_path=../../../../../:../../protobuf/:. issue427.proto + go test ./... diff --git a/test/issue427/README.md b/test/issue427/README.md new file mode 100644 index 0000000000..e9fd7da7b7 --- /dev/null +++ b/test/issue427/README.md @@ -0,0 +1,11 @@ +# The Bug + +Inconsistent package name generation between the import: + +* import golang_org_x_net_context "golang.org/x/net/context" +* import google_golang_org_grpc "google.golang.org/grpc" + +and the dummy vars: + +* var _ context.Context +* var _ grpc.ClientConn diff --git a/test/issue427/issue427.proto b/test/issue427/issue427.proto new file mode 100644 index 0000000000..c37e7f7c83 --- /dev/null +++ b/test/issue427/issue427.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package issue427; + +import "github.com/gogo/protobuf/gogoproto/gogo.proto"; + +option (gogoproto.testgen_all) = true; +option (gogoproto.populate_all) = true; +option (gogoproto.sizer_all) = true; +option (gogoproto.equal_all) = true; + +message Foo { + string foo = 1; +} + +service Bar { + rpc GetBar (Foo) returns (Foo); +} \ No newline at end of file