Skip to content

Commit

Permalink
fix #427 consistent import naming between the import declaration and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jmarais authored and awalterschulze committed Jul 17, 2018
1 parent 7d68e88 commit 636bf03
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions protoc-gen-gogo/grpc/grpc.go
Expand Up @@ -36,6 +36,7 @@ package grpc

import (
"fmt"
"path"
"strconv"
"strings"

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions protoc-gen-gogo/testdata/deprecated/deprecated.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions protoc-gen-gogo/testdata/grpc/grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/issue427/.gitignore
@@ -0,0 +1,2 @@
*.pb.go
*_test.go
7 changes: 7 additions & 0 deletions 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 ./...
11 changes: 11 additions & 0 deletions 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
18 changes: 18 additions & 0 deletions 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);
}

0 comments on commit 636bf03

Please sign in to comment.