mock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The name of the host user group that the calling user must be a member of to run "mock".
	MockGroup = "mock"
	// The name of the mock executable.
	MockBinary = "mock"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildLogDetails

type BuildLogDetails struct {
	// RPMBuildErrors is a list of error messages extracted from mock build logs.
	RPMBuildErrors []string

	// LastRPMBuildLogLines is a list of the last lines of the mock build log, which may contain
	// relevant context about why a build failure occurred.
	LastRPMBuildLogLines []string
}

BuildLogDetails encapsulates details extracted from mock build logs that may be relevant to understanding the cause of a build failure.

type CommonBuildOptions

type CommonBuildOptions struct {
	With    []string
	Without []string
	Defines map[string]string

	LocalRepoPaths []string
}

CommonBuildOptions encapsulates options that are shared between SRPM and RPM builds.

type RPMBuildOptions

type RPMBuildOptions struct {
	CommonBuildOptions

	// Binary RPM specific options
	NoCheck      bool
	ForceRebuild bool
}

RPMBuildOptions encapsulates options for building binary RPMs using mock.

type Runner

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

Encapsulates options for invoking mock.

func NewRunner

func NewRunner(ctx opctx.Ctx, mockConfigPath string) *Runner

Constructs a new Runner that can be used to invoke mock.

func (*Runner) AddBindMount

func (r *Runner) AddBindMount(hostPath, mockRootPath string) *Runner

Updates the Runner's configuration to add a bind mount, exposing the host directory at path `hostPath` in the mock root at path `mockRootPath`.

func (*Runner) BaseDir

func (r *Runner) BaseDir() string

BaseDir retrieves the path to the base directory used by this Runner for mock roots.

func (*Runner) BindMounts

func (r *Runner) BindMounts() map[string]string

BindMounts retrieves the set of bind mounts configured for this Runner, expressed as a map from host path to mock root path.

func (*Runner) BuildRPM

func (r *Runner) BuildRPM(ctx context.Context, srpmPath, outputDirPath string, options RPMBuildOptions) error

Given a path to a Source RPM (SRPM), invokes mock to build a binary RPM.

func (*Runner) BuildSRPM

func (r *Runner) BuildSRPM(
	ctx context.Context, specPath, sourceDirPath, outputDirPath string, options SRPMBuildOptions,
) error

Builds a Source RPM (SRPM) using mock.

func (*Runner) Clone

func (r *Runner) Clone() *Runner

Clone creates a deep copy of the provided Runner instance.

func (*Runner) CmdInChroot

func (r *Runner) CmdInChroot(ctx context.Context, args []string, interactive bool) (cmd opctx.Cmd, err error)

Builds a wrapper command that will run the specified inside a mock chroot.

func (*Runner) ConfigOpts

func (r *Runner) ConfigOpts() map[string]string

ConfigOpts retrieves the set of arbitrary config options configured for this Runner.

func (*Runner) ConfigPath

func (r *Runner) ConfigPath() string

Retrieves the path to the mock .cfg file used by this Runner.

func (*Runner) EnableNetwork

func (r *Runner) EnableNetwork() *Runner

Updates the Runner's configuration to enable external network access from within the mock root.

func (*Runner) GetRootPath

func (r *Runner) GetRootPath(ctx context.Context) (string, error)

Retrieves the path to the mock root used by this Runner.

func (*Runner) HasNetworkEnabled

func (r *Runner) HasNetworkEnabled() bool

HasNetworkEnabled indicates whether the Runner is configured to enable network access.

func (*Runner) HasNoPreClean

func (r *Runner) HasNoPreClean() bool

HasNoPreClean indicates whether the Runner is configured to avoid pre-cleaning the root.

func (*Runner) InitRoot

func (r *Runner) InitRoot(ctx context.Context) (err error)

InitRoot initializes a mock root.

func (*Runner) InstallPackages

func (r *Runner) InstallPackages(ctx context.Context, packages []string) error

InstallPackages installs the specified packages into the mock root.

func (*Runner) RootDir

func (r *Runner) RootDir() string

RootDir retrieves the path to the mock root used by this Runner.

func (*Runner) ScrubRoot

func (r *Runner) ScrubRoot(ctx context.Context) error

ScrubRoot removes the mock root.

func (*Runner) TryGetFailureDetails

func (r *Runner) TryGetFailureDetails(fs opctx.FS, outputDirPath string) (details *BuildLogDetails)

TryGetFailureDetails makes a best-effort attempt to extract details from mock build logs that may be relevant to understanding the cause of a build failure. This is intended to be called after a build failure to glean any insights we can from mock's logs about why the failure might have occurred.

func (*Runner) WithBaseDir

func (r *Runner) WithBaseDir(baseDir string) *Runner

WithBaseDir updates the Runner's configuration to set which directory mock roots are created under by default. If not set, mock will write under its default base (/var/lib/mock).

func (*Runner) WithConfigOpts

func (r *Runner) WithConfigOpts(opts map[string]string) *Runner

WithConfigOpts updates the Runner's configuration to set arbitrary config options that will be passed through to mock as --config-opts key=value arguments.

func (*Runner) WithNoPreClean

func (r *Runner) WithNoPreClean() *Runner

WithNoPreClean updates the Runner's configuration to ensure that mock does *not* pre-clean the root when invoking an operation.

func (*Runner) WithRootDir

func (r *Runner) WithRootDir(rootDir string) *Runner

WithRootDir update's the Runner's configuration to set which directory the root is created under.

type SRPMBuildOptions

type SRPMBuildOptions struct {
	CommonBuildOptions
}

SRPMBuildOptions encapsulates options for building source RPMs using mock.

Jump to

Keyboard shortcuts

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