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/main.go b/cmd/protoc-gen-go/main.go
index 919e3d1..efd294b 100644
--- a/cmd/protoc-gen-go/main.go
+++ b/cmd/protoc-gen-go/main.go
@@ -7,9 +7,31 @@
package main
import (
- "github.com/golang/protobuf/v2/cmd/protoc-gen-go/internal_gengo"
+ "errors"
+ "flag"
+
+ gengo "github.com/golang/protobuf/v2/cmd/protoc-gen-go/internal_gengo"
+ "github.com/golang/protobuf/v2/protogen"
)
func main() {
- internal_gengo.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
+ }
+ filename := f.GeneratedFilenamePrefix + ".pb.go"
+ g := gen.NewGeneratedFile(filename, f.GoImportPath)
+ gengo.GenerateFile(gen, f, g)
+ }
+ return nil
+ })
}