diff --git a/doc/godebug.md b/doc/godebug.md index d760e0f4ef9..43dbcd645a6 100644 --- a/doc/godebug.md +++ b/doc/godebug.md @@ -182,6 +182,12 @@ Go 1.18 removed support for SHA1 in most X.509 certificates, controlled by the [`x509sha1` setting](/crypto/x509#InsecureAlgorithmError). This setting will be removed in a future release, Go 1.22 at the earliest. +### Go 1.10 + +Go 1.10 changed how build caching worked and added test caching, along +with the [`gocacheverify`, `gocachehash`, and `gocachetest` settings](/cmd/go/#hdr-Build_and_test_caching). +There is no plan to remove these settings. + ### Go 1.6 Go 1.6 introduced transparent support for HTTP/2, diff --git a/src/cmd/go/internal/cache/cache.go b/src/cmd/go/internal/cache/cache.go index baa516c4688..378ae5db003 100644 --- a/src/cmd/go/internal/cache/cache.go +++ b/src/cmd/go/internal/cache/cache.go @@ -11,6 +11,7 @@ import ( "encoding/hex" "errors" "fmt" + "internal/godebug" "io" "io/fs" "os" @@ -115,20 +116,24 @@ var DebugTest = false func init() { initEnv() } +var ( + goCacheVerify = godebug.New("gocacheverify") + goDebugHash = godebug.New("gocachehash") + goCacheTest = godebug.New("gocachetest") +) + func initEnv() { - verify = false - debugHash = false - debug := strings.Split(os.Getenv("GODEBUG"), ",") - for _, f := range debug { - if f == "gocacheverify=1" { - verify = true - } - if f == "gocachehash=1" { - debugHash = true - } - if f == "gocachetest=1" { - DebugTest = true - } + if goCacheVerify.Value() == "1" { + goCacheVerify.IncNonDefault() + verify = true + } + if goDebugHash.Value() == "1" { + goDebugHash.IncNonDefault() + debugHash = true + } + if goCacheTest.Value() == "1" { + goCacheTest.IncNonDefault() + DebugTest = true } } diff --git a/src/internal/godebugs/table.go b/src/internal/godebugs/table.go index 6a78d74f8bc..0fdd146b24d 100644 --- a/src/internal/godebugs/table.go +++ b/src/internal/godebugs/table.go @@ -26,6 +26,9 @@ type Info struct { // (Otherwise the test in this package will fail.) var All = []Info{ {Name: "execerrdot", Package: "os/exec"}, + {Name: "gocachehash", Package: "cmd/go"}, + {Name: "gocachetest", Package: "cmd/go"}, + {Name: "gocacheverify", Package: "cmd/go"}, {Name: "http2client", Package: "net/http"}, {Name: "http2debug", Package: "net/http", Opaque: true}, {Name: "http2server", Package: "net/http"}, diff --git a/src/runtime/metrics/doc.go b/src/runtime/metrics/doc.go index db6ea686e8f..5238bcea8ea 100644 --- a/src/runtime/metrics/doc.go +++ b/src/runtime/metrics/doc.go @@ -234,6 +234,18 @@ Below is the full list of supported metrics, ordered lexicographically. The number of non-default behaviors executed by the os/exec package due to a non-default GODEBUG=execerrdot=... setting. + /godebug/non-default-behavior/gocachehash:events + The number of non-default behaviors executed by the cmd/go + package due to a non-default GODEBUG=gocachehash=... setting. + + /godebug/non-default-behavior/gocachetest:events + The number of non-default behaviors executed by the cmd/go + package due to a non-default GODEBUG=gocachetest=... setting. + + /godebug/non-default-behavior/gocacheverify:events + The number of non-default behaviors executed by the cmd/go + package due to a non-default GODEBUG=gocacheverify=... setting. + /godebug/non-default-behavior/http2client:events The number of non-default behaviors executed by the net/http package due to a non-default GODEBUG=http2client=... setting.