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: warn if implicit GOPATH is equal to GOROOT #24623

Closed
benesch opened this issue Mar 31, 2018 · 9 comments
Closed

cmd/go: warn if implicit GOPATH is equal to GOROOT #24623

benesch opened this issue Mar 31, 2018 · 9 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@benesch
Copy link
Contributor

benesch commented Mar 31, 2018

What version of Go are you using (go version)?

$ go version
go version devel +ad0ebc3 Tue Mar 27 19:55:14 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/benesch/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/benesch/go"
GORACE=""
GOROOT="/home/benesch/go1.10"
GOTMPDIR=""
GOTOOLDIR="/home/benesch/go1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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-build523055646=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I ran:

$ GOROOT=$HOME/go GOPATH= go env GOPATH
# no output

What did you expect to see?

The warning you normally see when GOROOT is set to the same value as GOPATH, followed by the value of GOPATH:

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

What did you see instead?

Neither the warning nor the value of GOPATH.

@davecheney
Copy link
Contributor

davecheney commented Mar 31, 2018 via email

@AlexRouSg
Copy link
Contributor

@davecheney I believe he is referring to the lack of warning when overriding goroot to be the same as gopath when gopath is unset.

@benesch
Copy link
Contributor Author

benesch commented Mar 31, 2018

@davecheney I believe he is referring to the lack of warning when overriding goroot to be the same as gopath when gopath is unset.

Yes, exactly. Sorry, I should have been more clear. I don't actually expect setting GOROOT and GOPATH like this to be usable.

@benesch benesch changed the title cmd/go: GOROOT of $HOME/go not handled correctly cmd/go: GOROOT of $HOME/go does not produce warning Mar 31, 2018
@davecheney
Copy link
Contributor

If I recall, that warning is only in the go get/build/install path.

@benesch
Copy link
Contributor Author

benesch commented Apr 1, 2018

My experiments disagree. It's certainly in the go env path, because it shows up in go env's output for any other bad combination of GOROOT/GOPATH:

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

$ GOROOT=$HOME/go GOPATH= go env GOPATH
# no output

Based on my source spelunking, it seems like the only command that's exempt is go help:

if gopath := cfg.BuildContext.GOPATH; filepath.Clean(gopath) == filepath.Clean(runtime.GOROOT()) {

@bcmills bcmills changed the title cmd/go: GOROOT of $HOME/go does not produce warning cmd/go: warn if GOROOT is set to implicit GOPATH Apr 2, 2018
@bcmills bcmills changed the title cmd/go: warn if GOROOT is set to implicit GOPATH cmd/go: warn if implicit GOPATH is equal to GOROOT Apr 2, 2018
@bcmills
Copy link
Contributor

bcmills commented Apr 2, 2018

I see the same issue with go test:

~$ GOROOT=~/go GOPATH= go test sync
ok      sync    0.496s
~$ GOROOT=~/go GOPATH=$GOROOT go test sync
warning: GOPATH set to GOROOT (/home/bcmills/go) has no effect
ok      sync    (cached)

@bcmills bcmills added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 2, 2018
@bcmills bcmills added this to the Go1.11 milestone Apr 2, 2018
@rsc
Copy link
Contributor

rsc commented Apr 18, 2018

The implicit GOPATH is never equal to GOROOT.

If the default GOPATH value would have been equal to GOROOT, it is left unset, which avoids creating the problem you are suggesting to warn about.

@rsc rsc closed this as completed Apr 18, 2018
@benesch
Copy link
Contributor Author

benesch commented Apr 18, 2018 via email

@ianlancetaylor
Copy link
Member

The longer term plan is likely to remove GOPATH.

Other than that I think you are describing documentation issues. I don't see any useful code changes that we could make. I think that a warning GOPATH set to GOROOT would be confusing and meaningless when GOPATH is not set.

@golang golang locked and limited conversation to collaborators Apr 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants