mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2024-12-27 15:26:51 +00:00
387873dd53
In the upcoming 3.12.x release of protoc, the proto3 language will be amended to support true presence for scalars. This CL adds support to both the generator and runtime to support these semantics. Newly added public API: protogen.Plugin.SupportedFeatures protoreflect.FieldDescriptor.HasPresence protoreflect.FieldDescriptor.HasOptionalKeyword protoreflect.OneofDescriptor.IsSynthetic Change-Id: I7c86bf66d0ae56642109beb5f2132184593747ad Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/230698 Reviewed-by: Damien Neil <dneil@google.com>
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// The protoc-gen-go binary is a protoc plugin to generate Go code for
|
|
// both proto2 and proto3 versions of the protocol buffer language.
|
|
//
|
|
// For more information about the usage of this plugin, see:
|
|
// https://developers.google.com/protocol-buffers/docs/reference/go-generated
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo"
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
"google.golang.org/protobuf/internal/version"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) == 2 && os.Args[1] == "--version" {
|
|
fmt.Fprintf(os.Stderr, "%v %v\n", filepath.Base(os.Args[0]), version.String())
|
|
os.Exit(1)
|
|
}
|
|
|
|
var (
|
|
flags flag.FlagSet
|
|
plugins = flags.String("plugins", "", "deprecated option")
|
|
importPrefix = flags.String("import_prefix", "", "deprecated option")
|
|
)
|
|
protogen.Options{
|
|
ParamFunc: flags.Set,
|
|
}.Run(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")
|
|
}
|
|
if *importPrefix != "" {
|
|
return errors.New("protoc-gen-go: import_prefix is not supported")
|
|
}
|
|
for _, f := range gen.Files {
|
|
if f.Generate {
|
|
gengo.GenerateFile(gen, f)
|
|
}
|
|
}
|
|
gen.SupportedFeatures = gengo.SupportedFeatures
|
|
return nil
|
|
})
|
|
}
|