mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: remove loaderstate dependency
This change removes the dependency on the module loader state from the `QueryMatchesMainModulesError.Error()` method. This commit is part of the overall effort to eliminate global modloader state. Change-Id: I47241587a0bf9b578931628f35ed3b936a0cb04a Reviewed-on: https://go-review.googlesource.com/c/go/+/714700 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
83a44bde64
commit
ca379b1c56
2 changed files with 32 additions and 23 deletions
|
|
@ -735,7 +735,12 @@ func (r *resolver) queryNone(loaderstate *modload.State, ctx context.Context, q
|
|||
// However, neither of those behaviors would be consistent with the
|
||||
// plain meaning of the query. To try to reduce confusion, reject the
|
||||
// query explicitly.
|
||||
return errSet(&modload.QueryMatchesMainModulesError{LoaderState: loaderstate, MainModules: []module.Version{v}, Pattern: q.pattern, Query: q.version})
|
||||
return errSet(&modload.QueryMatchesMainModulesError{
|
||||
MainModules: []module.Version{v},
|
||||
Pattern: q.pattern,
|
||||
Query: q.version,
|
||||
PatternIsModule: loaderstate.MainModules.Contains(q.pattern),
|
||||
})
|
||||
}
|
||||
|
||||
return pathSet{mod: module.Version{Path: q.pattern, Version: "none"}}
|
||||
|
|
@ -748,7 +753,12 @@ func (r *resolver) queryNone(loaderstate *modload.State, ctx context.Context, q
|
|||
}
|
||||
q.pathOnce(curM.Path, func() pathSet {
|
||||
if modload.HasModRoot(loaderstate) && curM.Version == "" && loaderstate.MainModules.Contains(curM.Path) {
|
||||
return errSet(&modload.QueryMatchesMainModulesError{LoaderState: loaderstate, MainModules: []module.Version{curM}, Pattern: q.pattern, Query: q.version})
|
||||
return errSet(&modload.QueryMatchesMainModulesError{
|
||||
MainModules: []module.Version{curM},
|
||||
Pattern: q.pattern,
|
||||
Query: q.version,
|
||||
PatternIsModule: loaderstate.MainModules.Contains(q.pattern),
|
||||
})
|
||||
}
|
||||
return pathSet{mod: module.Version{Path: curM.Path, Version: "none"}}
|
||||
})
|
||||
|
|
@ -852,10 +862,10 @@ func (r *resolver) queryWildcard(loaderstate *modload.State, ctx context.Context
|
|||
if loaderstate.MainModules.Contains(curM.Path) && !versionOkForMainModule(q.version) {
|
||||
if q.matchesPath(curM.Path) {
|
||||
return errSet(&modload.QueryMatchesMainModulesError{
|
||||
LoaderState: loaderstate,
|
||||
MainModules: []module.Version{curM},
|
||||
Pattern: q.pattern,
|
||||
Query: q.version,
|
||||
PatternIsModule: loaderstate.MainModules.Contains(q.pattern),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1953,10 +1963,10 @@ func (r *resolver) resolve(s *modload.State, q *query, m module.Version) {
|
|||
|
||||
if s.MainModules.Contains(m.Path) && m.Version != "" {
|
||||
reportError(q, &modload.QueryMatchesMainModulesError{
|
||||
LoaderState: s,
|
||||
MainModules: []module.Version{{Path: m.Path}},
|
||||
Pattern: q.pattern,
|
||||
Query: q.version,
|
||||
PatternIsModule: s.MainModules.Contains(q.pattern),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -763,10 +763,10 @@ func QueryPattern(loaderstate *State, ctx context.Context, pattern, query string
|
|||
return nil, modOnly, nil
|
||||
} else if len(mainModuleMatches) != 0 {
|
||||
return nil, nil, &QueryMatchesMainModulesError{
|
||||
LoaderState: loaderstate,
|
||||
MainModules: mainModuleMatches,
|
||||
Pattern: pattern,
|
||||
Query: query,
|
||||
PatternIsModule: loaderstate.MainModules.Contains(pattern),
|
||||
}
|
||||
} else {
|
||||
return nil, nil, &PackageNotInModuleError{
|
||||
|
|
@ -827,9 +827,9 @@ func QueryPattern(loaderstate *State, ctx context.Context, pattern, query string
|
|||
|
||||
if len(mainModuleMatches) > 0 && len(results) == 0 && modOnly == nil && errors.Is(err, fs.ErrNotExist) {
|
||||
return nil, nil, &QueryMatchesMainModulesError{
|
||||
LoaderState: loaderstate,
|
||||
Pattern: pattern,
|
||||
Query: query,
|
||||
PatternIsModule: loaderstate.MainModules.Contains(pattern),
|
||||
}
|
||||
}
|
||||
return slices.Clip(results), modOnly, err
|
||||
|
|
@ -1287,15 +1287,14 @@ func (rr *replacementRepo) replacementStat(v string) (*modfetch.RevInfo, error)
|
|||
// a version of the main module that cannot be satisfied.
|
||||
// (The main module's version cannot be changed.)
|
||||
type QueryMatchesMainModulesError struct {
|
||||
LoaderState *State
|
||||
MainModules []module.Version
|
||||
Pattern string
|
||||
Query string
|
||||
PatternIsModule bool // true if pattern is one of the main modules
|
||||
}
|
||||
|
||||
func (e *QueryMatchesMainModulesError) Error() string {
|
||||
// TODO(jitsu): break dependency on loaderstate
|
||||
if e.LoaderState.MainModules.Contains(e.Pattern) {
|
||||
if e.PatternIsModule {
|
||||
return fmt.Sprintf("can't request version %q of the main module (%s)", e.Query, e.Pattern)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue