From 899f0a29c7be2bba3f8f0bc2987f7c2d70a6c4ec Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Tue, 7 Jun 2022 13:53:40 -0400 Subject: [PATCH] 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 Reviewed-by: Russ Cox Reviewed-by: Michael Matloob Reviewed-by: Dmitri Shuralyov --- src/cmd/go/internal/modindex/read.go | 13 ++++++++++--- src/cmd/go/script_test.go | 1 - 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cmd/go/internal/modindex/read.go b/src/cmd/go/internal/modindex/read.go index 0ed480fbd0..daa85762be 100644 --- a/src/cmd/go/internal/modindex/read.go +++ b/src/cmd/go/internal/modindex/read.go @@ -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} diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index d1fe36ec21..04bc8d581a 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -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, -- 2.48.1