Skip to content

Commit

Permalink
nodep
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Jun 2, 2015
1 parent 23f7c73 commit 4549dd0
Show file tree
Hide file tree
Showing 40 changed files with 678 additions and 332 deletions.
9 changes: 9 additions & 0 deletions gogoproto/gogo.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gogoproto/gogo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extend google.protobuf.FileOptions {

optional bool goproto_extensions_map_all = 63025;
optional bool goproto_unrecognized_all = 63026;
optional bool gogoproto_import = 63027;
}

extend google.protobuf.MessageOptions {
Expand Down
4 changes: 4 additions & 0 deletions gogoproto/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,7 @@ func HasUnrecognized(file *google_protobuf.FileDescriptorProto, message *google_
func IsProto3(file *google_protobuf.FileDescriptorProto) bool {
return file.GetSyntax() == "proto3"
}

func ImportsGoGoProto(file *google_protobuf.FileDescriptorProto) bool {
return proto.GetBoolExtension(file.Options, E_GogoprotoImport, true)
}
3 changes: 3 additions & 0 deletions plugin/equal/equaltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (p *test) Generate(imports generator.PluginImports, file *generator.FileDes
timePkg := imports.NewImport("time")
testingPkg := imports.NewImport("testing")
protoPkg := imports.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = imports.NewImport("github.com/golang/protobuf/proto")
}
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
if !gogoproto.HasVerboseEqual(file.FileDescriptorProto, message.DescriptorProto) {
Expand Down
3 changes: 3 additions & 0 deletions plugin/face/face.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func (p *plugin) GetMapGoType(file *descriptor.FileDescriptorProto, field *descr
func (p *plugin) Generate(file *generator.FileDescriptor) {
p.PluginImports = generator.NewPluginImports(p.Generator)
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = p.NewImport("github.com/golang/protobuf/proto")
}
for _, message := range file.Messages() {
if !gogoproto.IsFace(file.FileDescriptorProto, message.DescriptorProto) {
continue
Expand Down
3 changes: 3 additions & 0 deletions plugin/gostring/gostring.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func (p *gostring) Generate(file *generator.FileDescriptor) {
fmtPkg := p.NewImport("fmt")
stringsPkg := p.NewImport("strings")
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = p.NewImport("github.com/golang/protobuf/proto")
}
sortPkg := p.NewImport("sort")
strconvPkg := p.NewImport("strconv")
reflectPkg := p.NewImport("reflect")
Expand Down
3 changes: 3 additions & 0 deletions plugin/marshalto/marshalto.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ func (p *marshalto) Generate(file *generator.FileDescriptor) {

mathPkg := p.NewImport("math")
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = p.NewImport("github.com/golang/protobuf/proto")
}
sortKeysPkg := p.NewImport("github.com/gogo/protobuf/sortkeys")
p.unsafePkg = p.NewImport("unsafe")

Expand Down
3 changes: 3 additions & 0 deletions plugin/populate/populate.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ func (p *plugin) Generate(file *generator.FileDescriptor) {

p.localName = generator.FileName(file)
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = p.NewImport("github.com/golang/protobuf/proto")
}

for _, message := range file.Messages() {
if !gogoproto.HasPopulate(file.FileDescriptorProto, message.DescriptorProto) {
Expand Down
3 changes: 3 additions & 0 deletions plugin/size/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ func (p *size) Generate(file *generator.FileDescriptor) {
p.atleastOne = false
p.localName = generator.FileName(file)
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = p.NewImport("github.com/golang/protobuf/proto")
}
for _, message := range file.Messages() {
if !gogoproto.IsSizer(file.FileDescriptorProto, message.DescriptorProto) {
continue
Expand Down
3 changes: 3 additions & 0 deletions plugin/size/sizetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (p *test) Generate(imports generator.PluginImports, file *generator.FileDes
timePkg := imports.NewImport("time")
testingPkg := imports.NewImport("testing")
protoPkg := imports.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = imports.NewImport("github.com/golang/protobuf/proto")
}
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
if !gogoproto.IsSizer(file.FileDescriptorProto, message.DescriptorProto) {
Expand Down
6 changes: 6 additions & 0 deletions plugin/testgen/testgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ func (p *testProto) Generate(imports generator.PluginImports, file *generator.Fi
randPkg := imports.NewImport("math/rand")
timePkg := imports.NewImport("time")
protoPkg := imports.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = imports.NewImport("github.com/golang/protobuf/proto")
}
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
if message.DescriptorProto.GetOptions().GetMapEntry() {
Expand Down Expand Up @@ -505,6 +508,9 @@ func (p *testText) Generate(imports generator.PluginImports, file *generator.Fil
randPkg := imports.NewImport("math/rand")
timePkg := imports.NewImport("time")
protoPkg := imports.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = imports.NewImport("github.com/golang/protobuf/proto")
}
//fmtPkg := imports.NewImport("fmt")
for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
Expand Down
3 changes: 3 additions & 0 deletions plugin/unmarshal/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,9 @@ func (p *unmarshal) Generate(file *generator.FileDescriptor) {
p.unsafePkg = p.NewImport("unsafe")
fmtPkg := p.NewImport("fmt")
protoPkg := p.NewImport("github.com/gogo/protobuf/proto")
if !gogoproto.ImportsGoGoProto(file.FileDescriptorProto) {
protoPkg = p.NewImport("github.com/golang/protobuf/proto")
}

for _, message := range file.Messages() {
ccTypeName := generator.CamelCaseSlice(message.TypeName())
Expand Down
6 changes: 5 additions & 1 deletion protoc-gen-gogo/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,11 @@ func (g *Generator) generateImports() {
// do, which is tricky when there's a plugin, just import it and
// reference it later. The same argument applies to the math package,
// for handling bit patterns for floating-point numbers.
g.PrintImport(g.Pkg["proto"], g.ImportPrefix+"github.com/gogo/protobuf/proto")
if gogoproto.ImportsGoGoProto(g.file.FileDescriptorProto) {
g.PrintImport(g.Pkg["proto"], g.ImportPrefix+"github.com/gogo/protobuf/proto")
} else {
g.PrintImport(g.Pkg["proto"], g.ImportPrefix+"github.com/golang/protobuf/proto")
}
if !g.file.proto3 {
g.PrintImport(g.Pkg["math"], "math")
}
Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
regenerate:
go install github.com/gogo/protobuf/protoc-gen-gogo/protoc-gen-combo
protoc-gen-combo --default=false --proto_path=../:../../../../:../protobuf/:. thetest.proto
protoc --gogo_out=. --proto_path=../:../../../../:../protobuf/:. thetest.proto
cp uuid.go ./combos/both/
cp uuid.go ./combos/marshaler/
cp uuid.go ./combos/unmarshaler/
Expand Down
6 changes: 5 additions & 1 deletion test/combos/both/thetest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion test/combos/marshaler/thetest.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4549dd0

Please sign in to comment.