Skip to content

Commit

Permalink
Fix import path behaviour when using full path
Browse files Browse the repository at this point in the history
This change makes protoc-gen-star conform to the behaviour
of protoc-gen-go in the presence of an import_path
parameter that contains slashes.

See https://github.com/golang/protobuf/blob/v1.4.2/protoc-gen-go/generator/generator.go#L637-L643
for evidence of this behaviour in protoc-gen-go.

Fixes lyft#77
  • Loading branch information
johanbrandhorst committed Jun 8, 2020
1 parent 823d49f commit 0219938
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lang/go/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func (c context) PackageName(node pgs.Node) pgs.Name {
// use import_path parameter ONLY if there is no go_package option in the file.
if ip := c.p.Str("import_path"); ip != "" &&
e.File().Descriptor().GetOptions().GetGoPackage() == "" {

if i := strings.LastIndex(ip, "/"); i >= 0 {
ip = ip[i+1:]
}
pkg = ip
}

Expand Down
2 changes: 1 addition & 1 deletion lang/go/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestPackageName(t *testing.T) {
{"unnamed", "names_unnamed"}, // use the proto package if no go_package
{"import", "bar"}, // uses the basename if go_package contains a /
{"override", "baz"}, // if go_package contains ;, use everything to the right
{"import_path", "_package"}, // import_path param used if no go_package option
{"import_path", "buzz"}, // import_path param used if no go_package option. Should use last part of path.
{"mapped", "unaffected"}, // M mapped params are ignored for build targets
{"import_path_mapped", "go_package"}, // mixed import_path and M parameters should lose to go_package
{"transitive_package", "foobar"}, // go_option gets picked up from other files if present
Expand Down
2 changes: 1 addition & 1 deletion lang/go/testdata/names/import_path/params
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Mnames/import_path/import_path.proto=foobar,import_path=package
Mnames/import_path/import_path.proto=foobar,import_path=github.com/fizz/buzz

0 comments on commit 0219938

Please sign in to comment.