sources

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: 41 Imported by: 0

Documentation

Index

Constants

View Source
const MacrosFileExtension = ".azl.macros"

MacrosFileExtension is the file extension used for azldev-generated macros files.

View Source
const MacrosFileHeader = `# Macros file automatically generated by azldev.
# Do not edit manually; changes will be overwritten.`

MacrosFileHeader is the comment header included at the top of generated macros files.

Variables

View Source
var ErrOverlayDidNotApply = errors.New("overlay did not apply to target")

Error to return when an overlay did not apply to its target (e.g., a search-and-replace overlay that found no matches).

Functions

func ApplyOverlayToSources

func ApplyOverlayToSources(
	dryRunnable opctx.DryRunnable,
	fs opctx.FS,
	overlay projectconfig.ComponentOverlay,
	sourcesDirPath, specPath string,
) error

ApplyOverlayToSources applies the provided overlay to the specified spec and related sources. Files are mutated in-place. If an error occurs mid-way through applying multiple overlays, previously applied changes will remain. Callers should consider working on copies of source files if atomicity is required.

func ApplySpecOverlay

func ApplySpecOverlay(overlay projectconfig.ComponentOverlay, openedSpec *spec.Spec) error

ApplySpecOverlay applies a spec-based overlay to an opened spec. An error is returned if a non-spec overlay is provided.

func ApplySpecOverlayToFileInPlace

func ApplySpecOverlayToFileInPlace(fs opctx.FS, overlay projectconfig.ComponentOverlay, specPath string) error

ApplySpecOverlayToFileInPlace applies the given overlay to the specified spec file. Changes are made in-place.

func BumpStaticRelease added in v0.2.0

func BumpStaticRelease(releaseValue string, commitCount int) (string, error)

BumpStaticRelease increments the leading integer in a static Release tag value by the given commit count.

func CommitInterleavedHistory added in v0.2.0

func CommitInterleavedHistory(
	repo *gogit.Repository,
	changes []FingerprintChange,
	importCommit string,
) error

CommitInterleavedHistory rebuilds the dist-git history by interleaving synthetic commits with the existing upstream commits. Synthetic commits referencing an older upstream commit are placed directly after that commit; those referencing the latest upstream commit are appended on top. The very last synthetic commit carries the overlay file changes; all others are empty.

When importCommit is non-empty, only upstream commits from importCommit onward are considered for interleaving.

func GenerateMacrosFileContents

func GenerateMacrosFileContents(buildConfig projectconfig.ComponentBuildConfig) string

GenerateMacrosFileContents generates the contents of an RPM macros file from the given build configuration. The output uses standard RPM macro file format (%name value) and includes a header comment identifying the file as auto-generated.

With flags are converted to %_with_FLAG 1 macros. Without flags are converted to %_without_FLAG 1 macros. Defines are emitted as %name value macros.

All macros are collected into a single map and sorted alphabetically by name for deterministic output. If the same macro is defined multiple times (e.g., via both a with flag and an explicit define), the later definition wins. The order of processing is: with flags, then without flags, then explicit defines, then undefines.

Undefines remove entries from the generated macros map. This only affects macros that originate from the merged TOML configuration (with, without, and defines fields); it does not undefine arbitrary system-level RPM macros. The primary use case is allowing a component-level TOML file to override a distro-level or project-level default by removing a macro that would otherwise be emitted into the macros file.

Note: RPM macro values can contain spaces without special escaping; everything after the macro name (and separating whitespace) is treated as the macro body.

If no macros remain after processing (empty config, or all macros removed via undefines), an empty string is returned to signal that no macros file is needed.

func GetReleaseTagValue added in v0.2.0

func GetReleaseTagValue(fs opctx.FS, specPath string) (string, error)

GetReleaseTagValue reads the Release tag value from the spec file at specPath. It returns the raw value string as written in the spec (e.g. "1%{?dist}" or "%autorelease"). Returns spec.ErrNoSuchTag if no Release tag is found.

func ReleaseUsesAutorelease added in v0.2.0

func ReleaseUsesAutorelease(releaseValue string) bool

ReleaseUsesAutorelease reports whether the given Release tag value uses the %autorelease macro (either bare or braced form).

Types

type CommitMetadata added in v0.2.0

type CommitMetadata struct {
	Hash        string
	Author      string
	AuthorEmail string
	Timestamp   int64
	Message     string
}

CommitMetadata holds full metadata for a commit in the project repository.

func ParseCommitMetadata added in v0.2.0

func ParseCommitMetadata(output string) (CommitMetadata, error)

ParseCommitMetadata parses a single NUL-delimited commit record produced by 'git log --format=%H%x00%an%x00%ae%x00%at%x00%s'.

type ComponentInput added in v0.2.0

type ComponentInput struct {
	Name         string // Component name (matches subdirectory in staging dir)
	SpecFilename string // Just the filename, e.g., "curl.spec"
}

ComponentInput describes a single component to process in the mock chroot. Name must match the subdirectory name under the staging directory.

type ComponentMockResult added in v0.2.0

type ComponentMockResult struct {
	Name      string   // Component name
	SpecFiles []string // Files listed by spectool (basenames/relative paths)
	Error     error    // Non-nil if rpmautospec or spectool failed for this component
}

ComponentMockResult holds the mock processing result for one component.

type FingerprintChange added in v0.2.0

type FingerprintChange struct {
	CommitMetadata

	// UpstreamCommit is the upstream dist-git commit hash recorded in the lock
	// file at the time the fingerprint changed.
	UpstreamCommit string
}

FingerprintChange records a project commit that changed a component's lock file fingerprint. [UpstreamCommit] is the value of the 'upstream-commit' field in the lock file at the point of the change.

func BuildDirtyChange added in v0.2.0

func BuildDirtyChange(
	currentFingerprint string,
	headLock *lockfile.ComponentLock,
	currentUpstreamCommit string,
) *FingerprintChange

BuildDirtyChange returns a FingerprintChange representing uncommitted config/overlay changes. Returns nil when currentFingerprint is empty or matches the HEAD lock file's fingerprint.

currentUpstreamCommit is the effective upstream commit from the on-disk (possibly uncommitted) lock file. This is used instead of [headLock.UpstreamCommit] so that upstream commit changes from 'component update' (written to disk but not yet committed) are reflected in the dirty entry.

func FindFingerprintChanges added in v0.2.0

func FindFingerprintChanges(
	ctx context.Context,
	cmdFactory opctx.CmdFactory,
	projectRepo *gogit.Repository,
	projectRepoDir string,
	lockFileRelPath string,
) ([]FingerprintChange, error)

FindFingerprintChanges walks the git log of the project repository for commits that changed the given lock file and returns metadata for each commit where the 'input-fingerprint' field changed. Results are sorted chronologically (oldest first).

type MockProcessor added in v0.2.0

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

MockProcessor provides a shared mock chroot for running rpmautospec and spectool during component rendering. The chroot is lazily initialized on first use and supports batch processing of multiple components in a single mock invocation.

func NewMockProcessor added in v0.2.0

func NewMockProcessor(ctx opctx.Ctx, mockConfigPath string) *MockProcessor

NewMockProcessor creates a new processor that will lazily initialize a mock chroot using the given config path. The runner is created eagerly but the chroot is only initialized on first use.

func (*MockProcessor) BatchProcess added in v0.2.0

func (p *MockProcessor) BatchProcess(
	ctx context.Context, events opctx.EventListener,
	stagingDir string, inputs []ComponentInput, fs opctx.FS, maxWorkers int,
) ([]ComponentMockResult, error)

BatchProcess runs rpmautospec and spectool for multiple components in a single mock chroot invocation. stagingDir is the host directory containing one subdirectory per component (named by ComponentInput.Name). A single bind mount exposes the entire staging tree to the chroot.

Components are processed in parallel inside the chroot by an embedded Python script (render_process.py) which returns a JSON file, and reports per-component progress on stderr (mapped by mock to stdout).

func (*MockProcessor) Destroy added in v0.2.0

func (p *MockProcessor) Destroy(ctx context.Context)

Destroy cleans up the mock chroot. Should be called when rendering is complete. The processor must not be reused after Destroy — create a new MockProcessor if needed. Attempts cleanup even if initialization partially failed (e.g., InitRoot succeeded but InstallPackages failed), since a partially initialized chroot still needs scrubbing.

type PreparerOption added in v0.2.0

type PreparerOption func(*sourcePreparerImpl)

PreparerOption is a functional option for configuring a SourcePreparer.

func WithAllowNoHashes added in v0.2.0

func WithAllowNoHashes() PreparerOption

WithAllowNoHashes returns a PreparerOption that allows source file references to omit their projectconfig.SourceFileReference.Hash value. When set, any source file that lacks a hash will have its hash computed from the already-downloaded file in the output directory. If projectconfig.SourceFileReference.HashType is also missing, SHA-512 is used as the default. A warning is emitted for each file whose hash is auto-computed.

When combined with WithSkipLookaside, source file downloads are skipped, so files needed for hash computation are not available on disk. In that case, missing hashes cannot be auto-computed and source preparation returns an error.

func WithDirtyDetection added in v0.2.0

func WithDirtyDetection() PreparerOption

WithDirtyDetection returns a PreparerOption that enables uncommitted-change detection during synthetic history generation. When set, the current input fingerprint is compared against the committed lock file; if they differ, a "dirty" synthetic commit is appended to represent the uncommitted changes. Without this option, only committed fingerprint changes produce synthetic commits.

This should be enabled for commands that operate on the working tree state (build, render, prepare-sources) and left disabled for commands that should only reflect committed state.

func WithGitRepo added in v0.2.0

func WithGitRepo(
	cmdFactory opctx.CmdFactory,
	lockReader lockfile.LockReader,
	releaseVer string,
) PreparerOption

WithGitRepo returns a PreparerOption that enables dist-git repository creation during source preparation. When set, the upstream .git directory is preserved and synthetic commit history is generated on top of it. This requires the project configuration to reside inside a git repository. Without this option, no dist-git is created and synthetic history is skipped.

The cmdFactory is used to shell out to git for fingerprint change detection. The lockReader provides access to per-component lock files and their directory. The releaseVer must be the per-component resolved distro release version (e.g., "4.0"), not the project default — components may override the distro via projectconfig.SpecSource.UpstreamDistro.

func WithSkipLookaside added in v0.2.0

func WithSkipLookaside() PreparerOption

WithSkipLookaside returns a PreparerOption that skips all lookaside cache downloads during source preparation. This includes both explicit source file downloads ([SourceManager.FetchFiles]) and lookaside extraction during component fetching ([FedoraSourceDownloader.ExtractSourcesFromRepo]). Git-tracked files (spec, patches, scripts, configs) are still fetched from the upstream clone. This is useful for rendering, where only the spec and sidecar files are needed and downloading large source tarballs is unnecessary.

type SourcePreparer

type SourcePreparer interface {
	// PrepareSources prepares the input sources for the given component, writing them to the given output directory.
	// After this function completes successfully, the output directory should contain all files required to build
	// the component, with any post-processing applied as necessary. The only remaining dependencies not contained
	// within the output directory will be build-time dependencies on external packages (RPMs), including those
	// relied on to be present implicitly within the build root, or expressed via BuildRequires or DynamicBuildRequires
	// in the component's spec file and any defaults from the macros used to interpret the spec file.
	PrepareSources(ctx context.Context, component components.Component, outputDir string, applyOverlays bool) error

	// DiffSources computes a unified diff showing the changes that overlays apply to a component's sources.
	// The component's sources are fetched once into a subdirectory of baseDir, then copied to a second
	// subdirectory where overlays are applied in-place. The diff between the two subdirectories is returned.
	DiffSources(ctx context.Context, component components.Component, baseDir string) (*dirdiff.DiffResult, error)
}

SourcePreparer is a utility for acquiring and preparing all input files required to build a component. This may include the component's spec file, any loose files that must accompany it, any payload source archives and patches required by the spec, etc. Preparation may also include any post-processing of these inputs to match the component's configuration within the containing project.

func NewPreparer

func NewPreparer(
	sourceManager sourceproviders.SourceManager,
	fs opctx.FS,
	eventListener opctx.EventListener,
	dryRunnable opctx.DryRunnable,
	opts ...PreparerOption,
) (SourcePreparer, error)

NewPreparer creates a new SourcePreparer instance. All positional arguments are required. Optional behavior can be configured via PreparerOption values.

Jump to

Keyboard shortcuts

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