Documentation
¶
Overview ¶
Package depsource builds an sbom.Inventory from a project's dependency files. Lockfiles the resolver supports become a dependency graph (pkg/dependencies/resolve/lockfile), with dev members left out; manifests no lockfile covers are parsed flat (pkg/dependencies), as a list of declared packages with no edges. It is the dependency counterpart of scansource, and the only SBOM code that depends on the dependency parsers.
Index ¶
- func Graph(g resolve.Graph) sbom.Inventory
- func Inventory(ctx context.Context, root string, files []string, opts Options) (sbom.Inventory, map[string]error)
- func Manifests(parsed *parsers.LocalDependencies, root string) sbom.Inventory
- func Resolve(ctx context.Context, root, rel string, o Options) (resolve.Graph, error)
- func Select(files []string) []string
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Graph ¶
Graph projects a resolved graph into an inventory: one declared component per member of each root that is not dev, and one DependencyRoot per root. A node shared by several roots is one component carrying one evidence per root, "declared" where that root's manifest declares it and "transitive" where its lockfile pulls it in. Dev members never appear, and neither does an edge that touches one, so a root's edges only ever join components that are in the inventory. An unknown root is kept, with no members and no edges, so the output says the lockfile was there and could not be read.
func Inventory ¶
func Inventory(ctx context.Context, root string, files []string, opts Options) (sbom.Inventory, map[string]error)
Inventory reads the dependency files of the project at root. Each supported lockfile is resolved into a graph and the graphs are merged; every root covers its manifest and its lockfile, so neither is parsed flat again. An unknown root covers them too: it says the lockfile was there and could not be read, and a flat parse would bring back the range entries and dev dependencies the graph exists to replace. Every other selected manifest is parsed flat.
failed is keyed by path and holds the lockfiles that could not be read and the manifests that could not be parsed. It is nil when nothing failed. Unknown roots are not failures: they are reported on the root itself.
func Manifests ¶
func Manifests(parsed *parsers.LocalDependencies, root string) sbom.Inventory
Manifests builds declared components from flat-parsed manifests, with no round trip to any service: each PURL is split into its base and version (the manifest's requirement when the PURL carries none), tagged declared, and given the manifest as evidence, relative to root in slash form so it matches a root's manifest path. Exact duplicates fold into one component with one evidence per manifest; distinct versions of a package are kept, including a declared range (package.json "^1.5.5") alongside its resolved pin (package-lock.json "1.14.3").
func Resolve ¶ added in v0.18.0
Resolve builds the graph of the manifest or lockfile rel, a slash path under root. An enabled toolchain runs first; when it leaves a root unknown (tool missing, failed or timed out) its graph is dropped with a warning and the lockfile parser answers instead, as without the toolchain. A manifest only the toolchain resolves then yields an empty graph, which leaves it to the flat parser.
Types ¶
type Options ¶ added in v0.18.0
type Options struct {
// Toolchain holds the base names of the manifests ("go.mod", "pom.xml") resolved by running the
// ecosystem's own tools instead of reading a lockfile, when the toolchain package supports them.
Toolchain map[string]bool
// ToolchainOptions configures those tool runs: timeout, environment and limits.
ToolchainOptions toolchain.Options
}
Options chooses how manifests are resolved. The zero value reads lockfiles only.
func (Options) Resolvable ¶ added in v0.18.0
Resolvable reports whether Resolve builds a graph for file: a lockfile the resolver supports, or a manifest the toolchain is enabled for.