Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

cmd/go: go tool -n can point to a file that doesn't exist #72824

Open
iwahbe opened this issue Mar 12, 2025 · 4 comments
Open

cmd/go: go tool -n can point to a file that doesn't exist #72824

iwahbe opened this issue Mar 12, 2025 · 4 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@iwahbe
Copy link

iwahbe commented Mar 12, 2025

Go version

go version go1.24.1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/ianwahbe/go/bin'
GOCACHE='/Users/ianwahbe/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/ianwahbe/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/fg/_1q36r4j6yx0rwz2fbhjd5y40000gn/T/go-build3052038314=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/ianwahbe/go/src/github.com/example/empty/go.mod'
GOMODCACHE='/Users/ianwahbe/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/ianwahbe/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.1/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/ianwahbe/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I was using go tool -n github.com/iwahbe/helpmakego in my Makefile to work around #71733 like this:

HELPMAKEGO := $(shell go tool -n github.com/iwahbe/helpmakego)

# Use the tool as intended - details don't really matter here
$(shell ${HELPMAKEGO} ...)

I noticed that sometimes $(shell ${HELPMAKEGO} ...) would fail unexpectedly, saying that there was no file at ${HELPMAKEGO}.

I can replicate this behavior locally:

$ mkdir repro
$ go mod init
$ go get -tool github.com/iwahbe/helpmakego
$ go tool -n github.com/iwahbe/helpmakego | tee should_exist && rm $(cat should_exist)
/Users/ianwahbe/Library/Caches/go-build/c5/c503c5059f1c48a29b1dc68749074f475aaf82c717ef355e7079f7e9b4116c2b-d/helpmakego
$ go tool -n github.com/iwahbe/helpmakego | tee should_exist && rm $(cat should_exist)
/var/folders/fg/_1q36r4j6yx0rwz2fbhjd5y40000gn/T/go-build1160981703/b001/exe/helpmakego
rm: /var/folders/fg/_1q36r4j6yx0rwz2fbhjd5y40000gn/T/go-build1160981703/b001/exe/helpmakego: No such file or directory
$ go tool -n github.com/iwahbe/helpmakego | tee should_exist && rm $(cat should_exist)
/Users/ianwahbe/Library/Caches/go-build/c5/c503c5059f1c48a29b1dc68749074f475aaf82c717ef355e7079f7e9b4116c2b-d/helpmakego
$ go tool -n github.com/iwahbe/helpmakego | tee should_exist && rm $(cat should_exist)
/var/folders/fg/_1q36r4j6yx0rwz2fbhjd5y40000gn/T/go-build1221207145/b001/exe/helpmakego
rm: /var/folders/fg/_1q36r4j6yx0rwz2fbhjd5y40000gn/T/go-build1221207145/b001/exe/helpmakego: No such file or directory

You will see that every other time go tool -n github.com/iwahbe/helpmakego it points to a file that doesn't exist.

What did you see happen?

$ go tool -n github.com/iwahbe/helpmakego
/var/folders/fg/_1q36r4j6yx0rwz2fbhjd5y40000gn/T/go-build1221207145/b001/exe/helpmakego

What did you expect to see?

I expect that any time go tool -n ... is run, it will point to a runnable executable.

If that isn't true, then go help tool should document what conditions are necessary to ensure that go tool -n ... will point to an executable file.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 12, 2025
@seankhliao
Copy link
Member

seems like when it builds a tool it prints the location of it in the temporary work directory, rather than the final location in the build cache

@ianlancetaylor
Copy link
Member

CC @matloob @samthanawalla

@ianlancetaylor ianlancetaylor added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 12, 2025
@KirtanSoni
Copy link

I figured out the cause on the bug. would u mind if i take this issue up and propose a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants