From 621d4eef75da74cfd9dec5b23796c4c65d3ab01f Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Mon, 16 Dec 2019 18:04:38 -0500 Subject: [PATCH] imports: pass more of the environment goimports now wants various module flags, but I forgot to set them up in the many places we create environments. Do so. Change-Id: Ic3817caeb8fc4d564b49006ef6ca6842b2498eaf Reviewed-on: https://go-review.googlesource.com/c/tools/+/211581 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- cmd/goimports/goimports.go | 8 ++++++-- imports/forward.go | 5 +++++ internal/imports/imports.go | 9 +++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/goimports/goimports.go b/cmd/goimports/goimports.go index a476a7f3c3..2cca292359 100644 --- a/cmd/goimports/goimports.go +++ b/cmd/goimports/goimports.go @@ -45,8 +45,12 @@ var ( Fragment: true, // This environment, and its caches, will be reused for the whole run. Env: &imports.ProcessEnv{ - GOPATH: build.Default.GOPATH, - GOROOT: build.Default.GOROOT, + GOPATH: build.Default.GOPATH, + GOROOT: build.Default.GOROOT, + GOFLAGS: os.Getenv("GOFLAGS"), + GO111MODULE: os.Getenv("GO111MODULE"), + GOPROXY: os.Getenv("GOPROXY"), + GOSUMDB: os.Getenv("GOSUMDB"), }, } exitCode = 0 diff --git a/imports/forward.go b/imports/forward.go index eef25969de..b4f4287679 100644 --- a/imports/forward.go +++ b/imports/forward.go @@ -4,6 +4,7 @@ package imports // import "golang.org/x/tools/imports" import ( "go/build" + "os" intimp "golang.org/x/tools/internal/imports" ) @@ -42,6 +43,10 @@ func Process(filename string, src []byte, opt *Options) ([]byte, error) { Env: &intimp.ProcessEnv{ GOPATH: build.Default.GOPATH, GOROOT: build.Default.GOROOT, + GOFLAGS: os.Getenv("GOFLAGS"), + GO111MODULE: os.Getenv("GO111MODULE"), + GOPROXY: os.Getenv("GOPROXY"), + GOSUMDB: os.Getenv("GOSUMDB"), Debug: Debug, LocalPrefix: LocalPrefix, }, diff --git a/internal/imports/imports.go b/internal/imports/imports.go index e066d909e4..b5c9754953 100644 --- a/internal/imports/imports.go +++ b/internal/imports/imports.go @@ -21,6 +21,7 @@ import ( "io" "io/ioutil" "log" + "os" "regexp" "strconv" "strings" @@ -145,8 +146,12 @@ func initialize(filename string, src []byte, opt *Options) ([]byte, *Options, er // Set the env if the user has not provided it. if opt.Env == nil { opt.Env = &ProcessEnv{ - GOPATH: build.Default.GOPATH, - GOROOT: build.Default.GOROOT, + GOPATH: build.Default.GOPATH, + GOROOT: build.Default.GOROOT, + GOFLAGS: os.Getenv("GOFLAGS"), + GO111MODULE: os.Getenv("GO111MODULE"), + GOPROXY: os.Getenv("GOPROXY"), + GOSUMDB: os.Getenv("GOSUMDB"), } }