Skip to content

Commit eca5c83

Browse files
author
Bryan C. Mills
committed
cmd/go: change the default value of GO111MODULE to 'on'
This reverts CL 166985, restoring CL 162698. The bootstrap failure from CL 162698 was fixed in CL 167077 and CL 167078. Fixes #30228 Change-Id: I5a4e3081018c51b74b67185e64f20a9c824a564e Reviewed-on: https://go-review.googlesource.com/c/go/+/167087 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 259de39 commit eca5c83

File tree

9 files changed

+210
-232
lines changed

9 files changed

+210
-232
lines changed

src/cmd/go/alldocs.go

+161-170
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/help_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ import (
1212
"testing"
1313

1414
"cmd/go/internal/help"
15+
"cmd/go/internal/modload"
1516
)
1617

1718
func TestDocsUpToDate(t *testing.T) {
19+
if !modload.Enabled() {
20+
t.Skipf("help.Help in GOPATH mode is configured by main.main")
21+
}
22+
1823
buf := new(bytes.Buffer)
1924
// Match the command in mkalldocs.sh that generates alldocs.go.
2025
help.Help(buf, []string{"documentation"})

src/cmd/go/internal/help/help.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"unicode/utf8"
1818

1919
"cmd/go/internal/base"
20+
"cmd/go/internal/modload"
2021
)
2122

2223
// Help implements the 'help' command.
@@ -35,8 +36,10 @@ func Help(w io.Writer, args []string) {
3536
usage := &base.Command{Long: buf.String()}
3637
cmds := []*base.Command{usage}
3738
for _, cmd := range base.Go.Commands {
38-
if cmd.UsageLine == "gopath-get" {
39-
// Avoid duplication of the "get" documentation.
39+
// Avoid duplication of the "get" documentation.
40+
if cmd.UsageLine == "module-get" && modload.Enabled() {
41+
continue
42+
} else if cmd.UsageLine == "gopath-get" && !modload.Enabled() {
4043
continue
4144
}
4245
cmds = append(cmds, cmd)

src/cmd/go/internal/modload/help.go

+15-24
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,25 @@ including recording and resolving dependencies on other modules.
1919
Modules replace the old GOPATH-based approach to specifying
2020
which source files are used in a given build.
2121
22-
Preliminary module support
22+
Module support
2323
24-
Go 1.11 includes preliminary support for Go modules,
25-
including a new module-aware 'go get' command.
26-
We intend to keep revising this support, while preserving compatibility,
27-
until it can be declared official (no longer preliminary),
28-
and then at a later point we may remove support for work
29-
in GOPATH and the old 'go get' command.
24+
Go 1.13 includes official support for Go modules,
25+
including a module-aware 'go get' command.
26+
Module-aware mode is active by default.
3027
31-
The quickest way to take advantage of the new Go 1.11 module support
32-
is to check out your repository into a directory outside GOPATH/src,
33-
create a go.mod file (described in the next section) there, and run
34-
go commands from within that file tree.
35-
36-
For more fine-grained control, the module support in Go 1.11 respects
28+
For more fine-grained control, Go 1.13 continues to respect
3729
a temporary environment variable, GO111MODULE, which can be set to one
38-
of three string values: off, on, or auto (the default).
39-
If GO111MODULE=off, then the go command never uses the
40-
new module support. Instead it looks in vendor directories and GOPATH
30+
of three string values: off, auto, or on (the default).
31+
If GO111MODULE=on or is unset, then the go command requires the use of
32+
modules, never consulting GOPATH. We refer to this as the command
33+
being module-aware or running in "module-aware mode".
34+
If GO111MODULE=auto, then the go command enables or disables module
35+
support based on the current directory. Module support is enabled only
36+
when the current directory is outside GOPATH/src and itself contains a
37+
go.mod file or is below a directory containing a go.mod file.
38+
If GO111MODULE=off, then the go command never uses
39+
module support. Instead it looks in vendor directories and GOPATH
4140
to find dependencies; we now refer to this as "GOPATH mode."
42-
If GO111MODULE=on, then the go command requires the use of modules,
43-
never consulting GOPATH. We refer to this as the command being
44-
module-aware or running in "module-aware mode".
45-
If GO111MODULE=auto or is unset, then the go command enables or
46-
disables module support based on the current directory.
47-
Module support is enabled only when the current directory is outside
48-
GOPATH/src and itself contains a go.mod file or is below a directory
49-
containing a go.mod file.
5041
5142
In module-aware mode, GOPATH no longer defines the meaning of imports
5243
during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)

src/cmd/go/internal/modload/init.go

+12-23
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
var (
3535
cwd string // TODO(bcmills): Is this redundant with base.Cwd?
36-
MustUseModules = mustUseModules()
36+
mustUseModules = true
3737
initialized bool
3838

3939
modRoot string
@@ -78,16 +78,6 @@ func BinDir() string {
7878
return filepath.Join(gopath, "bin")
7979
}
8080

81-
// mustUseModules reports whether we are invoked as vgo
82-
// (as opposed to go).
83-
// If so, we only support builds with go.mod files.
84-
func mustUseModules() bool {
85-
name := os.Args[0]
86-
name = name[strings.LastIndex(name, "/")+1:]
87-
name = name[strings.LastIndex(name, `\`)+1:]
88-
return strings.HasPrefix(name, "vgo")
89-
}
90-
9181
var inGOPATH bool // running in GOPATH/src
9282

9383
// Init determines whether module mode is enabled, locates the root of the
@@ -104,14 +94,13 @@ func Init() {
10494
switch env {
10595
default:
10696
base.Fatalf("go: unknown environment setting GO111MODULE=%s", env)
107-
case "", "auto":
108-
// leave MustUseModules alone
109-
case "on":
110-
MustUseModules = true
97+
case "auto":
98+
mustUseModules = false
99+
case "on", "":
100+
mustUseModules = true
111101
case "off":
112-
if !MustUseModules {
113-
return
114-
}
102+
mustUseModules = false
103+
return
115104
}
116105

117106
// Disable any prompting for passwords by Git.
@@ -158,7 +147,7 @@ func Init() {
158147
}
159148
}
160149

161-
if inGOPATH && !MustUseModules {
150+
if inGOPATH && !mustUseModules {
162151
if CmdModInit {
163152
die() // Don't init a module that we're just going to ignore.
164153
}
@@ -175,8 +164,8 @@ func Init() {
175164
} else {
176165
modRoot = findModuleRoot(cwd)
177166
if modRoot == "" {
178-
if !MustUseModules {
179-
// GO111MODULE is 'auto' (or unset), and we can't find a module root.
167+
if !mustUseModules {
168+
// GO111MODULE is 'auto', and we can't find a module root.
180169
// Stay in GOPATH mode.
181170
return
182171
}
@@ -275,7 +264,7 @@ func init() {
275264
// (usually through MustModRoot).
276265
func Enabled() bool {
277266
Init()
278-
return modRoot != "" || MustUseModules
267+
return modRoot != "" || mustUseModules
279268
}
280269

281270
// ModRoot returns the root of the main module.
@@ -308,7 +297,7 @@ func die() {
308297
if os.Getenv("GO111MODULE") == "off" {
309298
base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'")
310299
}
311-
if inGOPATH && !MustUseModules {
300+
if inGOPATH && !mustUseModules {
312301
base.Fatalf("go: modules disabled inside GOPATH/src by GO111MODULE=auto; see 'go help modules'")
313302
}
314303
if cwd != "" {

src/cmd/go/main.go

+4-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func init() {
4949
fix.CmdFix,
5050
fmtcmd.CmdFmt,
5151
generate.CmdGenerate,
52-
get.CmdGet,
52+
modget.CmdGet,
5353
work.CmdInstall,
5454
list.CmdList,
5555
modcmd.CmdMod,
@@ -89,17 +89,10 @@ func main() {
8989
base.Usage()
9090
}
9191

92-
if modload.MustUseModules {
93-
// If running with modules force-enabled, change get now to change help message.
94-
*get.CmdGet = *modget.CmdGet
95-
}
96-
9792
if args[0] == "get" || args[0] == "help" {
98-
// Replace get with module-aware get if appropriate.
99-
// Note that if MustUseModules is true, this happened already above,
100-
// but no harm in doing it again.
101-
if modload.Init(); modload.Enabled() {
102-
*get.CmdGet = *modget.CmdGet
93+
if modload.Init(); !modload.Enabled() {
94+
// Replace module-aware get with GOPATH get if appropriate.
95+
*modget.CmdGet = *get.CmdGet
10396
}
10497
}
10598

src/cmd/go/mkalldocs.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ set -e
88
go build -o go.latest
99
# If the command used to generate alldocs.go changes, update TestDocsUpToDate in
1010
# help_test.go.
11-
./go.latest help documentation >alldocs.go
11+
GO111MODULE='' ./go.latest help documentation >alldocs.go
1212
gofmt -w alldocs.go
1313
rm go.latest

src/cmd/go/testdata/script/mod_find.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cd $GOPATH/src/example.com/x/y
1717
! go mod init
1818
stderr 'go: modules disabled inside GOPATH/src by GO111MODULE=auto; see ''go help modules'''
1919

20-
env GO111MODULE=on
20+
env GO111MODULE=
2121

2222
# Derive module path from location inside GOPATH.
2323
cd $GOPATH/src/example.com/x/y

src/cmd/go/testdata/script/mod_gobuild_import.txt

+6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ exec $WORK/testimport.exe other/x/y/z/w .
2424
stdout w2.go
2525

2626
# GO111MODULE=on outside GOPATH/src
27+
env GO111MODULE=
28+
exec $WORK/testimport.exe other/x/y/z/w .
29+
stdout w2.go
2730
env GO111MODULE=on
2831
exec $WORK/testimport.exe other/x/y/z/w .
2932
stdout w2.go
3033

3134
# GO111MODULE=on in GOPATH/src
3235
cd $GOPATH/src
36+
env GO111MODULE=
37+
exec $WORK/testimport.exe x/y/z/w .
38+
stdout w1.go
3339
env GO111MODULE=on
3440
exec $WORK/testimport.exe x/y/z/w .
3541
stdout w1.go

0 commit comments

Comments
 (0)