x/tools/go/packages: Config.Env always uses current environment, not as documented only when it's nil #42590
Labels
Documentation
Issues describing a change to documentation.
FrozenDueToAge
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
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?
I'm using
packages.Load
(golang.org/x/tools/go/packages) to collect source files of go packages.My program is calling
packagesLoad()
withConfig.Env
set to[]string{"GO111MODULE=on", "GOFLAGS=-mod=readonly"}
.I ran the program in an environment where the environment variable
GOPATH
was set to/go
.What did you expect to see?
I expected that
packages.Load()
runsgo list
without theGOPATH
variable of my current environment, instead that eitherGOPATH
is unset or the default value is used.I expected this because the documentation of
Config.Env
states:https://github.com/golang/tools/blob/eeaa07dd769687291ac8e71ec39a7db382b22b65/go/packages/packages.go#L130
What did you see instead?
The setting of my current environment were used for the
go list
execution.go list
is run viaInvocation.run()
which uses the current environment and appends additional environment variables to the slice:https://github.com/golang/tools/blob/eeaa07dd769687291ac8e71ec39a7db382b22b65/internal/gocommand/invoke.go#L210
That
Invocation.run()
always uses the current environment was introduced in commit:golang/tools@f8bfb4e#diff-55f055b305279edb4e62ce29481a985df8d488314120de25803e0336efdea6e1
I would prefer if instead of correcting the documentation,
packages.Load()
would work as it is currently documented.It makes it easy to run the function in a controlled environment.
The text was updated successfully, but these errors were encountered: