mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: add GODEBUG tokens for debugging lazy module loading
GODEBUG=lazymod=log causes the go command to log a stack dump whenever the full module graph is loaded in a lazy module. GODEBUG=lazymod=strict does the same, but also terminates the command with a nonzero exit code. For #36460 Change-Id: Ia5a4c46069044bcc157b285f64c2392990d70bd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/315411 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
eb71887b99
commit
cbff713e68
1 changed files with 19 additions and 0 deletions
|
|
@ -11,8 +11,10 @@ import (
|
||||||
"cmd/go/internal/par"
|
"cmd/go/internal/par"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
@ -232,12 +234,29 @@ type summaryError struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var readModGraphDebugOnce sync.Once
|
||||||
|
|
||||||
// readModGraph reads and returns the module dependency graph starting at the
|
// readModGraph reads and returns the module dependency graph starting at the
|
||||||
// given roots.
|
// given roots.
|
||||||
//
|
//
|
||||||
// Unlike LoadModGraph, readModGraph does not attempt to diagnose or update
|
// Unlike LoadModGraph, readModGraph does not attempt to diagnose or update
|
||||||
// inconsistent roots.
|
// inconsistent roots.
|
||||||
func readModGraph(ctx context.Context, depth modDepth, roots []module.Version) (*ModuleGraph, error) {
|
func readModGraph(ctx context.Context, depth modDepth, roots []module.Version) (*ModuleGraph, error) {
|
||||||
|
if depth == lazy {
|
||||||
|
readModGraphDebugOnce.Do(func() {
|
||||||
|
for _, f := range strings.Split(os.Getenv("GODEBUG"), ",") {
|
||||||
|
switch f {
|
||||||
|
case "lazymod=log":
|
||||||
|
debug.PrintStack()
|
||||||
|
fmt.Fprintf(os.Stderr, "go: read full module graph.\n")
|
||||||
|
case "lazymod=strict":
|
||||||
|
debug.PrintStack()
|
||||||
|
base.Fatalf("go: read full module graph (forbidden by GODEBUG=lazymod=strict).")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
mu sync.Mutex // guards mg.g and hasError during loading
|
mu sync.Mutex // guards mg.g and hasError during loading
|
||||||
hasError bool
|
hasError bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue