components

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package components provides abstractions and utilities for representing, querying, and managing software components within an Azure Linux project. We define a software component as being a buildable entity that may produce zero, one, or multiple packages when built.

Responsibilities

This package is responsible for:

  • Defining types and interfaces for component metadata, configuration, and relationships.
  • Providing logic to enumerate and filter on collections of components within the environment.
  • Integrating with the broader azldev environment (azldev.Env) and project configuration (projectconfig.ComponentConfig) to ensure context-sensitive component handling.

Usage Context

This package is used by command implementations and automation logic that need to operate on sets of components, determine their properties, or perform actions such as builds, checks, or queries.

Index

Constants

This section is empty.

Variables

View Source
var ErrComponentGroupNotFound = errors.New("component group not found")

Well-known errors.

Functions

func AddComponentFilterOptionsToCommand

func AddComponentFilterOptionsToCommand(cmd *cobra.Command, filter *ComponentFilter)

Adds to the given command a standardized set of command options for selecting components from the loaded configuration. This allows consistency across the commands that operate on components in some form. Those commands that only support operating on a fixed number of components (say, 1) can further extend the logic by adding their own checks.

func BuildUpstreamCommitResolutionInputs added in v0.2.0

func BuildUpstreamCommitResolutionInputs(
	env *azldev.Env, config *projectconfig.ComponentConfig,
) (fingerprint.UpstreamCommitResolutionInputs, error)

BuildUpstreamCommitResolutionInputs resolves the effective distro for a component and builds fingerprint.UpstreamCommitResolutionInputs for resolution hash computation. Uses the resolved (inherited) config values — not raw spec fields — so that default-distro and distro-version-level snapshots are captured.

func FindAllSpecPaths

func FindAllSpecPaths(env *azldev.Env) ([]string, error)

Collects file paths to all .spec files known about in this environment.

func GenerateComponentGroupNameCompletions

func GenerateComponentGroupNameCompletions(
	cmd *cobra.Command, args []string, toComplete string,
) (completions []string, directive cobra.ShellCompDirective)

Function suitable for use as a cobra.ValidArgsFunction in a cobra.Command. Intended for use in generating completions for commands that take component group names as positional arguments.

func GenerateComponentNameCompletions

func GenerateComponentNameCompletions(
	cmd *cobra.Command, args []string, toComplete string,
) (completions []string, directive cobra.ShellCompDirective)

Function suitable for use as a cobra.ValidArgsFunction in a cobra.Command. Intended for use in generating completions for commands that take component names as positional arguments.

func RenderedSpecDir added in v0.2.0

func RenderedSpecDir(renderedSpecsDir, componentName string) (string, error)

RenderedSpecDir returns the rendered spec output directory for a given component. Components are organized by the lowercase first letter of their name: {renderedSpecsDir}/{letter}/{componentName} (e.g., "SPECS/c/curl"). Returns an empty string if renderedSpecsDir is not configured (empty). Returns an error if componentName is unsafe (absolute, contains path separators or traversal sequences).

func RenderedSpecDirAliasName added in v0.2.0

func RenderedSpecDirAliasName(componentName string) string

RenderedSpecDirAliasName returns the URL-encoded form of componentName intended for use as a sibling alias (typically a symlink) alongside the real rendered directory. This is a temporary compatibility shim — see the workaround block in `RenderComponents` for the full rationale and TODO link. It is NOT part of the canonical rendered-spec directory contract and should be removed once the downstream build system decodes SCM URL fragments correctly.

Encoder choice: url.QueryEscape is used deliberately, in conscious divergence from the url.PathEscape convention elsewhere in this codebase (e.g. fedorasource). Of the two stdlib encoders, only QueryEscape escapes '+' as '%2B', and '+' is the only RPM-name character that triggers the downstream path mismatch we need to bridge (PathEscape would emit a literal '+', the alias name would equal the real name, and no symlink would be written). Component names with '%' literal are assumed not to occur (RPM convention); no real-world packages exercise this case.

Returns "" when no alias is needed (the encoded form equals componentName).

Types

type Component

type Component interface {
	// GetName returns the name of the component.
	GetName() string
	// GetConfig returns the static configuration for the component.
	GetConfig() *projectconfig.ComponentConfig
	// GetSpec returns an abstract object that represents the specification for building the component.
	GetSpec() specs.ComponentSpec
	// GetDetails inspects the component and retrieves more detailed information; non-trivial
	// computation may be required to collect these details.
	GetDetails() (info *ComponentDetails, err error)
}

Component provides abstract access to a *software component*; software components are buildable entities that can be used in a project, and which typically produce 1 or more packages when built.

type ComponentDetails

type ComponentDetails struct {
	// We embed the details retrieved from the component's spec as well.
	specs.ComponentSpecDetails

	// Config holds the static configuration for the component, including its name.
	Config projectconfig.ComponentConfig
}

ComponentDetails encapsulates detailed information about a component, including both configuration information as well as detailed information that may be computationally intensive to collect. This information can be separately retrieved from the Component but this type provides a convenient data-oriented structure to encapsulate all details about a component in one place.

type ComponentFilter

type ComponentFilter struct {
	// Exact names to match against component groups. Does not support patterns or wildcards.
	ComponentGroupNames []string
	// Patterns to match against components; if no wildcards are present in the patterns, then an exact match
	// is required, otherwise lack of matches is still success.
	ComponentNamePatterns []string
	// Paths to individual spec files. Does not support patterns or wild-carding.
	SpecPaths []string
	// If true, then *all* known components are included in the result set.
	IncludeAllComponents bool
	// SkipLockValidation disables lock file consistency checks for this
	// filter's resolution. Commands that write lock files (update) or are
	// read-only (list) set this to true.
	SkipLockValidation bool
}

Describes a filter that selects a subset of components known within the environment's loaded configuration.

func (ComponentFilter) HasNoCriteria

func (f ComponentFilter) HasNoCriteria() bool

HasNoCriteria returns true if the filter has no criteria set, meaning that it will never match any components.

type ComponentGroup

type ComponentGroup struct {
	// The group's name.
	Name string
	// A list of the group's members.
	Components []ComponentGroupMember
}

ComponentGroup defines a component group. Component groups are used to group components, and optionally apply shared configuration or policy to them.

type ComponentGroupMember

type ComponentGroupMember struct {
	// Name of the component.
	ComponentName string
	// Path to the component's spec (optional).
	SpecPath string
}

ComponentGroupMember defines a member of a ComponentGroup.

type ComponentSet

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

Represents a unique logical set of components. Maintains insertion order.

func NewComponentSet

func NewComponentSet() *ComponentSet

Constructs an empty ComponentSet.

func (*ComponentSet) Add

func (cs *ComponentSet) Add(component Component)

Adds `component` to the component set, associating it with `name`. If a component with the same name is already present, it's replaced with `component`. Insertion order is maintained for stable enumeration.

func (*ComponentSet) Components

func (cs *ComponentSet) Components() []Component

Retrieves the components in the set, in original insertion order.

func (*ComponentSet) Contains

func (cs *ComponentSet) Contains(name string) bool

Checks if a component called `name` is present in the set.

func (*ComponentSet) Len

func (cs *ComponentSet) Len() int

Returns the number of unique components in the set.

func (*ComponentSet) Names

func (cs *ComponentSet) Names() []string

Retrieves the names of the components in the set, in original insertion order.

func (*ComponentSet) TryGet

func (cs *ComponentSet) TryGet(name string) (Component, bool)

Tries to retrieve the named component. If found, returns it; returns a clear indication of whether the component was present.

type Resolver

type Resolver struct {

	// SuppressLockWarnings disables advisory warnings emitted during lock
	// population (e.g., staleness warning when config pin differs from locked
	// commit). Set this for commands that are about to refresh the lock
	// themselves (e.g., 'component update') to avoid noise telling the user
	// to do what they're already doing.
	SuppressLockWarnings bool
	// CheckFreshness enables fingerprint-based freshness computation during
	// component resolution. When true, each component's
	// [projectconfig.ComponentLockData.Freshness] is set based on comparing
	// stored hashes to recomputed ones. When false (default), freshness
	// remains [projectconfig.FreshnessUnknown].
	//
	// Off by default because most commands (build, render, prepare-sources)
	// consume locked state as-is and don't need to know whether it's stale.
	// Only 'component update' enables this — it uses the freshness status to
	// decide which components need re-resolution and which can be skipped.
	CheckFreshness bool
	// contains filtered or unexported fields
}

Resolver is a utility for resolving components in an environment.

func NewResolver

func NewResolver(env *azldev.Env) *Resolver

NewResolver constructs a new Resolver for the given environment.

func (*Resolver) FindAllComponents

func (r *Resolver) FindAllComponents() (components *ComponentSet, err error)

Finds *all* components defined in the environment.

func (*Resolver) FindComponents

func (r *Resolver) FindComponents(filter *ComponentFilter) (components *ComponentSet, err error)

Given a component filter, finds all components defined in the environment that match the filter.

func (*Resolver) FindComponentsByNamePattern

func (r *Resolver) FindComponentsByNamePattern(pattern string) (components *ComponentSet, err error)

Finds all components in the environment whose names match the given glob pattern.

func (*Resolver) GetComponentByName

func (r *Resolver) GetComponentByName(name string) (component Component, err error)

Finds the component with the given name defined in the provided environment. Returns error if it can't be found.

func (*Resolver) GetComponentGroupByName

func (r *Resolver) GetComponentGroupByName(componentGroupName string) (componentGroup *ComponentGroup, err error)

Looks up the named component group in the provided environment. Returns error if it can't be found.

Directories

Path Synopsis
Package components_testutils is a generated GoMock package.
Package components_testutils is a generated GoMock package.

Jump to

Keyboard shortcuts

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