Open mejedi opened 1 year ago
how did you end up with GOROOT == GOPATH?
what's in /home/nickz/.config/go/env
?
@seankhliao
how did you end up with GOROOT == GOPATH?
By unpacking the tarball into ~/go
. Is it not supposed to work?
$ which go
/home/nickz/go/bin/go
The config file doesn't exist.
I can confirm that the issue goes away when GOROOT != GOPATH.
That's perhaps the only place where it doesn't work. GOROOT == place where go is installed needs to be different from GOPATH == place where it places some user data
I don't think we recommend doing what you did anywhere?
I don’t think “first party” resources suggest doing what I did. There might have been some third party ones, at least some years back when I did the setup.
It would be nice if the toolchain plain rejected this invalid setup rather than breaking in subtle ways.
Otherwise, please feel free to close. Thank you very much for the help!
It would be nice if the toolchain plain rejected this invalid setup rather than breaking in subtle ways.
It is supposed to: https://cs.opensource.google/go/go/+/master:src/cmd/go/main.go;l=121;drc=44e51e60acb8a1ff6ba10d698615fde98b2b28b0
However, that warning has no effect if GOPATH
is not set explicitly:
https://cs.opensource.google/go/go/+/master:src/go/build/build.go;l=298-302;drc=d22f287f12f4782082cd93785ad91e78dbe0d4d6
It looks like the attempt to improve the error message in https://go.dev/cl/331529 was incomplete. It should probably be extended to more places.
Change https://go.dev/cl/538738 mentions this issue: cmd/go: return a warning if GOROOT is the same as default GOPATH
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
It used to be possible to have
go run
inside//go:generate
lines. It is very handy since a project can require the specific generator version viago.mod
.Following examples by
cilium/ebpf
, I created amain.go
file...and invoked
go generate ./...
.(I'm using a specific generator in my bug report, but it looks like a generic issue affecting anyone using
go run
insidego:generate
technique. Therefore I believe that the specific generator being used is irrelevant.)What did you expect to see?
The generator to complain about missing arguments.
What did you see instead?
Further info
If I invoke
go run
directly, everything works as expected.It's clear that the generator gets executed and complains as expected.
However, if I set
GOROOT
(asgo generate
does):Changing
go:generate
line as below also "fixes" the problem:I believe that I have the most boring go setup possible.
$ env | grep GO
yields nothing.