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>
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index ed0d07f..89d4011 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -136,10 +136,12 @@
 		// 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
 	}