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

x/tools/cmd/guru: GOROOT needs to be set for guru #22418

Closed
yaojingguo opened this issue Oct 24, 2017 · 8 comments
Closed

x/tools/cmd/guru: GOROOT needs to be set for guru #22418

yaojingguo opened this issue Oct 24, 2017 · 8 comments
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@yaojingguo
Copy link
Contributor

yaojingguo commented Oct 24, 2017

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

go version go1.9.1 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jing/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qd/wj_djys9219cyj4l9c2qw6g80000gn/T/go-build712584400=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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"

Steps to reproduce the problem

I had installed go 1.8.3 in /usr/local/Cellar/go/1.8.3/libexec with brew before. But I had uninstalled it and installed Go 1.9.1.

I checked that GOROOT was unset in the terminal with echo $GOROOT. Then I ran guru definition main.go:#56. But guru said guru: cannot find package "fmt" . Here is the terminal session details:

➜  cockroach git:(master) ✗ echo $GOROOT

➜  cockroach git:(master) ✗ guru definition main.go:#56
guru: cannot find package "fmt" in any of:
	/Users/jing/go/src/github.com/cockroachdb/cockroach/vendor/fmt (vendor tree)
	/usr/local/Cellar/go/1.8.3/libexec/src/fmt (from $GOROOT)
	/Users/jing/go/src/fmt (from $GOPATH)
➜  cockroach git:(master) ✗

Then I ran export GOROOT=/usr/local/go in the same terminal. And then running guru definition main.go:#56 produced:

/usr/local/go/src/fmt/print.go:256:6: defined here as func fmt.Println

main.go is on https://play.golang.org/p/eEZMXonMhA.

And rogpeppe/godef#73 is a similar problem.

@gopherbot gopherbot added this to the Unreleased milestone Oct 24, 2017
@cznic
Copy link
Contributor

cznic commented Oct 24, 2017

I guess your environment variable GOROOT, if set, points to a wrong location. If it is not set, I guess the Go installation was made to a wrong place. It thinks it's in /usr/local/Cellar/go/1.8.3/libexec/, but you say it was installed in /usr/local/Cellar/go/1.8.3/ instead.

And finally, the workaround indicates that Go was perhaps actually installed in /usr/local/go/. The guesses are mutually exclusive, I think your current Go installation is somehow a corrupted mix of more than one installation.

Also trying to set GOPATH to point to GOROOT is probably not going to work well.

@yaojingguo
Copy link
Contributor Author

@cznic I have made several mistakes in my comment. Sorry for that. GOPATH should be GOROOT. And Go 1.8.3 was in /usr/local/Cellar/go/1.8.3/libexec before I uninstalled it.

I have updated my original comment.

@ianlancetaylor ianlancetaylor changed the title x/tools/cmd/guru: GOPATH needs to be set for guru x/tools/cmd/guru: GOROOT needs to be set for guru Oct 24, 2017
@ianlancetaylor
Copy link
Contributor

CC @alandonovan

I assume that you built guru yourself, and that it captured the setting of GOROOT used by the tools used to build it. Then you moved your installation, so guru was using the old GOROOT and was not finding anything in the new GOROOT.

I have not looked at the code, but perhaps guru should run go env GOROOT to determine the GOROOT value to use, rather than calling runtime.GOROOT. If that sounds right to @alandonovan , would you like to send a patch?

@dominikh
Copy link
Member

This sounds strongly related to #22303, and affects all static analysis tools.

@yaojingguo
Copy link
Contributor Author

@ianlancetaylor yes, sure

@natefinch
Copy link
Contributor

@dominikh - definitely the same problem.

@yaojingguo - if you want to avoid setting GOROOT, you can also rebuild the guru with your current set up, which will detect & embed the new (correct) GOROOT.

@yaojingguo
Copy link
Contributor Author

yaojingguo commented Oct 30, 2017

@natefinch Thanks. Rebuilding guru works.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 12, 2019
@stamblerre
Copy link
Contributor

Closing, as setting GOROOT is no longer needed with more recent versions of Go.

More context can be found in golang/vscode-go#146, and @hyangah has confirmed that it is no longer necessary to recompile tools when the Go version changes. Furthermore, guru is no longer maintained.

@golang golang locked and limited conversation to collaborators Jun 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

7 participants