dag

package
v0.23.5 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Local = "local"
)

Variables

View Source
var ErrMultipleConfigurations = fmt.Errorf("multiple configurations using the same package name")

Functions

func PackageHash added in v0.3.0

func PackageHash(p Package) string

PackageHash given anything that implements Package, return the hash to be used for the node in the graph.

Types

type Configuration

type Configuration struct {
	*config.Configuration
	Path string
	// contains filtered or unexported fields
}

Configuration represents a configuration along with the file that sourced it. It can be for an origin package, a subpackage, or something that is provided by a package. The Configuration field is a pointer to the actual configuration as parsed from a file. The Path field is the path to the file from which the configuration was parsed. The Name and Version fields are the name and version of the package, subpackage, or provided item. In the case of an origin package, the Name field is the same as the Configuration.Package.Name field, and the Version field is the same as the Configuration.Package.Version field with the epoch added as `-r<epoch>`. In the case of a subpackage or provided item, the Name and Version fields may be different.

func (Configuration) FullName added in v0.15.19

func (c Configuration) FullName() string

func (Configuration) Name

func (c Configuration) Name() string

func (Configuration) Resolved

func (c Configuration) Resolved() bool

func (Configuration) Source

func (c Configuration) Source() string

func (Configuration) String

func (c Configuration) String() string

func (Configuration) Version

func (c Configuration) Version() string

type Filter

type Filter func(Package) bool

Filter is a function that takes a Package and returns true if the Package should be included in the filtered Graph, or false if it should be excluded.

func FilterLocal

func FilterLocal() Filter

FilterLocal returns a Filter that returns true if the Package's source matches the local source, or false otherwise.

func FilterNotLocal

func FilterNotLocal() Filter

FilterNotLocal returns a Filter that returns true if the Package's source matches the local source, or false otherwise.

func FilterNotSources

func FilterNotSources(source ...string) Filter

FilterNotSources returns a Filter that returns false if the Package's source matches one of the provided sources, or true otherwise

func FilterSources

func FilterSources(source ...string) Filter

FilterSources returns a Filter that returns true if the Package's source matches one of the provided sources, or false otherwise

func OnlyMainPackages added in v0.1.4

func OnlyMainPackages(pkgs *Packages) Filter

Filter out non-main packages -- we only care about config file names, not each subpackage.

type Graph

type Graph struct {
	Graph graph.Graph[string, Package]
	// contains filtered or unexported fields
}

Graph represents an interdependent set of packages defined in one or more Melange configurations, as defined in Packages, as well as upstream repositories and their package indexes, as declared in those configurations files. The graph is directed and acyclic.

func NewGraph

func NewGraph(ctx context.Context, pkgs *Packages, options ...GraphOptions) (*Graph, error)

NewGraph returns a new Graph using the packages, including names and versions, in the Packages struct. It parses the packages to create the dependency graph. If the list of packages creates a cycle, an error is returned. If a package cannot be resolved, an error is returned, unless WithAllowUnresolved is set.

func (Graph) DependenciesOf

func (g Graph) DependenciesOf(node string) []string

DependenciesOf returns a slice of the names of the given package's dependencies, sorted alphabetically.

func (Graph) Filter

func (g Graph) Filter(filter Filter) (*Graph, error)

Filter returns a new Graph that's a subgraph of g, where the set of nodes in the new graph are filtered by the provided parameters. Must provide a func to which each Vertex of type Package is processed, and should return true to keep the Vertex and all references to it, or false to remove the Vertex and all references to it. Some convenience functions are provided for common filtering needs.

func (Graph) Nodes

func (g Graph) Nodes() (nodes []string, err error)

Nodes returns a slice of all of the nodes in the graph, sorted alphabetically. Unlike Packages, this includes subpackages, provides, etc.

func (Graph) NodesByName

func (g Graph) NodesByName(name string) (pkgs []Package, err error)

NodesByName returns a slice of all of the nodes in the graph for which the Vertex's Name() matches the provided name. The sorting order is not guaranteed.

func (Graph) Packages

func (g Graph) Packages() []string

Packages returns a slice of the names of all origin packages, sorted alphabetically.

func (Graph) RequirementsOf added in v0.1.4

func (g Graph) RequirementsOf(node string) []string

RequirementsOf returns a slice of the names of the given package's requirements, sorted alphabetically.

func (Graph) ReverseSorted

func (g Graph) ReverseSorted() ([]Package, error)

ReverseSorted returns a list of all package names in the Graph, sorted in reverse topological order, meaning that packages later in the list depend on packages earlier in the list.

func (Graph) Sorted

func (g Graph) Sorted() ([]Package, error)

Sorted returns a list of all package names in the Graph, sorted in topological order, meaning that packages earlier in the list depend on packages later in the list.

func (Graph) SubgraphWithLeaves

func (g Graph) SubgraphWithLeaves(leaves []string) (*Graph, error)

SubgraphWithLeaves returns a new Graph that's a subgraph of g, where the set of the new Graph's leaves will be identical to or a subset of the given set of leaves.

In other words, the new subgraph will contain all packages (transitively) that are dependent on the packages whose names were given as the `leaves` argument.

func (Graph) SubgraphWithRoots

func (g Graph) SubgraphWithRoots(ctx context.Context, roots []string) (*Graph, error)

SubgraphWithRoots returns a new Graph that's a subgraph of g, where the set of the new Graph's roots will be identical to or a subset of the given set of roots.

In other words, the new subgraph will contain all dependencies (transitively) of all packages whose names were given as the `roots` argument.

func (Graph) Targets added in v0.15.17

func (g Graph) Targets() (*Graph, error)

Targets returns a subgraph that flattens subpackages into their origins.

type GraphOptions

type GraphOptions func(*graphOptions) error

func WithAllowUnresolved

func WithAllowUnresolved() GraphOptions

func WithArch added in v0.12.0

func WithArch(arch string) GraphOptions

WithArch sets the architecture for which the graph is built.

func WithKeys

func WithKeys(keys ...string) GraphOptions

WithKeys add keys for validating repositories referenced in the buildtime graph, i.e. environments.contents.packages. The local repository in which this package is defined does not need additional keys. Normally used in concert with WithRepos.

func WithRepos

func WithRepos(repos ...string) GraphOptions

WithRepos add repos for resolution of the buildtime graph, i.e. environments.contents.packages. Always includes packages in the local repository in which this package is defined. Optionally, you can add other repositories.

type Package

type Package interface {
	Name() string
	Version() string
	String() string // String shows the combination name and version
	Source() string // Source shows the source repository of the package
	Resolved() bool // if this is resolved or just an interim
}

Package represents an individual package.

type Packages

type Packages struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Packages represents a set of package configurations, including the parent, or origin, package, its subpackages, and whatever else it 'provides'. It contains references from each such origin package, subpackage and provides to the origin config.

It also maintains a list of the origin packages.

It does not try to determine relationships and dependencies between packages. For that, pass a Packages to NewGraph.

func NewPackages

func NewPackages(ctx context.Context, fsys fs.FS, dirPath, pipelineDir string) (*Packages, error)

NewPackages reads an fs.FS to get all of the Melange configuration yamls in the given directory, and then parses them, including their subpackages and 'provides' parameters, to create a Packages struct with all of the information, as well as the list of original packages, and, for each such package, the source path (yaml) from which it came. The result is a Packages struct.

The input is any fs.FS filesystem implementation. Given a directory path, you can call NewPackages like this:

NewPackages(ctx, os.DirFS("/path/to/dir"), "/path/to/dir", "./pipelines")

The repetition of the path is necessary because of how the upstream parser in melange requires the full path to the directory to be passed in.

func (*Packages) Config

func (p *Packages) Config(name string, packageOnly bool) []*Configuration

Config returns the Melange configuration for the package, provides or subpackage with the given name, if the package is present in the Graph. If it's not present, Config returns an empty list.

Pass packageOnly=true to restruct it just to origin package names.

func (*Packages) ConfigByKey

func (p *Packages) ConfigByKey(key string) *Configuration

func (*Packages) PackageNames

func (p *Packages) PackageNames() []string

PackageNames returns a slice of the names of all packages, sorted alphabetically.

func (*Packages) Packages

func (p *Packages) Packages() []*Configuration

Packages returns a slice of every package and subpackage available in the Packages struct, sorted alphabetically and then by version, with each package converted to a *apk.RepositoryPackage.

func (*Packages) PkgConfig added in v0.15.17

func (p *Packages) PkgConfig(pkgName string) *Configuration

PkgConfig returns the melange Configuration for a given package name.

func (*Packages) PkgInfo

func (p *Packages) PkgInfo(pkgName string) *config.Package

PkgInfo returns the build.Package struct for a given package name. If no such package name is found in the packages, return nil package and nil error.

func (*Packages) Repository

func (p *Packages) Repository(arch string) apk.NamedIndex

Repository provide the Packages as a apk.RepositoryWithIndex. To be used in other places that require using alpine/go structs instead of ours.

func (*Packages) Sub

func (p *Packages) Sub(names ...string) (*Packages, error)

Sub returns a new Packages whose members are the named packages or provides that are listed. If a listed element is a provides, automatically includes the origin package that provides it. If a listed element is a subpackage, automatically includes the origin package that contains it. If a listed element does not exist, returns an error.

func (*Packages) WithArch added in v0.15.5

func (p *Packages) WithArch(arch string) (*Packages, error)

WithArch returns a new Packages whose members are valid for the given arch.

Jump to

Keyboard shortcuts

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