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/godoc: godoc doesn't respect the implicit GOROOT / -goroot #25004

Closed
tsuna opened this issue Apr 23, 2018 · 1 comment
Closed

x/tools/godoc: godoc doesn't respect the implicit GOROOT / -goroot #25004

tsuna opened this issue Apr 23, 2018 · 1 comment

Comments

@tsuna
Copy link
Contributor

tsuna commented Apr 23, 2018

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

go version go1.10.1 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/local"
GOTMPDIR=""
GOTOOLDIR="/usr/local/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build709421669=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Use the following Dockerfile:

FROM ubuntu

ADD https://dl.google.com/go/go1.10.1.linux-amd64.tar.gz /tmp
RUN tar -C /usr/local --strip-components=1 -xzf /tmp/go1.10.1.linux-amd64.tar.gz
RUN mkdir -p /go/src/foo
RUN printf 'package main\nimport "fmt"\nfunc main() {fmt.Println("Hello, godoc")}' >/go/src/foo/main.go

ENV GOPATH /go

Please note that this is installing Go directly under /usr/local and not /usr/local/go as the recommended installation instructions do. I haven't found any issue with this so far other than this problem with godoc.

Build the image with docker build . and then fire it up with docker run -it <the-image-you-built> bash

Once in the container:

root@1015578e9135:/# godoc -http=:8055 -analysis=type
2018/04/23 08:29:32 newDirectory(/): stat /usr/local/go: no such file or directory
2018/04/23 08:29:32 godoc: corpus fstree is nil
root@1015578e9135:/# godoc -goroot=/usr/local -http=:8055 -analysis=type
2018/04/23 08:29:36 GOROOT=/usr/local/go/src/: []
2018/04/23 08:29:36 GOPATH[0]=/go/src/: [foo]
2018/04/23 08:29:36 Loading and type-checking packages...
/go/src/foo/main.go:2:8: could not import fmt (cannot find package "fmt" in any of:
	/usr/local/go/src/fmt (from $GOROOT)
	/go/src/fmt (from $GOPATH))
2018/04/23 08:29:36 Loaded 1 packages.
2018/04/23 08:29:36 Constructing SSA form...
2018/04/23 08:29:36 SSA construction complete
2018/04/23 08:29:36 Computing implements relation...
2018/04/23 08:29:36 Extracting type info...
2018/04/23 08:29:36 Visit instructions...
2018/04/23 08:29:36 Visit instructions complete
2018/04/23 08:29:36 Type analysis complete.

The only thing that works is setting the GOROOT environment variable:

root@1015578e9135:/# GOROOT=/usr/local godoc -http=:8055 -analysis=type
2018/04/23 08:29:49 GOROOT=/usr/local/src/: [archive archive/tar ...etc...]
2018/04/23 08:29:50 GOPATH[0]=/go/src/: [foo]
2018/04/23 08:29:50 Loading and type-checking packages...
[...]

What did you expect to see?

godoc should be able to load the standard library by honoring the default implicit value of GOROOT as printed by go env. Or at least setting the -goroot flag should work.

What did you see instead?

godoc fails to load standard library packages unless GOROOT is set.

@gopherbot gopherbot added this to the Unreleased milestone Apr 23, 2018
@tsuna
Copy link
Contributor Author

tsuna commented Apr 23, 2018

Awww, of course it's right after filing the issue that I find it's a dup. This is already filed under #23445. I swear I looked for godoc issues first, but not hard enough apparently! Sorry for the noise.

@tsuna tsuna closed this as completed Apr 23, 2018
@golang golang locked and limited conversation to collaborators Apr 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants