Skip to content

No way to get gofmt’s version #65933

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
dilyanpalauzov opened this issue Feb 25, 2024 · 4 comments
Closed

No way to get gofmt’s version #65933

dilyanpalauzov opened this issue Feb 25, 2024 · 4 comments

Comments

@dilyanpalauzov
Copy link

Go version

go version go1.21.7 linux/amd64 and go version go1.21.7 linux/amd64

Output of go env in your module/workspace:

This is irrelevant, but anyway, with go from golang:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/usr/local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/usr/local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/git/goroot'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/git/goroot/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.7'
GCCGO='/usr/local/bin/gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build700299863=/tmp/go-build -gno-record-gcc-switches'

go env from “gccgo”:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT="fieldtrack,regabiwrappers"
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/share/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/share/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/libexec/gcc/x86_64-pc-linux-gnu/13.2.1"
GOVCS=""
GOVERSION="go1.18 gccgo (GCC) 13.2.1 20230731"
GCCGO="/usr/local/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build454846075=/tmp/go-build -gno-record-gcc-switches -funwind-tables"


### What did you do?

`gofmt`, just as `go`, can be provided by “golang” or by “gccgo”.  `go version` does print `go version go1.18 gccgo (GCC) 13.2.1 20230731 linux/amd64` or `go version go1.21.7 linux/amd64`, making clear not only the used version, but also whether it is from “goclang” or from “gccgo”.



### What did you see happen?

On `gofmt -h` I see

usage: gofmt [flags] [path ...]
-cpuprofile string
write cpu profile to this file
-d display diffs instead of rewriting files
-e report all errors (not just the first 10 on different lines)
-l list files whose formatting differs from gofmt's
-r string
rewrite rule (e.g., 'a[b:len(a)] -> a[b:]')
-s simplify code
-w write result to (source) file instead of stdout


### What did you expect to see?

• On `gofmt -h` I expect to see a way to extract the version of `gofmt`. 
• `gofmt --version` shall print the version of gofmt, and whether it comes from golang or from gccgo
@zigo101
Copy link

zigo101 commented Feb 25, 2024

go version `which gofmt`

@dilyanpalauzov
Copy link
Author

dilyanpalauzov commented Feb 25, 2024

On my system gofmt.alt-gcc13.2.1 originates from gccgo, whatever was on the releases/gcc-13 branch in July 2023. When I run go version ./gofmt.alt-gcc13.2.1 it prints ./gofmt.alt-gcc13.2.1: could not read Go build info from ./gofmt.alt-gcc13.2.1: not a Go executable.

./go.alt-gcc13.2.1 is from gccgo. ./go.alt-gcc13.2.1 version ./gofmt.alt-gcc13.2.1 prints ./gofmt.alt-gcc13.2.1: could not read Go build info from ./gofmt.alt-gcc13.2.1: not a Go executable.

So go version $(which gofmt) runs, when gofmt is not from gccgo.

@seankhliao
Copy link
Member

where it comes from is irrelevant, there's only a single implementation of gofmt, unlike gccgo which is a different implementation.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 25, 2024
@dilyanpalauzov
Copy link
Author

If I remember correctly, compiling gcc does produce also gofmt. For it go version $(which gofmt) does not work.

@golang golang locked and limited conversation to collaborators Feb 24, 2025
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

4 participants