Imports #
"fmt"
"strings"
"golang.org/x/mod/module"
"fmt"
"slices"
"cmd/go/internal/gover"
"golang.org/x/mod/module"
"fmt"
"slices"
"sort"
"sync"
"cmd/internal/par"
"golang.org/x/mod/module"
"fmt"
"strings"
"golang.org/x/mod/module"
"fmt"
"slices"
"cmd/go/internal/gover"
"golang.org/x/mod/module"
"fmt"
"slices"
"sort"
"sync"
"cmd/internal/par"
"golang.org/x/mod/module"
A DowngradeReqs is a Reqs that can also identify available downgrades.
type DowngradeReqs interface {
Reqs
Previous(m module.Version) (module.Version, error)
}
A Reqs is the requirement graph on which Minimal Version Selection (MVS) operates. The version strings are opaque except for the special version "none" (see the documentation for module.Version). In particular, MVS does not assume that the version strings are semantic versions; instead, the Max method gives access to the comparison operation. It must be safe to call methods on a Reqs from multiple goroutines simultaneously. Because a Reqs may read the underlying graph from the network on demand, the MVS algorithms parallelize the traversal to overlap network delays.
type Reqs interface {
Required(m module.Version) ([]module.Version, error)
Max(p string, v1 string, v2 string) string
}
An UpgradeReqs is a Reqs that can also identify available upgrades.
type UpgradeReqs interface {
Reqs
Upgrade(m module.Version) (module.Version, error)
}
BuildListError decorates an error that occurred gathering requirements while constructing a build list. BuildListError prints the chain of requirements to the module where the error occurred.
type BuildListError struct {
Err error
stack []buildListErrorElem
}
Graph implements an incremental version of the MVS algorithm, with the requirements pushed by the caller instead of pulled by the MVS traversal.
type Graph struct {
cmp func(p string, v1 string, v2 string) int
roots []module.Version
required map[module.Version][]module.Version
isRoot map[module.Version]bool
selected map[string]string
}
type buildListErrorElem struct {
m module.Version
nextReason string
}
type override struct {
target module.Version
list []module.Version
Reqs
}
BuildList returns the selected versions of all modules present in the Graph, beginning with the selected versions of each module path in the roots of g. The order of the remaining elements in the list is deterministic but arbitrary.
func (g *Graph) BuildList() []module.Version
BuildList returns the build list for the target module. target is the root vertex of a module requirement graph. For cmd/go, this is typically the main module, but note that this algorithm is not intended to be Go-specific: module paths and versions are treated as opaque values. reqs describes the module requirement graph and provides an opaque method for comparing versions. BuildList traverses the graph and returns a list containing the highest version for each visited module. The first element of the returned list is target itself; reqs.Max requires target.Version to compare higher than all other versions, so no other version can be selected. The remaining elements of the list are sorted by path. See https://research.swtch.com/vgo-mvs for details.
func BuildList(targets []module.Version, reqs Reqs) ([]module.Version, error)
Downgrade returns a build list for the target module in which the given additional modules are downgraded, potentially overriding the requirements of the target. The versions to be downgraded may be unreachable from reqs.Latest and reqs.Previous, but the methods of reqs must otherwise handle such versions correctly.
func Downgrade(target module.Version, reqs DowngradeReqs, downgrade ...module.Version) ([]module.Version, error)
func (e *BuildListError) Error() string
FindPath reports a shortest requirement path starting at one of the roots of the graph and ending at a module version m for which f(m) returns true, or nil if no such path exists.
func (g *Graph) FindPath(f func(module.Version) bool) []module.Version
Module returns the module where the error occurred. If the module stack is empty, this returns a zero value.
func (e *BuildListError) Module() module.Version
NewBuildListError returns a new BuildListError wrapping an error that occurred at a module found along the given path of requirements and/or upgrades, which must be non-empty. The isVersionChange function reports whether a path step is due to an explicit upgrade or downgrade (as opposed to an existing requirement in a go.mod file). A nil isVersionChange function indicates that none of the path steps are due to explicit version changes.
func NewBuildListError(err error, path []module.Version, isVersionChange func(from module.Version, to module.Version) bool) *BuildListError
NewGraph returns an incremental MVS graph containing only a set of root dependencies and using the given max function for version strings. The caller must ensure that the root slice is not modified while the Graph may be in use.
func NewGraph(cmp func(p string, v1 string, v2 string) int, roots []module.Version) *Graph
Req returns the minimal requirement list for the target module, with the constraint that all module paths listed in base must appear in the returned list.
func Req(mainModule module.Version, base []string, reqs Reqs) ([]module.Version, error)
Require adds the information that module m requires all modules in reqs. The reqs slice must not be modified after it is passed to Require. m must be reachable by some existing chain of requirements from g's target, and Require must not have been called for it already. If any of the modules in reqs has the same path as g's target, the target must have higher precedence than the version in req.
func (g *Graph) Require(m module.Version, reqs []module.Version)
func (r *override) Required(m module.Version) ([]module.Version, error)
RequiredBy returns the slice of requirements passed to Require for m, if any, with its capacity reduced to its length. If Require has not been called for m, RequiredBy(m) returns ok=false. The caller must not modify the returned slice, but may safely append to it and may rely on it not to be modified.
func (g *Graph) RequiredBy(m module.Version) (reqs []module.Version, ok bool)
Selected returns the selected version of the given module path. If no version is selected, Selected returns version "none".
func (g *Graph) Selected(path string) (version string)
func (e *BuildListError) Unwrap() error
Upgrade returns a build list for the target module in which the given additional modules are upgraded.
func Upgrade(target module.Version, reqs UpgradeReqs, upgrade ...module.Version) ([]module.Version, error)
UpgradeAll returns a build list for the target module in which every module is upgraded to its latest version.
func UpgradeAll(target module.Version, reqs UpgradeReqs) ([]module.Version, error)
WalkBreadthFirst invokes f once, in breadth-first order, for each module version other than "none" that appears in the graph, regardless of whether that version is selected.
func (g *Graph) WalkBreadthFirst(f func(m module.Version))
func buildList(targets []module.Version, reqs Reqs, upgrade func(module.Version) (module.Version, error)) ([]module.Version, error)
Generated with Arrow