go/packages: don't use os.LookupEnv
Get the value of GOARCH from the config instead. It should have been set to the same as the one from the environment by default, but may have been overidden by the caller. Change-Id: If9a6c0ae998c1c72ad2a68fe83c8bb9f5614a189 Reviewed-on: https://go-review.googlesource.com/c/142361 Run-TryBot: Ian Cottrell <iancottrell@google.com> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
5d4988d199
commit
3bba456143
|
@ -20,6 +20,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/tools/go/gcexportdata"
|
"golang.org/x/tools/go/gcexportdata"
|
||||||
|
@ -685,8 +686,11 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
|
||||||
// This is only an approximation.
|
// This is only an approximation.
|
||||||
// TODO(adonovan): derive Sizes from the underlying build system.
|
// TODO(adonovan): derive Sizes from the underlying build system.
|
||||||
goarch := runtime.GOARCH
|
goarch := runtime.GOARCH
|
||||||
if x, ok := os.LookupEnv("GOARCH"); ok {
|
const goarchPrefix = "GOARCH="
|
||||||
goarch = x
|
for _, e := range ld.Config.Env {
|
||||||
|
if strings.HasPrefix(e, goarchPrefix) {
|
||||||
|
goarch = e[len(goarchPrefix):]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sizes := types.SizesFor("gc", goarch)
|
sizes := types.SizesFor("gc", goarch)
|
||||||
|
|
||||||
|
|
|
@ -1052,15 +1052,11 @@ func TestSizes(t *testing.T) {
|
||||||
})
|
})
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
savedGOARCH := os.Getenv("GOARCH")
|
|
||||||
defer os.Setenv("GOARCH", savedGOARCH)
|
|
||||||
|
|
||||||
for arch, wantWordSize := range map[string]int64{"386": 32, "amd64": 64} {
|
for arch, wantWordSize := range map[string]int64{"386": 32, "amd64": 64} {
|
||||||
os.Setenv("GOARCH", arch)
|
|
||||||
cfg := &packages.Config{
|
cfg := &packages.Config{
|
||||||
Mode: packages.LoadSyntax,
|
Mode: packages.LoadSyntax,
|
||||||
Dir: tmp,
|
Dir: tmp,
|
||||||
Env: append(os.Environ(), "GOPATH="+tmp, "GO111MODULE=off"),
|
Env: append(os.Environ(), "GOARCH="+arch, "GOPATH="+tmp, "GO111MODULE=off"),
|
||||||
}
|
}
|
||||||
initial, err := packages.Load(cfg, "a")
|
initial, err := packages.Load(cfg, "a")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue