diff --git a/src/cmd/go/internal/modcmd/download.go b/src/cmd/go/internal/modcmd/download.go index 63eb6886a1a..1b2f850d1b4 100644 --- a/src/cmd/go/internal/modcmd/download.go +++ b/src/cmd/go/internal/modcmd/download.go @@ -153,7 +153,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) { // However, we also need to load the full module graph, to ensure that // we have downloaded enough of the module graph to run 'go list all', // 'go mod graph', and similar commands. - _, err := modload.LoadModGraph(ctx, "") + _, err := modload.LoadModGraph(modload.LoaderState, ctx, "") if err != nil { // TODO(#64008): call base.Fatalf instead of toolchain.SwitchOrFatal // here, since we can only reach this point with an outdated toolchain @@ -231,7 +231,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) { // TODO(#64008): In the future, report an error if go.mod or go.sum need to // be updated after loading the build list. This may require setting // the mode to "mod" or "readonly" depending on haveExplicitArgs. - if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil { + if err := modload.WriteGoMod(modload.LoaderState, ctx, modload.WriteOpts{}); err != nil { base.Fatal(err) } } @@ -348,7 +348,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) { // Don't save sums for 'go mod download' without arguments unless we're in // workspace mode; see comment above. if haveExplicitArgs || modload.WorkFilePath(modload.LoaderState) != "" { - if err := modload.WriteGoMod(ctx, modload.WriteOpts{}); err != nil { + if err := modload.WriteGoMod(modload.LoaderState, ctx, modload.WriteOpts{}); err != nil { base.Error(err) } } diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go index aa3c9f45405..2a1bad0e0ef 100644 --- a/src/cmd/go/internal/modcmd/graph.go +++ b/src/cmd/go/internal/modcmd/graph.go @@ -68,7 +68,7 @@ func runGraph(ctx context.Context, cmd *base.Command, args []string) { }) } - mg, err := modload.LoadModGraph(ctx, goVersion) + mg, err := modload.LoadModGraph(modload.LoaderState, ctx, goVersion) if err != nil { base.Fatal(err) } diff --git a/src/cmd/go/internal/modcmd/verify.go b/src/cmd/go/internal/modcmd/verify.go index d8227bcd545..bf803fd2ebb 100644 --- a/src/cmd/go/internal/modcmd/verify.go +++ b/src/cmd/go/internal/modcmd/verify.go @@ -57,7 +57,7 @@ func runVerify(ctx context.Context, cmd *base.Command, args []string) { type token struct{} sem := make(chan token, runtime.GOMAXPROCS(0)) - mg, err := modload.LoadModGraph(ctx, "") + mg, err := modload.LoadModGraph(modload.LoaderState, ctx, "") if err != nil { base.Fatal(err) } diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go index 9de24c4508a..b8018c04c98 100644 --- a/src/cmd/go/internal/modget/get.go +++ b/src/cmd/go/internal/modget/get.go @@ -412,7 +412,7 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) { // Everything succeeded. Update go.mod. oldReqs := reqsFromGoMod(modload.ModFile()) - if err := modload.WriteGoMod(ctx, opts); err != nil { + if err := modload.WriteGoMod(modload.LoaderState, ctx, opts); err != nil { // A TooNewError can happen for 'go get go@newversion' // when all the required modules are old enough // but the command line is not. @@ -556,7 +556,7 @@ type matchInModuleKey struct { func newResolver(ctx context.Context, queries []*query) *resolver { // LoadModGraph also sets modload.Target, which is needed by various resolver // methods. - mg, err := modload.LoadModGraph(ctx, "") + mg, err := modload.LoadModGraph(modload.LoaderState, ctx, "") if err != nil { toolchain.SwitchOrFatal(modload.LoaderState, ctx, err) } @@ -2033,7 +2033,7 @@ func (r *resolver) updateBuildList(ctx context.Context, additions []module.Versi return false } - mg, err := modload.LoadModGraph(ctx, "") + mg, err := modload.LoadModGraph(modload.LoaderState, ctx, "") if err != nil { toolchain.SwitchOrFatal(modload.LoaderState, ctx, err) } diff --git a/src/cmd/go/internal/modload/buildlist.go b/src/cmd/go/internal/modload/buildlist.go index 54ec4d23ebe..bd3fc3ec757 100644 --- a/src/cmd/go/internal/modload/buildlist.go +++ b/src/cmd/go/internal/modload/buildlist.go @@ -552,14 +552,14 @@ func (mg *ModuleGraph) allRootsSelected(loaderstate *State) bool { // Modules are loaded automatically (and lazily) in LoadPackages: // LoadModGraph need only be called if LoadPackages is not, // typically in commands that care about modules but no particular package. -func LoadModGraph(ctx context.Context, goVersion string) (*ModuleGraph, error) { - rs, err := loadModFile(LoaderState, ctx, nil) +func LoadModGraph(loaderstate *State, ctx context.Context, goVersion string) (*ModuleGraph, error) { + rs, err := loadModFile(loaderstate, ctx, nil) if err != nil { return nil, err } if goVersion != "" { - v, _ := rs.rootSelected(LoaderState, "go") + v, _ := rs.rootSelected(loaderstate, "go") if gover.Compare(v, gover.GoStrictVersion) >= 0 && gover.Compare(goVersion, v) < 0 { return nil, fmt.Errorf("requested Go version %s cannot load module graph (requires Go >= %s)", goVersion, v) } @@ -569,17 +569,17 @@ func LoadModGraph(ctx context.Context, goVersion string) (*ModuleGraph, error) { // Use newRequirements instead of convertDepth because convertDepth // also updates roots; here, we want to report the unmodified roots // even though they may seem inconsistent. - rs = newRequirements(LoaderState, unpruned, rs.rootModules, rs.direct) + rs = newRequirements(loaderstate, unpruned, rs.rootModules, rs.direct) } - return rs.Graph(LoaderState, ctx) + return rs.Graph(loaderstate, ctx) } - rs, mg, err := expandGraph(LoaderState, ctx, rs) + rs, mg, err := expandGraph(loaderstate, ctx, rs) if err != nil { return nil, err } - LoaderState.requirements = rs + loaderstate.requirements = rs return mg, nil } diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 9182f60ee7b..9b8e520d74a 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -1808,9 +1808,9 @@ type WriteOpts struct { } // WriteGoMod writes the current build list back to go.mod. -func WriteGoMod(ctx context.Context, opts WriteOpts) error { - LoaderState.requirements = LoadModFile(LoaderState, ctx) - return commitRequirements(LoaderState, ctx, opts) +func WriteGoMod(loaderstate *State, ctx context.Context, opts WriteOpts) error { + loaderstate.requirements = LoadModFile(loaderstate, ctx) + return commitRequirements(loaderstate, ctx, opts) } var errNoChange = errors.New("no update needed") diff --git a/src/cmd/go/internal/workcmd/sync.go b/src/cmd/go/internal/workcmd/sync.go index dfff0c29d22..7f45909de5c 100644 --- a/src/cmd/go/internal/workcmd/sync.go +++ b/src/cmd/go/internal/workcmd/sync.go @@ -54,7 +54,7 @@ func runSync(ctx context.Context, cmd *base.Command, args []string) { base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)") } - _, err := modload.LoadModGraph(ctx, "") + _, err := modload.LoadModGraph(modload.LoaderState, ctx, "") if err != nil { toolchain.SwitchOrFatal(modload.LoaderState, ctx, err) } @@ -129,7 +129,7 @@ func runSync(ctx context.Context, cmd *base.Command, args []string) { SilenceMissingStdImports: true, SilencePackageErrors: true, }, "all") - modload.WriteGoMod(ctx, modload.WriteOpts{}) + modload.WriteGoMod(modload.LoaderState, ctx, modload.WriteOpts{}) } goV = gover.Max(goV, modload.LoaderState.MainModules.GoVersion(modload.LoaderState)) }