|
|
@@ -10,8 +10,6 @@ import (
|
|
|
"compress/gzip"
|
|
|
"crypto/sha256"
|
|
|
"encoding/hex"
|
|
|
- "errors"
|
|
|
- "flag"
|
|
|
"fmt"
|
|
|
"math"
|
|
|
"sort"
|
|
|
@@ -32,26 +30,6 @@ const generatedCodeVersion = 2
|
|
|
|
|
|
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 @@ type fileInfo struct {
|
|
|
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 @@ func genFile(gen *protogen.Plugin, file *protogen.File) {
|
|
|
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.")
|