cmd/protoc-gen-go: don't import _ weak imports

Don't generate a blank import for unused weak imports.

Full support for weak imports would involve not importing the package at
all. This just avoids generating an import when we don't need one.

Change-Id: I7e8491f415dc8333a2837db5225256b959921be2
Reviewed-on: https://go-review.googlesource.com/c/145497
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
Damien Neil 2018-10-29 09:07:41 -07:00
parent a485fbd353
commit 40a08052f9

View File

@ -136,10 +136,12 @@ func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, imp
// Don't generate imports or aliases for types in the same Go package.
return
}
// Generate imports for all dependencies, even if they are not
// Generate imports for all non-weak dependencies, even if they are not
// referenced, because other code and tools depend on having the
// full transitive closure of protocol buffer types in the binary.
g.Import(impFile.GoImportPath)
if !imp.IsWeak {
g.Import(impFile.GoImportPath)
}
if !imp.IsPublic {
return
}