]> Cypherpunks repositories - gostls13.git/commit
cmd/go: set GOROOT explicitly for 'go generate' subprocesses
authorBryan C. Mills <bcmills@google.com>
Fri, 8 Apr 2022 19:26:38 +0000 (15:26 -0400)
committerBryan Mills <bcmills@google.com>
Tue, 12 Apr 2022 03:13:39 +0000 (03:13 +0000)
commitf2d9ab263b8c62a81d314feb1e7a7fb424bb9c43
tree63da9196bb2e4913d7514a85ad083f3980940682
parente299381cd1b4b7efecf7642ebfcd5e76ffa65e6d
cmd/go: set GOROOT explicitly for 'go generate' subprocesses

Code generators may reasonably expect to find the GOROOT for which the
code is being generated.

If the generator invokes 'go run' (which ought to be reasonable to do)
and the user has set 'GOFLAGS=trimpath' (which also ought to be
reasonable), then either 'go generate' or 'go run' needs to set GOROOT
explicitly.

I would argue that it is more appropriate for 'go generate' to set
GOROOT than for 'go run' to do so, since a user may reasonably invoke
'go run' to reproduce a user-reported bug in a standalone Go program,
but should not invoke 'go generate' except to regenerate code for a Go
package.

Updates #51461.

Change-Id: Iceba233b4eebd57c40cf5dcd4af9031d210dc9d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/399157
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/go/alldocs.go
src/cmd/go/internal/generate/generate.go
src/cmd/go/testdata/script/build_trimpath_goroot.txt