Don't generate a Go file, if that would be empty
Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
parent
5f3b724323
commit
3742c756e8
@ -159,13 +159,6 @@ func collectChildlen(parent *protogen.Message) ([]*protogen.Message, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generate(plugin *protogen.Plugin, input *protogen.File) error {
|
func generate(plugin *protogen.Plugin, input *protogen.File) error {
|
||||||
file := plugin.NewGeneratedFile(input.GeneratedFilenamePrefix+"_fieldpath.pb.go", input.GoImportPath)
|
|
||||||
file.P("// Code generated by protoc-gen-go-fieldpath. DO NOT EDIT.")
|
|
||||||
file.P("// source: ", input.Desc.Path())
|
|
||||||
file.P("package ", input.GoPackageName)
|
|
||||||
|
|
||||||
gen := newGenerator(file)
|
|
||||||
|
|
||||||
var messages []*protogen.Message
|
var messages []*protogen.Message
|
||||||
for _, m := range input.Messages {
|
for _, m := range input.Messages {
|
||||||
messages = append(messages, m)
|
messages = append(messages, m)
|
||||||
@ -176,6 +169,18 @@ func generate(plugin *protogen.Plugin, input *protogen.File) error {
|
|||||||
messages = append(messages, children...)
|
messages = append(messages, children...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(messages) == 0 {
|
||||||
|
// Don't generate a Go file, if that would be empty.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
file := plugin.NewGeneratedFile(input.GeneratedFilenamePrefix+"_fieldpath.pb.go", input.GoImportPath)
|
||||||
|
file.P("// Code generated by protoc-gen-go-fieldpath. DO NOT EDIT.")
|
||||||
|
file.P("// source: ", input.Desc.Path())
|
||||||
|
file.P("package ", input.GoPackageName)
|
||||||
|
|
||||||
|
gen := newGenerator(file)
|
||||||
|
|
||||||
for _, m := range messages {
|
for _, m := range messages {
|
||||||
gen.genFieldMethod(m)
|
gen.genFieldMethod(m)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user