mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-30 03:32:49 +00:00
cmd/protoc-gen-go: reference proto.ProtoPackageIsVersionX
Include the compile-time assertion that the generated file is compatible with the proto package it is being compiled against. Change-Id: Iefa27ee3a99a6669a93303b6674b0033794ba0be Reviewed-on: https://go-review.googlesource.com/134995 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
parent
658051ba78
commit
d412792d34
@ -22,6 +22,12 @@ import (
|
||||
"google.golang.org/proto/reflect/protoreflect"
|
||||
)
|
||||
|
||||
// generatedCodeVersion indicates a version of the generated code.
|
||||
// It is incremented whenever an incompatibility between the generated code and
|
||||
// proto package is introduced; the generated code references
|
||||
// a constant, proto.ProtoPackageIsVersionN (where N is generatedCodeVersion).
|
||||
const generatedCodeVersion = 2
|
||||
|
||||
const protoPackage = "github.com/golang/protobuf/proto"
|
||||
|
||||
func main() {
|
||||
@ -74,6 +80,15 @@ func genFile(gen *protogen.Plugin, file *protogen.File) {
|
||||
g.P()
|
||||
g.P("package ", f.GoPackageName)
|
||||
g.P()
|
||||
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")
|
||||
g.P("// proto package needs to be updated.")
|
||||
g.P("const _ = ", protogen.GoIdent{
|
||||
GoImportPath: protoPackage,
|
||||
GoName: fmt.Sprintf("ProtoPackageIsVersion%d", generatedCodeVersion),
|
||||
}, "// please upgrade the proto package")
|
||||
g.P()
|
||||
|
||||
for _, enum := range f.Enums {
|
||||
genEnum(gen, g, f, enum)
|
||||
|
@ -5,6 +5,14 @@
|
||||
|
||||
package proto2
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
// COMMENT: Message1
|
||||
type Message1 struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
|
@ -3,6 +3,14 @@
|
||||
|
||||
package fieldnames
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
// Assorted edge cases in field name conflict resolution.
|
||||
//
|
||||
// Not all (or possibly any) of these behave in an easily-understood fashion.
|
||||
|
6
cmd/protoc-gen-go/testdata/proto2/enum.pb.go
vendored
6
cmd/protoc-gen-go/testdata/proto2/enum.pb.go
vendored
@ -5,6 +5,12 @@ package proto2
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
// EnumType1 comment.
|
||||
type EnumType1 int32
|
||||
|
||||
|
@ -5,6 +5,12 @@ package proto2
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type FieldTestMessage_Enum int32
|
||||
|
||||
const (
|
||||
|
@ -3,6 +3,14 @@
|
||||
|
||||
package proto2
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Layer1 struct {
|
||||
L2 *Layer1_Layer2 `protobuf:"bytes,1,opt,name=l2" json:"l2,omitempty"`
|
||||
L3 *Layer1_Layer2_Layer3 `protobuf:"bytes,2,opt,name=l3" json:"l3,omitempty"`
|
||||
|
@ -3,6 +3,14 @@
|
||||
|
||||
package proto2
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Message struct {
|
||||
I32 *int32 `protobuf:"varint,1,opt,name=i32" json:"i32,omitempty"`
|
||||
M *Message `protobuf:"bytes,2,opt,name=m" json:"m,omitempty"`
|
||||
|
6
cmd/protoc-gen-go/testdata/proto3/enum.pb.go
vendored
6
cmd/protoc-gen-go/testdata/proto3/enum.pb.go
vendored
@ -5,6 +5,12 @@ package proto3
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Enum int32
|
||||
|
||||
const (
|
||||
|
@ -5,6 +5,12 @@ package proto3
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type FieldTestMessage_Enum int32
|
||||
|
||||
const (
|
||||
|
Loading…
x
Reference in New Issue
Block a user