From d5451f02f0d0ae2e22365b4f0ccd813593056467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 8 Apr 2023 20:58:02 +0100 Subject: [PATCH] support -ldflags=main.version= again I rolled back the build via the proxy in my go-cross build script, as that sort of thing is incompatible with how many packagers and distributions automatically build Go software. Fixes #253 again. --- format/format.go | 2 +- gofmt.go | 6 ++++-- internal/version/version.go | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/format/format.go b/format/format.go index d0917f6..36da9fb 100644 --- a/format/format.go +++ b/format/format.go @@ -395,7 +395,7 @@ func (f *fumpter) applyPre(c *astutil.Cursor) { slc := []string{ "//gofumpt:diagnose", "version:", - version.String(), + version.String(""), "flags:", "-lang=" + f.LangVersion, "-modpath=" + f.ModulePath, diff --git a/gofmt.go b/gofmt.go index 1553ae7..9e445f3 100644 --- a/gofmt.go +++ b/gofmt.go @@ -30,7 +30,7 @@ import ( gformat "mvdan.cc/gofumpt/format" "mvdan.cc/gofumpt/internal/govendor/diff" "mvdan.cc/gofumpt/internal/govendor/go/printer" - "mvdan.cc/gofumpt/internal/version" + gversion "mvdan.cc/gofumpt/internal/version" ) //go:generate go run gen_govendor.go @@ -57,6 +57,8 @@ var ( simplifyAST = flag.Bool("s", false, "") ) +var version = "" + // Keep these in sync with go/format/format.go. const ( tabWidth = 8 @@ -464,7 +466,7 @@ func gofmtMain(s *sequencer) { // Print the gofumpt version if the user asks for it. if *showVersion { - fmt.Println(version.String()) + fmt.Println(gversion.String(version)) return } diff --git a/internal/version/version.go b/internal/version/version.go index 9929304..785b6b3 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -97,6 +97,9 @@ func goVersion() string { return runtime.Version() } -func String() string { +func String(injected string) string { + if injected != "" { + return fmt.Sprintf("%s (%s)", injected, goVersion()) + } return fmt.Sprintf("%s (%s)", gofumptVersion(), goVersion()) }