cmd/protoc-gen-go: add constants to control generation of deprecated features
These deprecated features add a non-trivial amount of binary bloat.
Protect these under a constant to make it easy to patch them out.
Change-Id: I12cc33613c19ef60ceec4c4449d0cf3692835170
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/172407
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/reflect.go b/cmd/protoc-gen-go/internal_gengo/reflect.go
index 0b584a4..fb33ea2 100644
--- a/cmd/protoc-gen-go/internal_gengo/reflect.go
+++ b/cmd/protoc-gen-go/internal_gengo/reflect.go
@@ -210,21 +210,23 @@
g.P("}")
g.P()
- onceVar := rawDescVarName(f) + "Once"
- dataVar := rawDescVarName(f) + "Data"
- g.P("var (")
- g.P(onceVar, " ", syncPackage.Ident("Once"))
- g.P(dataVar, " = ", rawDescVarName(f))
- g.P(")")
- g.P()
+ if generateRawDescMethods {
+ onceVar := rawDescVarName(f) + "Once"
+ dataVar := rawDescVarName(f) + "Data"
+ g.P("var (")
+ g.P(onceVar, " ", syncPackage.Ident("Once"))
+ g.P(dataVar, " = ", rawDescVarName(f))
+ g.P(")")
+ g.P()
- g.P("func ", rawDescVarName(f), "GZIP() []byte {")
- g.P(onceVar, ".Do(func() {")
- g.P(dataVar, " = ", protoimplPackage.Ident("X"), ".CompressGZIP(", dataVar, ")")
- g.P("})")
- g.P("return ", dataVar)
- g.P("}")
- g.P()
+ g.P("func ", rawDescVarName(f), "GZIP() []byte {")
+ g.P(onceVar, ".Do(func() {")
+ g.P(dataVar, " = ", protoimplPackage.Ident("X"), ".CompressGZIP(", dataVar, ")")
+ g.P("})")
+ g.P("return ", dataVar)
+ g.P("}")
+ g.P()
+ }
}
func genReflectEnum(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, enum *protogen.Enum) {