]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go/internal/cache: use internal/godebug for three GODEBUGs
authorBrad Fitzpatrick <bradfitz@golang.org>
Sat, 22 Apr 2023 02:55:43 +0000 (19:55 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 24 May 2023 22:05:27 +0000 (22:05 +0000)
And register/document them.

Change-Id: If0f1cf3c09230e0f63d03c52e56e51a030468ab2
Reviewed-on: https://go-review.googlesource.com/c/go/+/487655
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>

doc/godebug.md
src/cmd/go/internal/cache/cache.go
src/internal/godebugs/table.go
src/runtime/metrics/doc.go

index d760e0f4ef93b378681221c13ae647edd4ea2c5b..43dbcd645a6b66e7cd40e111019da52419a29360 100644 (file)
@@ -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,
index baa516c46883b57a1085ef3b0d3ad08cce74e582..378ae5db003c8fbe5c0ba188d370e06618b30d7b 100644 (file)
@@ -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
        }
 }
 
index 6a78d74f8bcf06dbf8b698e6037a83130529ef2c..0fdd146b24dbd931c0e3555e8fe606c0a351cc19 100644 (file)
@@ -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"},
index db6ea686e8fadd21e839b24588352ef1394a6b46..5238bcea8eaf087ed8ecfe1032b6914a23ee00c1 100644 (file)
@@ -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.