From 0d9cd384190f32bff61b05a3965df9cd787b6cbe Mon Sep 17 00:00:00 2001 From: lisong Date: Thu, 3 Nov 2022 18:09:43 +0800 Subject: [PATCH] support build tag --- .gitignore | 3 ++- protoc-gen-gogo/generator/generator.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 82f4de4a51..ce82b97c40 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ *.js.map # Conformance test output and transient files. -conformance/failing_tests.txt \ No newline at end of file +conformance/failing_tests.txt +/.idea diff --git a/protoc-gen-gogo/generator/generator.go b/protoc-gen-gogo/generator/generator.go index ab07ed61ef..82a3837877 100644 --- a/protoc-gen-gogo/generator/generator.go +++ b/protoc-gen-gogo/generator/generator.go @@ -466,6 +466,8 @@ type Generator struct { customImports []string writtenImports map[string]bool // For de-duplicating written imports + + buildTag string } type pathType int @@ -536,6 +538,8 @@ func (g *Generator) CommandLineParameters(parameter string) { if v == "true" { g.annotateCode = true } + case "build_tag": + g.buildTag = v default: if len(k) > 0 && k[0] == 'M' { g.ImportMap[k[1:]] = v @@ -1197,6 +1201,11 @@ func (g *Generator) generate(file *FileDescriptor) { g.usedPackageNames[name] = true } + if g.buildTag != "" { + g.P("//go:build ", g.buildTag) + g.P("// +build ", g.buildTag) + } + g.P("// This is a compile-time assertion to ensure that this generated file") g.P("// is compatible with the proto package it is being compiled against.") g.P("// A compilation error at this line likely means your copy of the")