cmd/protoc-gen-go: expose internal_gengo.GenerateFile

Move things around a little bit to allow the v1 protoc-gen-go to support
plugins=grpc.

Change-Id: I98d1bb86828450afe7915b1fefaf22bb7915cf44
Reviewed-on: https://go-review.googlesource.com/138256
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 a337c5f..86c03e9 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -10,8 +10,6 @@
 	"compress/gzip"
 	"crypto/sha256"
 	"encoding/hex"
-	"errors"
-	"flag"
 	"fmt"
 	"math"
 	"sort"
@@ -32,26 +30,6 @@
 
 const protoPackage = "github.com/golang/protobuf/proto"
 
-func Main() {
-	var flags flag.FlagSet
-	plugins := flags.String("plugins", "", "deprecated option")
-	opts := &protogen.Options{
-		ParamFunc: flags.Set,
-	}
-	protogen.Run(opts, func(gen *protogen.Plugin) error {
-		if *plugins != "" {
-			return errors.New("protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC")
-		}
-		for _, f := range gen.Files {
-			if !f.Generate {
-				continue
-			}
-			genFile(gen, f)
-		}
-		return nil
-	})
-}
-
 type fileInfo struct {
 	*protogen.File
 	locationMap   map[string][]*descpb.SourceCodeInfo_Location
@@ -61,7 +39,8 @@
 	allExtensions []*protogen.Extension
 }
 
-func genFile(gen *protogen.Plugin, file *protogen.File) {
+// GenerateFile generates the contents of a .pb.go file.
+func GenerateFile(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile) {
 	f := &fileInfo{
 		File:        file,
 		locationMap: make(map[string][]*descpb.SourceCodeInfo_Location),
@@ -89,7 +68,6 @@
 	filenameHash := sha256.Sum256([]byte(f.Desc.Path()))
 	f.descriptorVar = fmt.Sprintf("fileDescriptor_%s", hex.EncodeToString(filenameHash[:8]))
 
-	g := gen.NewGeneratedFile(f.GeneratedFilenamePrefix+".pb.go", f.GoImportPath)
 	g.P("// Code generated by protoc-gen-go. DO NOT EDIT.")
 	if f.Proto.GetOptions().GetDeprecated() {
 		g.P("// ", f.Desc.Path(), " is a deprecated file.")