From e8bf0492d70057e9012dd4cfa84b4d1b30964302 Mon Sep 17 00:00:00 2001 From: Cam Date: Tue, 17 Oct 2023 13:21:00 +0200 Subject: [PATCH 1/2] fix: trim program extension from preamble --- cmd/protoc-gen-connect-go/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/protoc-gen-connect-go/main.go b/cmd/protoc-gen-connect-go/main.go index ba3509ce..09351c18 100644 --- a/cmd/protoc-gen-connect-go/main.go +++ b/cmd/protoc-gen-connect-go/main.go @@ -150,7 +150,9 @@ 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]) + programNameWithoutExt := strings.TrimSuffix(programName, filepath.Ext(programName)) + g.P("// Code generated by ", programNameWithoutExt, ". DO NOT EDIT.") g.P("//") if file.Proto.GetOptions().GetDeprecated() { wrapComments(g, file.Desc.Path(), " is a deprecated file.") From 06918035e99ff5e80d893a3142da524842bc4b76 Mon Sep 17 00:00:00 2001 From: Cam Date: Wed, 18 Oct 2023 09:16:40 +0200 Subject: [PATCH 2/2] Update cmd/protoc-gen-connect-go/main.go Only remove the extension when it is `.exe` (Windows) Co-authored-by: Joshua Humphries <2035234+jhump@users.noreply.github.com> --- cmd/protoc-gen-connect-go/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/protoc-gen-connect-go/main.go b/cmd/protoc-gen-connect-go/main.go index 09351c18..bde19f51 100644 --- a/cmd/protoc-gen-connect-go/main.go +++ b/cmd/protoc-gen-connect-go/main.go @@ -151,8 +151,12 @@ func generatePreamble(g *protogen.GeneratedFile, file *protogen.File) { g.P() programName := filepath.Base(os.Args[0]) - programNameWithoutExt := strings.TrimSuffix(programName, filepath.Ext(programName)) - g.P("// Code generated by ", programNameWithoutExt, ". DO NOT EDIT.") + // 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.")