cmd/go: default to GO111MODULE=on

Fixes #41330

Change-Id: Ib66087ac5e1eb827694915f21c32c4d88e1b9a7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/255052
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
Jay Conrod 2020-09-15 12:59:05 -04:00
parent 331614c4da
commit b4ea672009
3 changed files with 8 additions and 8 deletions

View File

@ -120,9 +120,9 @@ func Init() {
switch env {
default:
base.Fatalf("go: unknown environment setting GO111MODULE=%s", env)
case "auto", "":
case "auto":
mustUseModules = ForceUseModules
case "on":
case "on", "":
mustUseModules = true
case "off":
if ForceUseModules {
@ -257,9 +257,9 @@ func WillBeEnabled() bool {
// exits, so it can't call this function directly.
env := cfg.Getenv("GO111MODULE")
switch env {
case "on":
case "on", "":
return true
case "auto", "":
case "auto":
break
default:
return false

View File

@ -25,7 +25,7 @@ cd $GOPATH/foo/bar/baz
go env GOMOD
stdout foo[/\\]go.mod
# GO111MODULE unset should be equivalent to auto.
# GO111MODULE unset should be equivalent to on.
env GO111MODULE=
cd $GOPATH/src/x/y/z
@ -34,7 +34,7 @@ stdout $GOPATH[/\\]src[/\\]x[/\\]y[/\\]z[/\\]go.mod
cd $GOPATH/src/x/y
go env GOMOD
! stdout .
stdout 'NUL|/dev/null'
# GO111MODULE=on should trigger everywhere
env GO111MODULE=on

View File

@ -1072,9 +1072,9 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode)
}
}
// Unless GO111MODULE=on, look to see if there is a go.mod.
// If GO111MODULE=auto, look to see if there is a go.mod.
// Since go1.13, it doesn't matter if we're inside GOPATH.
if go111Module != "on" {
if go111Module == "auto" {
var (
parent string
err error