diff options
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/go/alldocs.go | 10 | ||||
| -rw-r--r-- | src/cmd/go/internal/help/helpdoc.go | 10 | ||||
| -rw-r--r-- | src/cmd/go/internal/load/godebug.go | 31 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/godebug_default_gopath.txt | 9 |
4 files changed, 39 insertions, 21 deletions
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 52aa6c7fb4..4be78b33bb 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -2878,11 +2878,11 @@ // GOPATH mode import path checking (see 'go help importpath'). // // In GOPATH mode, the default GODEBUG values built into a binary -// will be those used in Go 1.20, setting the same GODEBUG values -// as when a module specifies "godebug default=go1.20". To use -// different GODEBUG settings, the GODEBUG environment variable must -// be set to override those values. This also means that the standard -// library tests will not run properly with GO111MODULE=off. +// will be the same GODEBUG values as when a module specifies +// "godebug default=go1.20". To use different GODEBUG settings, the +// GODEBUG environment variable must be set to override those values. +// This also means that the standard library tests will not run +// properly with GO111MODULE=off. // // See https://go.dev/s/go15vendor for details. // diff --git a/src/cmd/go/internal/help/helpdoc.go b/src/cmd/go/internal/help/helpdoc.go index 5f77b88536..4b1444ee3b 100644 --- a/src/cmd/go/internal/help/helpdoc.go +++ b/src/cmd/go/internal/help/helpdoc.go @@ -525,11 +525,11 @@ Code in GOPATH mode vendor directories is not subject to GOPATH mode import path checking (see 'go help importpath'). In GOPATH mode, the default GODEBUG values built into a binary -will be those used in Go 1.20, setting the same GODEBUG values -as when a module specifies "godebug default=go1.20". To use -different GODEBUG settings, the GODEBUG environment variable must -be set to override those values. This also means that the standard -library tests will not run properly with GO111MODULE=off. +will be the same GODEBUG values as when a module specifies +"godebug default=go1.20". To use different GODEBUG settings, the +GODEBUG environment variable must be set to override those values. +This also means that the standard library tests will not run +properly with GO111MODULE=off. See https://go.dev/s/go15vendor for details. diff --git a/src/cmd/go/internal/load/godebug.go b/src/cmd/go/internal/load/godebug.go index 7bb873fa7d..a6bcdad627 100644 --- a/src/cmd/go/internal/load/godebug.go +++ b/src/cmd/go/internal/load/godebug.go @@ -42,6 +42,24 @@ func ParseGoDebug(text string) (key, value string, err error) { return k, v, nil } +func defaultGODEBUGGoVersion(loaderstate *modload.State, p *Package) string { + if !loaderstate.Enabled() { + // GOPATH mode. Use Go 1.20. + return "1.20" + } + if loaderstate.RootMode == modload.NoRoot && p.Module != nil { + // This is go install pkg@version or go run pkg@version. + // Use the Go version from the package. + // If there isn't one, then assume Go 1.20, the last + // version before GODEBUGs were introduced (#56986). + if goVersion := p.Module.GoVersion; goVersion != "" { + return goVersion + } + return "1.20" + } + return loaderstate.MainModules.GoVersion(loaderstate) +} + // defaultGODEBUG returns the default GODEBUG setting for the main package p. // When building a test binary, directives, testDirectives, and xtestDirectives // list additional directives from the package under test. @@ -49,17 +67,8 @@ func defaultGODEBUG(loaderstate *modload.State, p *Package, directives, testDire if p.Name != "main" { return "" } - goVersion := loaderstate.MainModules.GoVersion(loaderstate) - if loaderstate.RootMode == modload.NoRoot && p.Module != nil { - // This is go install pkg@version or go run pkg@version. - // Use the Go version from the package. - // If there isn't one, then assume Go 1.20, - // the last version before GODEBUGs were introduced. - goVersion = p.Module.GoVersion - if goVersion == "" { - goVersion = "1.20" - } - } + + goVersion := defaultGODEBUGGoVersion(loaderstate, p) var m map[string]string diff --git a/src/cmd/go/testdata/script/godebug_default_gopath.txt b/src/cmd/go/testdata/script/godebug_default_gopath.txt new file mode 100644 index 0000000000..2bdf8369ae --- /dev/null +++ b/src/cmd/go/testdata/script/godebug_default_gopath.txt @@ -0,0 +1,9 @@ +env GO111MODULE=off + +go list -f '{{.DefaultGODEBUG}}' +! stdout netedns0 + +-- foo.go -- +package main + +func main() {}
\ No newline at end of file |
