cmd/go: enable module index by default

This changes the module index to be enabled by default, rather than
disabled by default. The index can still be disabled by setting
GODEBUG=index=0.

Fixes #53290.

Change-Id: Ic3728fc69d96bb6ef56b56e8c9f2dce35f2923cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/410821
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Michael Matloob 2022-06-07 13:53:40 -04:00 committed by Russ Cox
parent f862280e30
commit 899f0a29c7
2 changed files with 10 additions and 4 deletions

View file

@ -22,7 +22,6 @@ import (
"runtime"
"runtime/debug"
"sort"
"strconv"
"strings"
"sync"
"unsafe"
@ -40,7 +39,15 @@ import (
// It will be removed before the release.
// TODO(matloob): Remove enabled once we have more confidence on the
// module index.
var enabled, _ = strconv.ParseBool(os.Getenv("GOINDEX"))
var enabled = func() bool {
debug := strings.Split(os.Getenv("GODEBUG"), ",")
for _, f := range debug {
if f == "goindex=0" {
return false
}
}
return true
}()
// ModuleIndex represents and encoded module index file. It is used to
// do the equivalent of build.Import of packages in the module and answer other
@ -125,7 +132,7 @@ func openIndex(modroot string, ismodcache bool) (*ModuleIndex, error) {
data, _, err := cache.Default().GetMmap(id)
if err != nil {
// Couldn't read from modindex. Assume we couldn't read from
// the index because the module has't been indexed yet.
// the index because the module hasn't been indexed yet.
data, err = indexModule(modroot)
if err != nil {
return result{nil, err}

View file

@ -170,7 +170,6 @@ func (ts *testScript) setup() {
"GOCACHE=" + testGOCACHE,
"GODEBUG=" + os.Getenv("GODEBUG"),
"GOEXE=" + cfg.ExeSuffix,
"GOINDEX=true",
"GOOS=" + runtime.GOOS,
"GOPATH=" + filepath.Join(ts.workdir, "gopath"),
"GOPROXY=" + proxyURL,