Skip to content

Commit

Permalink
support -ldflags=main.version= again
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvdan committed Apr 8, 2023
1 parent 92e2be6 commit d5451f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion format/format.go
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions gofmt.go
Expand Up @@ -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
Expand All @@ -57,6 +57,8 @@ var (
simplifyAST = flag.Bool("s", false, "")
)

var version = ""

// Keep these in sync with go/format/format.go.
const (
tabWidth = 8
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion internal/version/version.go
Expand Up @@ -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())
}

0 comments on commit d5451f0

Please sign in to comment.