pkggraph

package
v0.0.0-...-4cb4cf9 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LocalRepo      = "<LOCAL_REPO>"
	NoArchitecture = "<NO_ARCHITECTURE>"
	NoName         = "<NO_NAME>"
	NoRPMPath      = "<NO_RPM_PATH>"
	NoSourceDir    = "<NO_SOURCE_DIR>"
	NoSourceRepo   = "<NO_SOURCE_REPO>"
	NoSpecPath     = "<NO_SPEC_PATH>"
	NoSRPMPath     = "<NO_SRPM_PATH>"
)

Constants representing empty member fields of the 'PkgNode' struct.

Variables

This section is empty.

Functions

func FindRPMFiles

func FindRPMFiles(srpmPath string, pkgGraph *PkgGraph, graphMutex *sync.RWMutex) (expectedFiles, missingFiles []string)

FindRPMFiles returns a list of all RPMs built by an SRPM and a list of these RPMs that are not available on the disk. The function will lock 'graphMutex' before performing the check if the mutex is not nil.

func ReadDOTGraph

func ReadDOTGraph(g graph.DirectedBuilder, input io.Reader) (err error)

ReadDOTGraph de-serializes a graph from a DOT formatted object

func WriteDOTGraph

func WriteDOTGraph(g graph.Directed, output io.Writer) (err error)

WriteDOTGraph serializes a graph into a DOT formatted object

func WriteDOTGraphFile

func WriteDOTGraphFile(g graph.Directed, filename string) (err error)

WriteDOTGraphFile writes the graph to a DOT graph format file

Types

type LookupNode

type LookupNode struct {
	RunNode   *PkgNode // The "meta" run node for a package. Tracks the run-time dependencies for the package. Remote packages will only have a RunNode.
	BuildNode *PkgNode // The build node for a package. Tracks the build requirements for the package. May be nil for remote packages.
	TestNode  *PkgNode // The test node for a package. Tracks the test requirements for the package. Nil for non-test builds and when its spec has no '%check' section.
}

LookupNode represents a graph node for a package in the lookup list

func (*LookupNode) PackageVer

func (n *LookupNode) PackageVer() (packageVer *pkgjson.PackageVer)

type NodeState

type NodeState int

NodeState indicates if a node is a package node (build, upToDate,unresolved,cached) or a meta node (meta)

const (
	StateUnknown    NodeState = iota // Unknown state
	StateMeta       NodeState = iota // Meta nodes do not represent actual build artifacts, but additional nodes used for managing dependencies
	StateBuild      NodeState = iota // A package from a local SRPM which should be built from source
	StateUpToDate   NodeState = iota // A local RPM is already built and is available
	StateUnresolved NodeState = iota // A dependency is not available locally and must be acquired from a remote repo
	StateCached     NodeState = iota // A dependency was not available locally, but is now available in the chache
	StateBuildError NodeState = iota // A package from a local SRPM which failed to build
	StateDelta      NodeState = iota // Same as build state, but an attempt has been made to pre-download the .rpm to the cache
	StateMAX        NodeState = iota // Max allowable state
)

Valid values for NodeState type

func (NodeState) String

func (n NodeState) String() string

type NodeType

type NodeType int

NodeType indicates the general node type (build, run, goal, remote).

const (
	TypeUnknown    NodeType = iota // Unknown type
	TypeLocalBuild NodeType = iota // Package can be build if all dependency edges are satisfied
	TypeLocalRun   NodeType = iota // Package can be run if all dependency edges are satisfied. Will be associated with a partner build node
	TypeGoal       NodeType = iota // Meta node which depends on a user selected subset of packages to be built.
	TypeRemoteRun  NodeType = iota // A non-local node which may have a cache entry
	TypePureMeta   NodeType = iota // An arbitrary meta node with no other meaning
	TypePreBuilt   NodeType = iota // A node indicating a pre-built SRPM used in breaking cyclic build dependencies
	TypeTest       NodeType = iota // A node for running the '%check' section of the underlying package
	TypeMAX        NodeType = iota // Max allowable type
)

Valid values for NodeType type

func (NodeType) String

func (n NodeType) String() string

type PkgGraph

type PkgGraph struct {
	*simple.DirectedGraph
	// contains filtered or unexported fields
}

PkgGraph implements a simple.DirectedGraph using pkggraph Nodes.

func NewPkgGraph

func NewPkgGraph() *PkgGraph

NewPkgGraph creates a new package dependency graph based on a simple.DirectedGraph

func ReadDOTGraphFile

func ReadDOTGraphFile(filename string) (outputGraph *PkgGraph, err error)

ReadDOTGraphFile reads the graph from a DOT graph format file

func (*PkgGraph) AddEdge

func (g *PkgGraph) AddEdge(from *PkgNode, to *PkgNode) (err error)

AddEdge creates a new edge between the provided nodes.

func (*PkgGraph) AddGoalNode

func (g *PkgGraph) AddGoalNode(goalName string, packages, tests []*pkgjson.PackageVer, strict bool) (goalNode *PkgNode, err error)

AddGoalNode adds a goal node to the graph which links to existing nodes. An empty package list will add an edge to all nodes

  • goalName: The name of the goal node to add
  • packages: A list of packages to add to link the goal node to. If empty, all nodes will be added to the goal node
  • strict: If true, the goal node will fail if any of the packages are not found

func (*PkgGraph) AddGoalNodeToNodes

func (g *PkgGraph) AddGoalNodeToNodes(goalName string, existingNodes []*PkgNode, extraLayers int) (goalNode *PkgNode, err error)

AddGoalNodeToNodes behaves similarly to AddGoalNodeWithExtraLayers, but instead of using a list of package versions (via graph lookup) to create the goal node, it uses a list of existing nodes in the graph.

  • goalName: The name of the goal node to add
  • existingNodes: A list of nodes to link the goal node to.
  • extraLayers: The number of levels to expand the goal node. Each level will add one more layer of packages beyond the goal node. For example, if the goal node is "x" and extraLevels is 1, the goal node will link to all nodes which depend on "x" as well as "x" itself (Specifically run nodes, all other nodes are stepped over)

func (*PkgGraph) AddGoalNodeWithExtraLayers

func (g *PkgGraph) AddGoalNodeWithExtraLayers(goalName string, packages, tests []*pkgjson.PackageVer, strict bool, extraLayers int) (goalNode *PkgNode, err error)

AddGoalNodeWithExtraLayers adds a goal node to the graph which links to existing nodes. An empty package list will add an edge to all nodes

  • goalName: The name of the goal node to add
  • packages: A list of packages to add to link the goal node to. If empty, all nodes will be added to the goal node
  • strict: If true, the goal node will fail if any of the packages are not found
  • extraLayers: The number of levels to expand the goal node. Each level will add one more layer of packages beyond the goal node. For example, if the goal node is "x" and extraLevels is 1, the goal node will link to all nodes which depend on "x" as well as "x" itself (Specifically run nodes, all other nodes are stepped over)

func (*PkgGraph) AddMetaNode

func (g *PkgGraph) AddMetaNode(from []*PkgNode, to []*PkgNode) (metaNode *PkgNode)

AddMetaNode adds a generic meta node with edges: <from> -> metaNode -> <to>

func (*PkgGraph) AddPkgNode

func (g *PkgGraph) AddPkgNode(versionedPkg *pkgjson.PackageVer, nodeState NodeState, nodeType NodeType, srpmPath, rpmPath, specPath, sourceDir, architecture, sourceRepo string) (newNode *PkgNode, err error)

AddPkgNode adds a new node to the package graph. Run, Build, and Unresolved nodes are recorded in the lookup table.

func (*PkgGraph) AddRemoteUnresolvedNode

func (g *PkgGraph) AddRemoteUnresolvedNode(versionedPkg *pkgjson.PackageVer) (newNode *PkgNode, err error)

AddRemoteUnresolvedNode adds a new node to the package graph representing an unresolved remote dependency.

func (*PkgGraph) AllBuildNodes

func (g *PkgGraph) AllBuildNodes() []*PkgNode

AllBuildNodes returns a list of all build nodes in the graph

func (*PkgGraph) AllImplicitNodes

func (g *PkgGraph) AllImplicitNodes() []*PkgNode

AllImplicitNodes returns a list of all implicit remote nodes in the graph

func (*PkgGraph) AllNodes

func (g *PkgGraph) AllNodes() []*PkgNode

AllNodes returns a list of all nodes in the graph.

func (*PkgGraph) AllNodesFrom

func (g *PkgGraph) AllNodesFrom(rootNode *PkgNode) []*PkgNode

AllNodesFrom returns a list of all nodes accessible from a root node

func (*PkgGraph) AllPreferredRunNodes

func (g *PkgGraph) AllPreferredRunNodes() []*PkgNode

AllPreferredRunNodes returns all RunNodes in the LookupTable Though a graph can contain both LocalRun and RemoteRun node for a single package-version, the LookupTable will have: 1. LocalRun Node if only LocalRun node is present in the graph 2. RemoteRun Node if only RemoteRun node is present in the graph 3. LocalRun Node if both LocalRun and RemoteRun nodes are present in the graph This function will return all RunNodes in the LookupTable.

func (*PkgGraph) AllRunNodes

func (g *PkgGraph) AllRunNodes() []*PkgNode

AllRunNodes returns a list of all run nodes in the graph It traverses the graph and returns all nodes of type TypeLocalRun and TypeRemoteRun.

func (*PkgGraph) AllTestNodes

func (g *PkgGraph) AllTestNodes() []*PkgNode

AllTestNodes returns a list of all test nodes in the graph

func (*PkgGraph) CloneNode

func (g *PkgGraph) CloneNode(pkgNode *PkgNode) (newNode *PkgNode)

CloneNode creates a clone of the input node with a new, unique ID. The clone doesn't have any edges attached to it.

func (*PkgGraph) CreateCollapsedNode

func (g *PkgGraph) CreateCollapsedNode(versionedPkg *pkgjson.PackageVer, parentNode *PkgNode, nodesToCollapse []*PkgNode) (newNode *PkgNode, err error)

CreateCollapsedNode creates a new run node linked to a given parent node. All nodes in nodesToCollapse will be collapsed into the new node. - When a node is collapsed all of its dependents will be mirrored onto the new node. - The parentNode must be a run node. - The collapsed node will inherit all attributes of the parent node minus the versionedPkg.

func (*PkgGraph) CreateSubGraph

func (g *PkgGraph) CreateSubGraph(rootNode *PkgNode) (subGraph *PkgGraph, err error)

CreateSubGraph returns a new graph with which only contains the nodes accessible from rootNode.

func (*PkgGraph) DeepCopy

func (g *PkgGraph) DeepCopy() (deepCopy *PkgGraph, err error)

DeepCopy returns a deep copy of the receiver. On error, the returned deepCopy is in an invalid state

func (*PkgGraph) FindAnyDirectedCycle

func (g *PkgGraph) FindAnyDirectedCycle() (nodes []*PkgNode, err error)

FindAnyDirectedCycle returns any single cycle in the graph, if one exists. Multiple instances of this routine should not be run at the same time on a given graph.

func (*PkgGraph) FindBestPkgNode

func (g *PkgGraph) FindBestPkgNode(pkgVer *pkgjson.PackageVer) (lookupEntry *LookupNode, err error)

FindBestPkgNode will search the lookup table to see if a node which satisfies the PackageVer structure has already been created. Returns nil if no lookup entry is found. Condition = "" is equivalent to Condition = "=".

func (*PkgGraph) FindDoubleConditionalPkgNodeFromPkg

func (g *PkgGraph) FindDoubleConditionalPkgNodeFromPkg(pkgVer *pkgjson.PackageVer) (lookupEntry *LookupNode, err error)

FindDoubleConditionalPkgNodeFromPkg has the same behavior as FindConditionalPkgNodeFromPkg but supports two conditionals

func (*PkgGraph) FindExactPkgNodeFromPkg

func (g *PkgGraph) FindExactPkgNodeFromPkg(pkgVer *pkgjson.PackageVer) (lookupEntry *LookupNode, err error)

FindExactPkgNodeFromPkg attempts to find a LookupNode which has the exactly correct version information listed in the PackageVer structure. Returns nil if no lookup entry is found.

func (*PkgGraph) FindGoalNode

func (g *PkgGraph) FindGoalNode(goalName string) *PkgNode

FindGoalNode returns a named goal node if one exists.

func (*PkgGraph) HasNode

func (g *PkgGraph) HasNode(pkgNode *PkgNode) bool

HasNode returns true if pkgNode points to a node that is present in the graph. If the object is not the same, but the ID is the same, it will return false (i.e., the node is a copy)

func (*PkgGraph) MakeDAG

func (g *PkgGraph) MakeDAG() (err error)

func (*PkgGraph) MakeDAGUsingUpstreamRepos

func (g *PkgGraph) MakeDAGUsingUpstreamRepos(resolveCyclesFromUpstream, ignoreVersionToResolveSelfDep bool, cloner *rpmrepocloner.RpmRepoCloner) (err error)

MakeDAGUsingUpstreamRepos ensures the graph is a directed acyclic graph (DAG). If the graph is not a DAG, this routine will attempt to resolve any cycles using RPMs in the PMC to make the graph a DAG.

func (*PkgGraph) NewNode

func (g *PkgGraph) NewNode() graph.Node

NewNode creates a new pkggraph Node for the graph

func (*PkgGraph) NodesMatchingFilter

func (g *PkgGraph) NodesMatchingFilter(filter func(*PkgNode) bool) (nodes []*PkgNode)

NodesMatchingFilter returns a list of all nodes satisfying the input filter.

func (*PkgGraph) RemovePkgNode

func (g *PkgGraph) RemovePkgNode(pkgNode *PkgNode)

RemovePkgNode removes a node from the package graph and lookup tables.

type PkgNode

type PkgNode struct {
	VersionedPkg *pkgjson.PackageVer // JSON derived structure holding the exact version information for a graph
	State        NodeState           // The current state of the node (ie needs to be build, up-to-date, cached, etc)
	Type         NodeType            // The purpose of the node (build, run , meta goal, etc)
	SrpmPath     string              // SRPM file used to generate this package (likely shared with multiple other nodes)
	RpmPath      string              // RPM file that produces this package (likely shared with multiple other nodes)
	SpecPath     string              // The SPEC file extracted from the SRPM
	SourceDir    string              // The directory containing extracted sources from the SRPM
	Architecture string              // The architecture of the resulting package built.
	SourceRepo   string              // The location this package was acquired from
	GoalName     string              // Optional string for goal nodes
	Implicit     bool                // If the package is an implicit provide
	This         *PkgNode            // Self reference since the graph library returns nodes by value, not reference
	// contains filtered or unexported fields
}

PkgNode represents a package.

func (*PkgNode) Attributes

func (n *PkgNode) Attributes() []encoding.Attribute

Attributes marshals all relevent node data into a DOT graph structure. The entire node is encoded using base64 and gob.

func (*PkgNode) Copy

func (n *PkgNode) Copy() (copy *PkgNode)

Copy returns a copy of a PkgNode. The ID of the copy is NOT unique.

func (*PkgNode) DOTColor

func (n *PkgNode) DOTColor() string

DOTColor returns the graphviz color to set a node to

func (PkgNode) DOTID

func (n PkgNode) DOTID() string

DOTID generates an id for a DOT graph of the form "pkg(ver:=xyz)<TYPE> (ID=x,STATE=state)""

func (*PkgNode) Equal

func (n *PkgNode) Equal(otherNode *PkgNode) bool

Equal returns true if these nodes represent the same data

func (*PkgNode) FriendlyName

func (n *PkgNode) FriendlyName() string

FriendlyName formats a summary of a node into a string.

func (PkgNode) ID

func (n PkgNode) ID() int64

ID implements the graph.Node interface, returns the node's unique ID

func (PkgNode) MarshalBinary

func (n PkgNode) MarshalBinary() (data []byte, err error)

MarshalBinary implements the GOB encoding interface

func (*PkgNode) SRPMFileName

func (n *PkgNode) SRPMFileName() string

SRPMFileName returns the name of the SRPM file associated with this node. Returns "." if the node doesn't have an SRPM file path or URL.

func (*PkgNode) SetAttribute

func (n *PkgNode) SetAttribute(attr encoding.Attribute) (err error)

SetAttribute sets a DOT attribute for the current node when parsing a DOT file

func (PkgNode) SetDOTID

func (n PkgNode) SetDOTID(id string)

SetDOTID handles parsing the ID of a node from a DOT file

func (*PkgNode) SpecName

func (n *PkgNode) SpecName() string

SpecName returns the name of the spec associated with this node. Returns "." if the node doesn't have a spec file path or URL.

func (*PkgNode) String

func (n *PkgNode) String() string

func (*PkgNode) UnmarshalBinary

func (n *PkgNode) UnmarshalBinary(inBuffer []byte) (err error)

UnmarshalBinary implements the GOB encoding interface

Jump to

Keyboard shortcuts

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