go: x/tools/cmd/godoc: Does not infer $GOROOT from path to binary
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.10beta2 linux/amd64
Does this issue reproduce with the latest release?
Yes, but Go 1.10 is supposed to change that, https://tip.golang.org/doc/go1.10#goroot
(Awesome change by the way!)
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/fd0/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/fd0/shared/work/go"
GORACE=""
GOROOT="/home/fd0/Downloads/go1.10beta2"
GOTMPDIR=""
GOTOOLDIR="/home/fd0/Downloads/go1.10beta2/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-build797922256=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Without $GOROOT explicitely set, Go 1.10 infers the Go root directory from the location of the go binary as it called:
$ unset GOROOT
$ pwd
/home/fd0/Downloads/go1.10beta2
$ bin/go version
go version go1.10beta2 linux/amd64
$ bin/go env GOROOT
/home/fd0/Downloads/go1.10beta2
But this does not work for godoc:
$ bin/godoc os Exit
2018/01/15 14:17:19 cannot find package "." in:
/src/os
$ bin/godoc -http :6060
2018/01/15 14:17:34 newDirectory(/): stat /usr/local/go: no such file or directory
2018/01/15 14:17:34 godoc: corpus fstree is nil
Explicitely setting GOROOT (like in Go < 1.10) works:
$ GOROOT=$PWD bin/godoc os Exit
use 'godoc cmd/os' for documentation on the os command
func Exit(code int)
Exit causes the current program to exit with the given status code.
Conventionally, code zero indicates success, non-zero an error. The
program terminates immediately; deferred functions are not run.
What did you expect to see?
godoc finds the Go root directory ($GOROOT) by itself, like the go binary does. This is advertised as one of the (awesome) changes of Go 1.10, apparently it does not work for godoc yet, which is unexpected.
What did you see instead?
The Go root directory is not detected automatically, I needed to set it manually via $GOROOT.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 38 (20 by maintainers)
I think this is a bug. The
godocbinary from a released version of Go behaves differently than thegobinary, it requires users to manually setGOROOTbefore it can be used, that should be corrected. So let’s agree to disagree 😃The only version of godoc I have is in
$GOPATH/bin. There is nogodocat/usr/lib/go-1.10/bin/, which is where thegobinary lives.Oh I see. The godoc needs to come from the installed go distribution. If you update godoc manually, it will get installed in $GOBIN. Please check the output of
which godocandwhich go. If they are same, and you still see the issue, please open a new issue. If they are different, then there is no issue.It’s not clear to me why this was closed. I just installed the latest version of godoc by running
go get -u golang.org/x/tools/cmd/godocand I’m still seeing the same error:I’m on an Ubuntu 16.04 system and I installed Go using the xenial-backports package 1.10-1ubuntu1~16.04.1.
I still think it’s somewhat problematic that
runtime.GOROOT()doesn’t return the correctGOROOT(i.e. not whatgo envwould print). Ultimately this problem affects all the callers ofruntime.GOROOT(), not justgodoc.I spent half an hour trying to find out where
godocgets itsGOROOTwhen none is specified (via command line-gorootor environment), but did not succeed. If someone can point me into the right direction, I’ll try to prepare a PR (or whatever that’s called for Gerrit).