Skip to content

Commit 8b2a2d0

Browse files
author
Bryan C. Mills
committed
Revert "cmd/go: change the default value of GO111MODULE to 'on'"
This reverts commit cf46916 (CL 162698). Reason for revert: broke make.bash bootstrapping from head. Change-Id: I3de6d26b1af9038c6b92dec88667bfa734060a41 Reviewed-on: https://go-review.googlesource.com/c/go/+/166985 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 2bd28ce commit 8b2a2d0

File tree

9 files changed

+232
-210
lines changed

9 files changed

+232
-210
lines changed

src/cmd/go/alldocs.go

Lines changed: 170 additions & 161 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/help_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ import (
1212
"testing"
1313

1414
"cmd/go/internal/help"
15-
"cmd/go/internal/modload"
1615
)
1716

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

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"unicode/utf8"
1818

1919
"cmd/go/internal/base"
20-
"cmd/go/internal/modload"
2120
)
2221

2322
// Help implements the 'help' command.
@@ -36,10 +35,8 @@ func Help(w io.Writer, args []string) {
3635
usage := &base.Command{Long: buf.String()}
3736
cmds := []*base.Command{usage}
3837
for _, cmd := range base.Go.Commands {
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() {
38+
if cmd.UsageLine == "gopath-get" {
39+
// Avoid duplication of the "get" documentation.
4340
continue
4441
}
4542
cmds = append(cmds, cmd)

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,34 @@ 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-
Module support
22+
Preliminary module support
2323
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.
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.
2730
28-
For more fine-grained control, Go 1.13 continues to respect
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
2937
a temporary environment variable, GO111MODULE, which can be set to one
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
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
4041
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.
4150
4251
In module-aware mode, GOPATH no longer defines the meaning of imports
4352
during a build, but it still stores downloaded dependencies (in GOPATH/pkg/mod)

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

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

4040
modRoot string
@@ -70,6 +70,16 @@ func BinDir() string {
7070
return filepath.Join(gopath, "bin")
7171
}
7272

73+
// mustUseModules reports whether we are invoked as vgo
74+
// (as opposed to go).
75+
// If so, we only support builds with go.mod files.
76+
func mustUseModules() bool {
77+
name := os.Args[0]
78+
name = name[strings.LastIndex(name, "/")+1:]
79+
name = name[strings.LastIndex(name, `\`)+1:]
80+
return strings.HasPrefix(name, "vgo")
81+
}
82+
7383
var inGOPATH bool // running in GOPATH/src
7484

7585
// Init determines whether module mode is enabled, locates the root of the
@@ -86,13 +96,14 @@ func Init() {
8696
switch env {
8797
default:
8898
base.Fatalf("go: unknown environment setting GO111MODULE=%s", env)
89-
case "auto":
90-
mustUseModules = false
91-
case "on", "":
92-
mustUseModules = true
99+
case "", "auto":
100+
// leave MustUseModules alone
101+
case "on":
102+
MustUseModules = true
93103
case "off":
94-
mustUseModules = false
95-
return
104+
if !MustUseModules {
105+
return
106+
}
96107
}
97108

98109
// Disable any prompting for passwords by Git.
@@ -139,7 +150,7 @@ func Init() {
139150
}
140151
}
141152

142-
if inGOPATH && !mustUseModules {
153+
if inGOPATH && !MustUseModules {
143154
if CmdModInit {
144155
die() // Don't init a module that we're just going to ignore.
145156
}
@@ -156,8 +167,8 @@ func Init() {
156167
} else {
157168
modRoot = findModuleRoot(cwd)
158169
if modRoot == "" {
159-
if !mustUseModules {
160-
// GO111MODULE is 'auto', and we can't find a module root.
170+
if !MustUseModules {
171+
// GO111MODULE is 'auto' (or unset), and we can't find a module root.
161172
// Stay in GOPATH mode.
162173
return
163174
}
@@ -256,7 +267,7 @@ func init() {
256267
// (usually through MustModRoot).
257268
func Enabled() bool {
258269
Init()
259-
return modRoot != "" || mustUseModules
270+
return modRoot != "" || MustUseModules
260271
}
261272

262273
// ModRoot returns the root of the main module.
@@ -289,7 +300,7 @@ func die() {
289300
if os.Getenv("GO111MODULE") == "off" {
290301
base.Fatalf("go: modules disabled by GO111MODULE=off; see 'go help modules'")
291302
}
292-
if inGOPATH && !mustUseModules {
303+
if inGOPATH && !MustUseModules {
293304
base.Fatalf("go: modules disabled inside GOPATH/src by GO111MODULE=auto; see 'go help modules'")
294305
}
295306
if cwd != "" {

src/cmd/go/main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func init() {
4949
fix.CmdFix,
5050
fmtcmd.CmdFmt,
5151
generate.CmdGenerate,
52-
modget.CmdGet,
52+
get.CmdGet,
5353
work.CmdInstall,
5454
list.CmdList,
5555
modcmd.CmdMod,
@@ -89,10 +89,17 @@ 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+
9297
if args[0] == "get" || args[0] == "help" {
93-
if modload.Init(); !modload.Enabled() {
94-
// Replace module-aware get with GOPATH get if appropriate.
95-
*modget.CmdGet = *get.CmdGet
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
96103
}
97104
}
98105

src/cmd/go/mkalldocs.sh

Lines changed: 1 addition & 1 deletion
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-
GO111MODULE='' ./go.latest help documentation >alldocs.go
11+
./go.latest help documentation >alldocs.go
1212
gofmt -w alldocs.go
1313
rm go.latest

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

Lines changed: 1 addition & 1 deletion
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=
20+
env GO111MODULE=on
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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,12 @@ 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
3027
env GO111MODULE=on
3128
exec $WORK/testimport.exe other/x/y/z/w .
3229
stdout w2.go
3330

3431
# GO111MODULE=on in GOPATH/src
3532
cd $GOPATH/src
36-
env GO111MODULE=
37-
exec $WORK/testimport.exe x/y/z/w .
38-
stdout w1.go
3933
env GO111MODULE=on
4034
exec $WORK/testimport.exe x/y/z/w .
4135
stdout w1.go

0 commit comments

Comments
 (0)