protogen: avoid an obscure package name consistency check failure

When performing consistency checks on package names, ignore files that
are mentioned on the command line (M<filename>=<import_path>) but which
do not appear in the CodeGeneratorRequest.

Change-Id: I51f1eeda5eaaac14f4a0a975163f65d7774e7212
Reviewed-on: https://go-review.googlesource.com/c/140717
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
Damien Neil 2018-10-08 16:36:49 -07:00
parent daa4fad986
commit bbbd38f9f9

View File

@ -275,6 +275,11 @@ func New(req *pluginpb.CodeGeneratorRequest, opts *Options) (*Plugin, error) {
// the same Go package name.
packageFiles := make(map[GoImportPath][]string)
for filename, importPath := range importPaths {
if _, ok := packageNames[filename]; !ok {
// Skip files mentioned in a M<file>=<import_path> parameter
// but which do not appear in the CodeGeneratorRequest.
continue
}
packageFiles[importPath] = append(packageFiles[importPath], filename)
}
for importPath, filenames := range packageFiles {