mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: add loaderstate as field on mvsReqs
This change modifies the type `mvsReqs` to have an additional field to store the current module loader state. The field is used to break the dependency on the global `modload.LoaderState` variable. This commit is part of the overall effort to eliminate global modloader state. Change-Id: Id6bd96bc5de68bf327f9e78a778173634e1d15d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/711122 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
ccf4192a31
commit
ade9f33e1f
3 changed files with 9 additions and 8 deletions
|
|
@ -1319,7 +1319,7 @@ func tidyUnprunedRoots(loaderstate *State, ctx context.Context, mainModule modul
|
||||||
|
|
||||||
// Construct a build list with a minimal set of roots.
|
// Construct a build list with a minimal set of roots.
|
||||||
// This may remove or downgrade modules in altMods.
|
// 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)
|
min, err := mvs.Req(mainModule, rootPaths, reqs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -1445,7 +1445,7 @@ func updateUnprunedRoots(loaderstate *State, ctx context.Context, direct map[str
|
||||||
|
|
||||||
var roots []module.Version
|
var roots []module.Version
|
||||||
for _, mainModule := range loaderstate.MainModules.Versions() {
|
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 {
|
if err != nil {
|
||||||
return rs, err
|
return rs, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,12 @@ func cmpVersion(p string, v1, v2 string) int {
|
||||||
// mvsReqs implements mvs.Reqs for module semantic versions,
|
// mvsReqs implements mvs.Reqs for module semantic versions,
|
||||||
// with any exclusions or replacements applied internally.
|
// with any exclusions or replacements applied internally.
|
||||||
type mvsReqs struct {
|
type mvsReqs struct {
|
||||||
|
loaderstate *State // TODO(jitsu): Is there a way we can not depend on the entire loader state?
|
||||||
roots []module.Version
|
roots []module.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
|
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
|
// Use the build list as it existed when r was constructed, not the current
|
||||||
// global build list.
|
// global build list.
|
||||||
return r.roots, nil
|
return r.roots, nil
|
||||||
|
|
@ -53,7 +54,7 @@ func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
summary, err := goModSummary(LoaderState, mod)
|
summary, err := goModSummary(r.loaderstate, mod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
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.
|
// TODO(golang.org/issue/38714): thread tracing context through MVS.
|
||||||
return previousVersion(LoaderState, context.TODO(), m)
|
return previousVersion(r.loaderstate, context.TODO(), m)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue