compiler/protogen: make paths=import work with M overrides
In the default .pb.go filename generation mode, we generate the filename
from the import path when a file has a go_package option and the source
.proto filename otherwise.
Change filename generation when an explicit mode of paths=import is
specified to always use the import path, no matter how it was
determiend. The practical effect is that you can override the import
path of a file with Mx.proto=import/path and have this behave
identically to setting a go_package option in the file.
Change-Id: I954b3f9d5fd17d08896629bfc77945dea1732bd6
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/219597
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/compiler/protogen/protogen_test.go b/compiler/protogen/protogen_test.go
index 5cc3d66..1f7b75c 100644
--- a/compiler/protogen/protogen_test.go
+++ b/compiler/protogen/protogen_test.go
@@ -159,6 +159,15 @@
wantImportPath: "golang.org/x/foo",
wantFilenamePrefix: "golang.org/x/foo/filename",
},
+ {
+ desc: "paths=import uses import path from command line",
+ parameter: "paths=import,Mdir/filename.proto=golang.org/x/bar",
+ goPackageOption: "golang.org/x/foo",
+ generate: true,
+ wantPackageName: "foo",
+ wantImportPath: "golang.org/x/bar",
+ wantFilenamePrefix: "golang.org/x/bar/filename",
+ },
} {
context := fmt.Sprintf(`
TEST: %v