diff --git a/src/cmd/go/internal/modload/buildlist.go b/src/cmd/go/internal/modload/buildlist.go index bd3fc3ec757..cb64bec9c81 100644 --- a/src/cmd/go/internal/modload/buildlist.go +++ b/src/cmd/go/internal/modload/buildlist.go @@ -1319,7 +1319,7 @@ func tidyUnprunedRoots(loaderstate *State, ctx context.Context, mainModule modul // Construct a build list with a minimal set of roots. // This may remove or downgrade modules in altMods. - reqs := &mvsReqs{roots: keep} + reqs := &mvsReqs{loaderstate: loaderstate, roots: keep} min, err := mvs.Req(mainModule, rootPaths, reqs) if err != nil { return nil, err @@ -1445,7 +1445,7 @@ func updateUnprunedRoots(loaderstate *State, ctx context.Context, direct map[str var roots []module.Version for _, mainModule := range loaderstate.MainModules.Versions() { - min, err := mvs.Req(mainModule, rootPaths, &mvsReqs{roots: keep}) + min, err := mvs.Req(mainModule, rootPaths, &mvsReqs{loaderstate: loaderstate, roots: keep}) if err != nil { return rs, err } diff --git a/src/cmd/go/internal/modload/edit.go b/src/cmd/go/internal/modload/edit.go index 72d0f754224..1996b7c26b0 100644 --- a/src/cmd/go/internal/modload/edit.go +++ b/src/cmd/go/internal/modload/edit.go @@ -532,7 +532,7 @@ func editRequirements(loaderstate *State, ctx context.Context, rs *Requirements, } } - roots, err = mvs.Req(loaderstate.MainModules.mustGetSingleMainModule(loaderstate), rootPaths, &mvsReqs{roots: roots}) + roots, err = mvs.Req(loaderstate.MainModules.mustGetSingleMainModule(loaderstate), rootPaths, &mvsReqs{loaderstate: loaderstate, roots: roots}) if err != nil { return nil, false, err } diff --git a/src/cmd/go/internal/modload/mvs.go b/src/cmd/go/internal/modload/mvs.go index fba508873fa..63fedae0f16 100644 --- a/src/cmd/go/internal/modload/mvs.go +++ b/src/cmd/go/internal/modload/mvs.go @@ -39,11 +39,12 @@ func cmpVersion(p string, v1, v2 string) int { // mvsReqs implements mvs.Reqs for module semantic versions, // with any exclusions or replacements applied internally. type mvsReqs struct { - roots []module.Version + loaderstate *State // TODO(jitsu): Is there a way we can not depend on the entire loader state? + roots []module.Version } func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) { - if mod.Version == "" && LoaderState.MainModules.Contains(mod.Path) { + if mod.Version == "" && r.loaderstate.MainModules.Contains(mod.Path) { // Use the build list as it existed when r was constructed, not the current // global build list. return r.roots, nil @@ -53,7 +54,7 @@ func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) { return nil, nil } - summary, err := goModSummary(LoaderState, mod) + summary, err := goModSummary(r.loaderstate, mod) if err != nil { return nil, err } @@ -130,7 +131,7 @@ func previousVersion(loaderstate *State, ctx context.Context, m module.Version) return module.Version{Path: m.Path, Version: "none"}, nil } -func (*mvsReqs) Previous(m module.Version) (module.Version, error) { +func (r *mvsReqs) Previous(m module.Version) (module.Version, error) { // TODO(golang.org/issue/38714): thread tracing context through MVS. - return previousVersion(LoaderState, context.TODO(), m) + return previousVersion(r.loaderstate, context.TODO(), m) }