Skip to content

Commit

Permalink
Don't generate a Go file, if that would be empty
Browse files Browse the repository at this point in the history
Signed-off-by: Kazuyoshi Kato <[email protected]>
  • Loading branch information
kzys committed Apr 19, 2022
1 parent 5f3b724 commit 3742c75
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/protoc-gen-go-fieldpath/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ func collectChildlen(parent *protogen.Message) ([]*protogen.Message, 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
for _, m := range input.Messages {
messages = append(messages, m)
Expand All @@ -176,6 +169,18 @@ func generate(plugin *protogen.Plugin, input *protogen.File) error {
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 {
gen.genFieldMethod(m)
}
Expand Down

0 comments on commit 3742c75

Please sign in to comment.