-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/godoc: Does not infer $GOROOT from path to binary #23445
Comments
I spent half an hour trying to find out where |
Is this something that's relevant to get into 1.10? Or just "sometime"? I'm asking because I can spend some time on it this week, if it's relevant enough... |
go1.10 is pretty much done at this point. Also note that the release notes say
"the go tool" == the |
It seems like you have a fresh machine without a previous go installation. Because I have tried to repro your issue and it seems to work fine for me. Only when I renamed the GOROOT directory (/usr/local/go) to /usr/local/something, I can see your issue. $unset GOROOT
$~/play/go/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. But, if I do - $unset GOROOT
$sudo mv /usr/local/go /usr/local/something
$~/play/go/bin/godoc os Exit
2018/01/17 11:23:04 main.go:345: cannot find package "." in:
/src/os
|
@fd0 |
This issue is about the
It only works when users manually set
I can build a new I think it'd be great to make |
Thanks. It seems to me that godoc is not bugged. It has built in $GOROOT path into it. Also it might be problematic to solve this bug because godoc can be installed into $GOPATH/bin and it would be not able to infer the correct path to $GOROOT. My advise is to build godoc via |
I think this is a bug. The |
I concur with @fd0 that this is undesirable behavior; whether it's a bug or feature request isn't a key distinction. Either way it certainly violates the principle of least surprise. I never install Go in /usr/local since 1) it's just my developer tool, not something machine-wide, so why bother with 'sudo' and root access? and 2) I need to have multiple side-by-side Go versions available. I typically only add the latest one to my PATH, and I expected that this 1.10 godoc would have the same new feature that go 1.10 does for detecting GOROOT. |
Obvious solution would be to copy findGOROOT from go sources to godoc. But I am not sure if this is the best one. What do you think?
|
I think this is a good solution. We need to make sure that should this behavior change in the future, both places are updated. Or is it maybe desirable to export the |
Hm. // GOROOT returns the root of the Go tree. It uses the
// GOROOT environment variable, if set at process start,
// or else the root used during the Go build.
func GOROOT() string {
s := gogetenv("GOROOT")
if s != "" {
return s
}
return sys.DefaultGoroot
} Maybe this function should auto-detect the It feels to me I haven't understood the problem completely. Did I overlook something? |
Only the Is there any other way to share ping @rsc |
Regardless of the assumption used by |
Related- #13296. |
Indeed this is a bit problematic. Ideally, we should not keep duplicate copies of Should we -
@tsuna - I am going to bring this back to NeedsDecision as I don't see a clear way for a fix. @ianlancetaylor , @andybons , @rsc - Feel free to comment. |
Sorry, I haven't tried to keep track of the various varieties of godoc (I think we're up to four now). CC @griesemer in case he has something to add. |
cc: @dsnet |
Copying the GOROOT-finding code from cmd/go is OK to do in godoc. |
I still think it's somewhat problematic that |
Change https://golang.org/cl/118075 mentions this issue: |
Change https://golang.org/cl/118077 mentions this issue: |
Updates #23445 Change-Id: I4b09073e53b1cf04de698b711fb5fb0d08bc02df Reviewed-on: https://go-review.googlesource.com/118077 Reviewed-by: Ian Lance Taylor <[email protected]>
It's not clear to me why this was closed. I just installed the latest version of godoc by running
I'm on an Ubuntu 16.04 system and I installed Go using the xenial-backports package 1.10-1ubuntu1~16.04.1. |
Umm .. you are using Go 1.10. This is fixed in 1.11. |
I installed the latest godoc from the repo with |
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 |
The only version of godoc I have is in |
Also, I checked the file size before & after running |
If you stumble on this issue, make sure that your golang installation comes from the original instructions rather than some third party unofficial launchpad. To point to @agnivade remark which lead me to understand how to fix this issue. |
Go SDKs installed with |
@tv42, neither does Go 1.13: https://golang.org/doc/go1.13#godoc |
@bradfitz So it really sounds like this should not have been closed, then? |
Why do you say that? |
As far as I can see, godoc is broken in exactly the ways the previous commenters have described. |
Indeed, once @bradfitz - This will diverge from the |
Reopening. Diverging from cmd/go's logic is fine. Anybody want to take this? |
Sure. |
Change https://golang.org/cl/199279 mentions this issue: |
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
)?What did you do?
Without
$GOROOT
explicitely set, Go 1.10 infers the Go root directory from the location of thego
binary as it called:But this does not work for
godoc
:Explicitely setting
GOROOT
(like in Go < 1.10) works:What did you expect to see?
godoc
finds the Go root directory ($GOROOT
) by itself, like thego
binary does. This is advertised as one of the (awesome) changes of Go 1.10, apparently it does not work forgodoc
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
.The text was updated successfully, but these errors were encountered: