Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import path behaviour when using full path #78

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() == "" {
// Remove anything before the last slash
if i := strings.LastIndex(ip, "/"); i >= 0 {
ip = ip[i+1:]
}
pkg = ip
}

Expand Down
1 change: 1 addition & 0 deletions lang/go/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestPackageName(t *testing.T) {
{"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
{"full_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
4 changes: 4 additions & 0 deletions lang/go/testdata/names/full_import_path/import_path.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
syntax="proto3";
package names.import_path;

message ImportPath {}
1 change: 1 addition & 0 deletions lang/go/testdata/names/full_import_path/params
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mnames/import_path/import_path.proto=foobar,import_path=github.com/fizz/buzz