Skip to content

Commit

Permalink
Stablise program name in generated code preamble (#610)
Browse files Browse the repository at this point in the history
This PR fixes inconsistencies when running `protoc-gen-connect-go` on
Windows vs Linux.
  • Loading branch information
trixnz authored Oct 18, 2023
1 parent 96effed commit b6d44ec
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/protoc-gen-connect-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ func generatePreamble(g *protogen.GeneratedFile, file *protogen.File) {
leadingComments(g, protogen.Comments(syntaxLocation.LeadingComments), false /* deprecated */)
g.P()

g.P("// Code generated by ", filepath.Base(os.Args[0]), ". DO NOT EDIT.")
programName := filepath.Base(os.Args[0])
// Remove .exe suffix on Windows so that generated code is stable, regardless
// of whether it was generated on a Windows machine or not.
if ext := filepath.Ext(programName); strings.ToLower(ext) == ".exe" {
programName = strings.TrimSuffix(programName, ext)
}
g.P("// Code generated by ", programName, ". DO NOT EDIT.")
g.P("//")
if file.Proto.GetOptions().GetDeprecated() {
wrapComments(g, file.Desc.Path(), " is a deprecated file.")
Expand Down

0 comments on commit b6d44ec

Please sign in to comment.