Skip to content

Commit 621d4ee

Browse files
committed
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 <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
1 parent 846828e commit 621d4ee

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

cmd/goimports/goimports.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ var (
4545
Fragment: true,
4646
// This environment, and its caches, will be reused for the whole run.
4747
Env: &imports.ProcessEnv{
48-
GOPATH: build.Default.GOPATH,
49-
GOROOT: build.Default.GOROOT,
48+
GOPATH: build.Default.GOPATH,
49+
GOROOT: build.Default.GOROOT,
50+
GOFLAGS: os.Getenv("GOFLAGS"),
51+
GO111MODULE: os.Getenv("GO111MODULE"),
52+
GOPROXY: os.Getenv("GOPROXY"),
53+
GOSUMDB: os.Getenv("GOSUMDB"),
5054
},
5155
}
5256
exitCode = 0

imports/forward.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package imports // import "golang.org/x/tools/imports"
44

55
import (
66
"go/build"
7+
"os"
78

89
intimp "golang.org/x/tools/internal/imports"
910
)
@@ -42,6 +43,10 @@ func Process(filename string, src []byte, opt *Options) ([]byte, error) {
4243
Env: &intimp.ProcessEnv{
4344
GOPATH: build.Default.GOPATH,
4445
GOROOT: build.Default.GOROOT,
46+
GOFLAGS: os.Getenv("GOFLAGS"),
47+
GO111MODULE: os.Getenv("GO111MODULE"),
48+
GOPROXY: os.Getenv("GOPROXY"),
49+
GOSUMDB: os.Getenv("GOSUMDB"),
4550
Debug: Debug,
4651
LocalPrefix: LocalPrefix,
4752
},

internal/imports/imports.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io"
2222
"io/ioutil"
2323
"log"
24+
"os"
2425
"regexp"
2526
"strconv"
2627
"strings"
@@ -145,8 +146,12 @@ func initialize(filename string, src []byte, opt *Options) ([]byte, *Options, er
145146
// Set the env if the user has not provided it.
146147
if opt.Env == nil {
147148
opt.Env = &ProcessEnv{
148-
GOPATH: build.Default.GOPATH,
149-
GOROOT: build.Default.GOROOT,
149+
GOPATH: build.Default.GOPATH,
150+
GOROOT: build.Default.GOROOT,
151+
GOFLAGS: os.Getenv("GOFLAGS"),
152+
GO111MODULE: os.Getenv("GO111MODULE"),
153+
GOPROXY: os.Getenv("GOPROXY"),
154+
GOSUMDB: os.Getenv("GOSUMDB"),
150155
}
151156
}
152157

0 commit comments

Comments
 (0)