resolve

package module
v0.0.0-...-b3ba033 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 15 Imported by: 4

Documentation

Overview

Package resolve performs dependency resolution.

The Client interface describes how to access available package versions and their dependencies. Implementers of the Resolver interface use a Client to find a satisfactory set of packages and versions, and produce a Graph which describes those versions and their relationship to one another.

Index

Constants

View Source
const MaxMavenParent = 100

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned by Clients to indicate the requested data could not be located.

Functions

func MavenDepType

func MavenDepType(d maven.Dependency, origin string) dep.Type

func MavenDepTypeToDependency

func MavenDepTypeToDependency(typ dep.Type) (maven.Dependency, string, error)

func SortDependencies

func SortDependencies(deps []RequirementVersion)

SortDependencies sorts a set of dependencies in a system-specific order for resolution. For many systems this is no order, as it can be important to the resolution that they are processed in the order they were retrieved from the metadata.

func SortVersionKeys

func SortVersionKeys(ks []VersionKey)

SortVersionKeys sorts the given slice of VersionKeys in the order specified by the VersionKey.Less method.

func SortVersions

func SortVersions(vs []Version)

SortVersions sorts a set of version in ascending order, by semver.

Types

type APIClient

type APIClient struct {
	// contains filtered or unexported fields
}

APIClient is a Client that fetches data from the deps.dev API. For now it only supports NPM because that is the only system with a resolver implementation. It performs no caching, and nearly every method is an API call so it can be slow when resolving large dependency graphs. Note that bundled versions are constructed from the bundling version's Requirements call, so will be inaccessible until this is called at which point the client will store them. For dependency resolution this is typically not an issue, as bundled versions will only be visited after the version that bundles them. It is safe for concurrent use.

func NewAPIClient

func NewAPIClient(c pb.InsightsClient) *APIClient

NewAPIClient creates a new APIClient using the provided gRPC client to call the deps.dev Insights service.

func (*APIClient) MatchingVersions

func (a *APIClient) MatchingVersions(ctx context.Context, vk VersionKey) ([]Version, error)

func (*APIClient) Requirements

func (a *APIClient) Requirements(ctx context.Context, vk VersionKey) ([]RequirementVersion, error)

func (*APIClient) Version

func (a *APIClient) Version(ctx context.Context, vk VersionKey) (Version, error)

func (*APIClient) Versions

func (a *APIClient) Versions(ctx context.Context, pk PackageKey) ([]Version, error)

type Client

type Client interface {
	// Version finds a particular version, providing access to its
	// attributes.
	Version(context.Context, VersionKey) (Version, error)
	// Versions returns all the known versions of a package.
	Versions(context.Context, PackageKey) ([]Version, error)
	// Requirements returns the direct dependencies of the provided version.
	Requirements(context.Context, VersionKey) ([]RequirementVersion, error)
	// MatchingVersions return the set of concrete versions that match the
	// provided requirement version. The versions are returned in a
	// system-specific order, expected by the relevant resolver.
	MatchingVersions(context.Context, VersionKey) ([]Version, error)
}

Client defines an interface to fetch the data needed for dependency resolutions.

type Edge

type Edge struct {
	From        NodeID
	To          NodeID
	Requirement string
	Type        dep.Type
}

Edge represents a resolution From an importer Node To an imported Node, satisfying the importer's Requirement for the given dependency Type.

type Graph

type Graph struct {
	// The first element in the slice is the root node.
	// NodeID is the index into this slice.
	Nodes []Node

	Edges []Edge

	// Error is a graph-wide resolution error that is set if the resolver
	// was not able to perform the resolution based on its input data; it
	// is not used for errors that are independent of the data such as a
	// network connection problem.
	Error string

	// Duration is the time it took to perform this resolution.
	Duration time.Duration
}

Graph holds the result of a dependency resolution.

func (*Graph) AddEdge

func (g *Graph) AddEdge(from, to NodeID, req string, t dep.Type) error

AddEdge inserts an edge in the graph between the two provided nodes.

func (*Graph) AddError

func (g *Graph) AddError(n NodeID, req VersionKey, err string) error

AddError associates a resolution error with a node and the requirement that caused the error.

func (*Graph) AddNode

func (g *Graph) AddNode(vk VersionKey) NodeID

AddNode inserts a node into the graph, not connected to anything. The returned ID is required to add edges.

func (*Graph) Canon

func (g *Graph) Canon() error

Canon converts the graph (in place) into a canonicalized representation, suitable for comparing with other graphs. If it fails then the graph is still valid but won't be a canonical form.

func (*Graph) String

func (g *Graph) String() string

String produces a text representation of the graph. The graph is represented by a spanning tree computed using the creator relationship (when available, first edge otherwise). Extraneous (non creating) edges are represented using labels. The representation is recognized by the resolve graph schema.

type LocalClient

type LocalClient struct {
	// PackageVersions holds all the Concrete versions of every package.
	PackageVersions map[PackageKey][]Version
	// contains filtered or unexported fields
}

func NewLocalClient

func NewLocalClient() *LocalClient

NewLocalClient creates a new, empty, LocalClient.

func (*LocalClient) AddVersion

func (lc *LocalClient) AddVersion(v Version, deps []RequirementVersion)

AddVersion adds a version to the client along with its direct dependencies. Any existing version will be replaced. Also ensures all packages in the dependencies have an entry in the PackageVersions map, although it may be empty.

func (*LocalClient) MatchingVersions

func (lc *LocalClient) MatchingVersions(ctx context.Context, vk VersionKey) ([]Version, error)

MatchingVersions implements Client, returning all of the known Concrete versions that satisfy the provided requirement.

func (*LocalClient) Requirements

func (lc *LocalClient) Requirements(ctx context.Context, vk VersionKey) ([]RequirementVersion, error)

Requirements implements Client, returning the direct dependencies of a version.

func (*LocalClient) Version

func (lc *LocalClient) Version(ctx context.Context, vk VersionKey) (Version, error)

Version implements Client, finding a Version by key.

func (*LocalClient) Versions

func (lc *LocalClient) Versions(ctx context.Context, pk PackageKey) ([]Version, error)

Versions implements Client, returning all of the known Concrete versions for the given package.

type Node

type Node struct {
	Version VersionKey
	Errors  []NodeError
}

Node is a concrete version in a resolved dependency Graph.

func (Node) Compare

func (n Node) Compare(o Node) int

type NodeError

type NodeError struct {
	Req   VersionKey
	Error string
}

NodeError holds error information for a Node's Requirement.

func (NodeError) Compare

func (ne NodeError) Compare(other NodeError) int

type NodeID

type NodeID int

NodeID identifies a node in a Graph. It is always scoped to a specific Graph, and is an index of the Nodes slice in that Graph.

type PackageKey

type PackageKey struct {
	System
	Name string
}

PackageKey uniquely identifies a package.

func (PackageKey) Compare

func (pk1 PackageKey) Compare(pk2 PackageKey) int

Compare reports whether pk1 is less than, equal to or greater than pk2, returning a -1, 0 or 1. respectively. It compares System, PackageType and then Name.

func (PackageKey) String

func (k PackageKey) String() string

type RequirementVersion

type RequirementVersion struct {
	VersionKey // The requirement version.
	Type       dep.Type
}

RequirementVersion represents a direct dependency.

func (RequirementVersion) String

func (d RequirementVersion) String() string

type Resolver

type Resolver interface {
	Resolve(context.Context, VersionKey) (*Graph, error)
}

Resolver describes a dependency resolver.

type System

type System byte

System nominates a packaging system, such as Maven, npm, etc.

func (System) Semver

func (s System) Semver() semver.System

Semver returns the corresponding semver.System.

func (System) String

func (i System) String() string

type Version

type Version struct {
	VersionKey
	version.AttrSet
}

Version combines a VersionKey with the version's attributes.

func MatchRequirement

func MatchRequirement(req VersionKey, versions []Version) []Version

MatchRequirement returns the items from the given list of Concrete versions that match the given Requirement version, with appropriate system-specific logic. The list can be in any order, which may be modified, and the returned versions will be in a system-specific order expected by the relevant resolver.

func (Version) Equal

func (v Version) Equal(w Version) bool

Equal reports whether the two versions are equivalent.

func (Version) String

func (v Version) String() string

type VersionKey

type VersionKey struct {
	PackageKey
	VersionType
	Version string
}

VersionKey uniquely identifies a version of a package.

func (VersionKey) Compare

func (vk1 VersionKey) Compare(vk2 VersionKey) int

Compare reports whether vk1 is less than, equal to or greater than vk2, returning -1, 0 or 1 respectively. It compares PackageKey, VersionType and then Version.

func (VersionKey) Less

func (vk1 VersionKey) Less(vk2 VersionKey) bool

Less reports whether vk1 sorts before vk2, sorting by PackageKey, VersionType, and then lexicographically by Version.

func (VersionKey) String

func (k VersionKey) String() string

type VersionType

type VersionType byte

VersionType indicates the type of a version.

const (
	UnknownVersionType VersionType = iota

	// Concrete versions nominate a specific version.
	Concrete

	// Requirement versions describe dependencies; they are a reference to a
	// set of acceptable concrete versions. Their version strings are
	// whatever their ecosystem uses to refer to a particular version or set
	// of versions in dependencies.
	Requirement
)

func (VersionType) String

func (i VersionType) String() string

Directories

Path Synopsis
Package dep provides data structures for representing dependency types.
Package dep provides data structures for representing dependency types.
internal
attr
Package attr provides data structures for representing sets of keyed attributes.
Package attr provides data structures for representing sets of keyed attributes.
deptest
Package deptest contains helpers to aid testing code that interacts with dependency types.
Package deptest contains helpers to aid testing code that interacts with dependency types.
resolvetest
Package resolvetest provides a way to define test data for resolvers.
Package resolvetest provides a way to define test data for resolvers.
versiontest
Package versiontest contains helpers to aid testing code that interacts with version attributes.
Package versiontest contains helpers to aid testing code that interacts with version attributes.
Package maven implements a resolver for Maven dependencies, based on Maven version 3.6.3.
Package maven implements a resolver for Maven dependencies, based on Maven version 3.6.3.
Package npm implements a resolver for NPM dependencies, based on npm version 6.14.12.
Package npm implements a resolver for NPM dependencies, based on npm version 6.14.12.
Package schema provides mechanisms for describing ecosystems that can be used to construct a resolve.LocalClient or a resolve.Graph suitable for use in tests.
Package schema provides mechanisms for describing ecosystems that can be used to construct a resolve.LocalClient or a resolve.Graph suitable for use in tests.
Package version provides data structures for representing version attributes.
Package version provides data structures for representing version attributes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL