mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-27 15:26:51 +00:00
cmd/protoc-gen-go: always generate support for reflection
Now that binary bloat concerns have been addressed, remove the flag to control whether to generate support for reflection. Change-Id: Ia0d11183707572caaf91d2f01dfa77e3aac0a417 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167140 Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
9e88bc0b67
commit
4989810018
@ -7,21 +7,12 @@ package internal_gengo
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/v2/protogen"
|
||||
"github.com/golang/protobuf/v2/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// TODO: Remove this flag.
|
||||
// Remember to remove the copy in internal/protogen/goldentest.
|
||||
var enableReflectFlag = os.Getenv("PROTOC_GEN_GO_ENABLE_REFLECT") != ""
|
||||
|
||||
func enableReflection(f *protogen.File) bool {
|
||||
return enableReflectFlag || isDescriptor(f)
|
||||
}
|
||||
|
||||
// TODO: Remove special-casing for descriptor proto.
|
||||
func isDescriptor(f *protogen.File) bool {
|
||||
return f.Desc.Path() == "google/protobuf/descriptor.proto" && f.Desc.Package() == "google.protobuf"
|
||||
@ -42,10 +33,6 @@ const (
|
||||
// TODO: Add support for proto options.
|
||||
|
||||
func genReflectFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo) {
|
||||
if !enableReflection(f.File) {
|
||||
return
|
||||
}
|
||||
|
||||
// Emit a static check that enforces a minimum version of the proto package.
|
||||
// TODO: This should appear higher up in the Go source file.
|
||||
g.P("const _ = ", protoimplPackage.Ident("EnforceVersion"), "(", protoimplPackage.Ident("Version"), " - ", minimumVersion, ")")
|
||||
@ -224,10 +211,6 @@ func genReflectFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f
|
||||
}
|
||||
|
||||
func genReflectEnum(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, enum *protogen.Enum) {
|
||||
if !enableReflection(f.File) {
|
||||
return
|
||||
}
|
||||
|
||||
idx := f.allEnumsByPtr[enum]
|
||||
typesVar := enumTypesVarName(f)
|
||||
g.P("func (e ", enum.GoIdent, ") Type() ", protoreflectPackage.Ident("EnumType"), " {")
|
||||
@ -239,10 +222,6 @@ func genReflectEnum(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo
|
||||
}
|
||||
|
||||
func genReflectMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message) {
|
||||
if !enableReflection(f.File) {
|
||||
return
|
||||
}
|
||||
|
||||
idx := f.allMessagesByPtr[message]
|
||||
typesVar := messageTypesVarName(f)
|
||||
g.P("func (m *", message.GoIdent, ") ProtoReflect() ", protoreflectPackage.Ident("Message"), " {")
|
||||
|
@ -196,7 +196,6 @@ func protoc(plugins string, args ...string) {
|
||||
cmd := exec.Command("protoc", "--plugin=protoc-gen-go="+os.Args[0])
|
||||
cmd.Args = append(cmd.Args, args...)
|
||||
cmd.Env = append(os.Environ(), "RUN_AS_PROTOC_PLUGIN="+plugins)
|
||||
cmd.Env = append(cmd.Env, "PROTOC_GEN_GO_ENABLE_REFLECT=1")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Printf("executing: %v\n%s\n", strings.Join(cmd.Args, " "), out)
|
||||
|
Loading…
Reference in New Issue
Block a user