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: emits warning when GOPATH == GOROOT #65656

Closed
KumanekoSakura opened this issue Feb 11, 2024 · 5 comments
Closed

cmd/go: emits warning when GOPATH == GOROOT #65656

KumanekoSakura opened this issue Feb 11, 2024 · 5 comments

Comments

@KumanekoSakura
Copy link

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

warning: GOPATH set to GOROOT (/home/kumaneko/go) has no effect
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/kumaneko/.cache/go-build'
GOENV='/home/kumaneko/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/kumaneko/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/kumaneko/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/kumaneko/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/kumaneko/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='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-build871568154=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I noticed that go 1.22 started emitting

  warning: GOPATH set to GOROOT ($HOME/go) has no effect

and VSCode plugin noisily emits "Failed to run ..." messages
due to this warning message.

Installing under $HOME worked without problems until go 1.21.7.
Also, full bisection between go1.21.0 and go1.22.0 pointed at
commit fa72f3e ("[release-branch.go1.22] go1.22rc1").

If this is an intentional change, please update https://go.dev/doc/install
to explicitly comment that installing under $HOME is not possible.
Or maybe remove this warning from src/cmd/go/main.go , for this warning
is not fatal enough to justify "Failed to run ..." messages?

What did you see happen?

$ tar -C ~ -xzf go1.22.0.linux-amd64.tar.gz
$ export PATH=$PATH:~/go/bin/
$ go version
warning: GOPATH set to GOROOT (/home/kumaneko/go) has no effect
go version go1.22.0 linux/amd64

What did you expect to see?

$ tar -C ~ -xzf go1.22.0.linux-amd64.tar.gz
$ export PATH=$PATH:~/go/bin/
$ go version
go version go1.22.0 linux/amd64

@fzipp
Copy link
Contributor

fzipp commented Feb 11, 2024

It's definitely still possible, because I do it as well.

GOPATH='/home/kumaneko/go'
GOROOT='/home/kumaneko/go'

Your GOPATH and GOROOT are the same. If Go is installed in /home/kumaneko/go (GOROOT), then GOPATH must be set to a different directory.

@KumanekoSakura
Copy link
Author

If Go is installed in /home/kumaneko/go (GOROOT), then GOPATH must be set to a different directory.

What does "must" here mean? Did the meaning of "must" changed in 1.22?

No warning was emitted and plugins silently worked until 1.21.7, without making GOPATH and GOROOT different.

Interestingly, no warning is emitted on current head of go.git tree.

go version devel go1.23-4a7f3ac8eb Sat Feb 10 02:14:22 2024 +0000 linux/amd64

This warning is emitted if I do

$ echo 'go1.23devel' > VERSION
$ echo 'time 2024-02-11T15:14:00Z' >> VERSION

before building current head of go.git tree.

Why does creating the VERSION file cause this warning message to appear?

@seankhliao seankhliao changed the title Is installing go under $HOME no longer possible? cmd/go: emits warning when GOPATH == GOROOT Feb 11, 2024
@seankhliao
Copy link
Member

The VERSION file has no effect, your testing of it is wrong.

I believe this is working as intended,
the warning has been in place for a long time, but cmd/go wasn't emitting the warning previously when it should have. See CL 543955.

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

The VERSION file has no effect, your testing of it is wrong.

The VERSION file indeed has some effect. Full bisection between go1.21rc1~1 and
go1.22rc1~1 with the VERSION file added pointed at commit 841e63e ("cmd/go:
don't warn about GOROOT equal to GOPATH when both are the empty string").

I believe this is working as intended, the warning has been in place for
a long time, but cmd/go wasn't emitting the warning previously when it
should have. See CL 543955.

Since I was able to use go without problems using default GOPATH value, I don't
know what will break by setting GOPATH to a different location. What value is
recommended for GOPATH when GOROOT is set to $HOME/go ?

My expectation is that we don't need to take care of GOPATH and GOROOT because
GO111MODULE is enabled by default since 1.16. Then, I expect cmd/go not to emit
this warning, for emitting warnings on unused setting is confusing/misleading.

@ianlancetaylor
Copy link
Contributor

Although GOPATH is not used as much for modules, it is still used. For example, go install will install commands into $GOPATH/bin.

If you use $HOME/go for GOROOT, there is no particular recommended value for GOPATH. Personally I use $HOME/gopath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants