Documentation ¶
Index ¶
- Variables
- func GetAllHashes(primary, verification Config) (crt.FileSetHashes, error)
- type Build
- func New(name string, cfg Config, options ...Option) (Build, error)
- func NewLocalVerification(primaryRoot string, startAfter time.Time, cfg Config, options ...Option) (Build, error)
- func NewPrimary(cfg Config, opts ...Option) (Build, error)
- func NewRemoteBuild(c Config, options ...Option) (Build, error)
- type BuildPathsOpt
- type Config
- func (c Config) BuildResultCachePath(verification bool) string
- func (c Config) ChangeRoot(dir string) (Config, error)
- func (c Config) ChangeToRemotePrimaryRoot() (Config, error)
- func (c Config) ChangeToVerificationRoot() (Config, error)
- func (c Config) ID() string
- func (c Config) RemotePrimaryRoot() string
- func (c Config) VerificationRoot() string
- type DirNames
- type EnvVar
- type Inputs
- type LocalVerification
- func (b LocalVerification) CachedResult() (Result, bool, error)
- func (b LocalVerification) ChangeRoot(dir string) error
- func (b LocalVerification) ChangeToPrimaryRoot() error
- func (b LocalVerification) ChangeToVerificationRoot() error
- func (b LocalVerification) Config() Config
- func (b LocalVerification) Dirs() TempDirs
- func (b LocalVerification) Env() []string
- func (b LocalVerification) IsVerification() bool
- func (lv *LocalVerification) Kind() string
- func (lv *LocalVerification) Steps() []Step
- func (b LocalVerification) UpdateBuildRoot() error
- type Manager
- type Meta
- type Option
- func AsPrimaryBuild() Option
- func AsVerificationBuild() Option
- func WithCleanOnly(on bool) Option
- func WithContext(c context.Context) Option
- func WithDebugfunc(f func(string, ...any)) Option
- func WithForceRebuild(on bool) Option
- func WithForceVerification(on bool) Option
- func WithLogPrefix(p string) Option
- func WithLogfunc(f func(string, ...any)) Option
- func WithLoudfunc(f func(string, ...any)) Option
- func WithStderr(w io.Writer) Option
- func WithStdout(w io.Writer) Option
- type Parameters
- type Paths
- type Primary
- func (b Primary) CachedResult() (Result, bool, error)
- func (b Primary) ChangeRoot(dir string) error
- func (b Primary) ChangeToPrimaryRoot() error
- func (b Primary) ChangeToVerificationRoot() error
- func (b Primary) Config() Config
- func (b Primary) Dirs() TempDirs
- func (b Primary) Env() []string
- func (b Primary) IsVerification() bool
- func (p *Primary) Kind() string
- func (b Primary) Steps() []Step
- func (b Primary) UpdateBuildRoot() error
- type RemoteBuild
- func (b RemoteBuild) CachedResult() (Result, bool, error)
- func (b RemoteBuild) ChangeRoot(dir string) error
- func (b RemoteBuild) ChangeToPrimaryRoot() error
- func (b RemoteBuild) ChangeToVerificationRoot() error
- func (b RemoteBuild) Config() Config
- func (b RemoteBuild) Dirs() TempDirs
- func (b RemoteBuild) Env() []string
- func (b RemoteBuild) IsVerification() bool
- func (rb *RemoteBuild) Steps() []Step
- func (b RemoteBuild) UpdateBuildRoot() error
- type Result
- type ResultSource
- type Runner
- type Settings
- type Step
- type StepFunc
- type TempDirs
- type VerificationResult
- type Verifier
Constants ¶
This section is empty.
Variables ¶
var CacheKeyFunc = digest.CompoundID
CacheKeyFunc can be overridden by tests to generate stable strings.
var ConfigIDFunc = func(c Config) string { return digest.ID(c) }
ConfigIDFunc can be overridden in tests to generate stable config IDs.
var Dirs = DirNames{"dist", "out", "meta"}
var TempDirFunc = os.TempDir
TempDirFunc is the function used by this package to get the system temp dir. You can override this for testing purposes to get platform-independent paths.
Functions ¶
func GetAllHashes ¶
func GetAllHashes(primary, verification Config) (crt.FileSetHashes, error)
Types ¶
type Build ¶
type Build interface { Env() []string Config() Config CachedResult() (Result, bool, error) Steps() []Step ChangeRoot(string) error ChangeToVerificationRoot() error IsVerification() bool Dirs() TempDirs }
Build represents the build of a single binary. It could be a primary build or a verification build, this Build doesn't need to know.
func NewLocalVerification ¶
type BuildPathsOpt ¶ added in v0.1.8
type BuildPathsOpt func(s *pathsSettings)
func WithTargetDir ¶ added in v0.1.8
func WithTargetDir(path string) BuildPathsOpt
type Config ¶
type Config struct { // Product is the logical product being built. Product crt.Product // BuildParameters are the invariant build parameters that must be used // in order to reproduce the build. Parameters Parameters // Paths are local to a build on a specific machine. Paths Paths // Tool is info about the tool that created this build.Config. Tool crt.Tool // Reproducible tells us whether the build is expected to be reproducible. // This is used by downstream processes. Reproducible bool }
Config contains the complete configuration to build a single binary on a specific host.
func NewConfig ¶
func NewConfig(product crt.Product, params Parameters, paths Paths, creator crt.Tool, reproducible bool) (Config, error)
NewConfig expects product, params, and paths to be fully initialized.
func (Config) BuildResultCachePath ¶
func (Config) ChangeRoot ¶
ChangeRoot returns a copy of this Config with an updated build root.
func (Config) ChangeToRemotePrimaryRoot ¶
func (Config) ChangeToVerificationRoot ¶
func (Config) RemotePrimaryRoot ¶
func (Config) VerificationRoot ¶
type EnvVar ¶
type EnvVar struct {
Name, Description string
// contains filtered or unexported fields
}
envVar represents a documented environment variable alongside a function showing how it is extracted from Config.
func BuildEnvDefinitions ¶
func BuildEnvDefinitions() []EnvVar
BuildEnvDefinitions returns the set of env vars guaranteed to be available to the build instructions, alongside a description of each one.
func BuildSpecificBuildEnvDefinitions ¶
func BuildSpecificBuildEnvDefinitions() []EnvVar
BuildSpecificBuildEnvDefinitions are environment variables that are expected to be different between different runs without affecting the built artifacts.
func InvariantBuildEnvDefinitions ¶
func InvariantBuildEnvDefinitions() []EnvVar
InvariantBuildEnvDefinitions are environment variables that should be set exactly the same for both primary build and all verification builds. Changes to these variables could change the artifacts produced.
type Inputs ¶
type Inputs struct { Product crt.Product Parameters Parameters }
Inputs represents the fixed inuputs to the build. These are identical for both the primary and verification build.
type LocalVerification ¶
type LocalVerification struct {
// contains filtered or unexported fields
}
LocalVerification is the local verification build. It is run inside a temporary copy of the primary build's root directory.
func (LocalVerification) CachedResult ¶
func (LocalVerification) ChangeRoot ¶
func (LocalVerification) ChangeToPrimaryRoot ¶
func (b LocalVerification) ChangeToPrimaryRoot() error
func (LocalVerification) ChangeToVerificationRoot ¶
func (b LocalVerification) ChangeToVerificationRoot() error
func (LocalVerification) Env ¶
func (b LocalVerification) Env() []string
Env materialises the values for each defined env var as a slice compatible with exec.CMD.Env.
func (LocalVerification) IsVerification ¶
func (b LocalVerification) IsVerification() bool
func (*LocalVerification) Kind ¶
func (lv *LocalVerification) Kind() string
func (*LocalVerification) Steps ¶
func (lv *LocalVerification) Steps() []Step
func (LocalVerification) UpdateBuildRoot ¶
func (b LocalVerification) UpdateBuildRoot() error
UpdateBuildRoot updates the build root for this build depending whether it's a primary or verification build.
type Manager ¶
type Manager struct { Settings // contains filtered or unexported fields }
Manager is responsible for orchestrating the running of builds. By default it will return cached build results rather then re-running a build that's already been done.
func (*Manager) Result ¶
Result returns the build result either from cache if present and not forcing a rebuild, or by running the build to generate a new result. The only errors that can be returned are from the attempt to load from cache, so to check if the build failed or not you still need to call the Result's Error method.
type Meta ¶
Meta captures after-the-fact information about the build. This will be different between primary and verification builds.
type Option ¶
type Option func(*Settings)
Option represents a function that configures Settings.
func AsPrimaryBuild ¶
func AsPrimaryBuild() Option
AsPrimaryBuild forces a build to be treated as a primary build (i.e. run in the current directory, or primary root (for remote builds).
func AsVerificationBuild ¶
func AsVerificationBuild() Option
AsVerificationBuild forces a build to be treated as a verification build (i.e. run in the verification root, and cached separately from primary builds).
func WithCleanOnly ¶
WithCleanOnly causes the build to fail early if it's not based on a clean worktree.
func WithContext ¶
WithContext sets the context passed when we shell out.
func WithDebugfunc ¶
WithDebugfunc sest the debug func.
func WithForceRebuild ¶
WithForceRebuild forces a build to be re-done rather than using cache.
func WithForceVerification ¶
WithForceVerification forces a build to be a verification build (or not depending on the boolean passed).
func WithLoudfunc ¶
WithDebugfunc sest the debug func.
func WithStderr ¶
WithStderr sets the stderr for when we shell out.
func WithStdout ¶
WithStdout sets the stdout for when we shell out.
type Parameters ¶
type Parameters struct { // GoVersion is the version of the Go toolchain to run thid build with. GoVersion string `env:"GO_VERSION"` // Instructions are the build instructions (a bash script). Instructions string `env:"INSTRUCTIONS"` // OS is the target OS for this build. OS string `env:"OS"` // Arch is the target Architecture for this build. Arch string `env:"ARCH"` // ZipName is the name of the zip file to create. ZipName string `env:"ZIP_NAME"` }
Parameters are the set of build inputs that should be enough (along with the Product) to reproduce a build. Changes to these should result in different build outputs.
func (Parameters) Init ¶
func (bp Parameters) Init(p crt.Product) (Parameters, error)
type Paths ¶
type Paths struct { // WorkDir is the absolute directory to run the build instructions in. WorkDir string // BinPath is the absolute path to the executable binary the instructions // must create. BinPath string // ZipPath is the path to the zip file that will be created. ZipPath string // MetaDir is where we write metadata about this build. MetaDir string }
Paths are host-specific absolute paths to various things. We need to be aware of these paths in order to be able to do comparisons between primary and verification builds. They must not affect the bytes produced.
func NewBuildPaths ¶
func NewBuildPaths(root, executableName, zipName string, opts ...BuildPathsOpt) (Paths, error)
type Primary ¶
type Primary struct {
// contains filtered or unexported fields
}
Primary is the primary build. This is run in the current working directory, using whatever files are present.
func (Primary) CachedResult ¶
func (Primary) ChangeRoot ¶
func (Primary) ChangeToPrimaryRoot ¶
func (b Primary) ChangeToPrimaryRoot() error
func (Primary) ChangeToVerificationRoot ¶
func (b Primary) ChangeToVerificationRoot() error
func (Primary) Env ¶
func (b Primary) Env() []string
Env materialises the values for each defined env var as a slice compatible with exec.CMD.Env.
func (Primary) IsVerification ¶
func (b Primary) IsVerification() bool
func (Primary) UpdateBuildRoot ¶
func (b Primary) UpdateBuildRoot() error
UpdateBuildRoot updates the build root for this build depending whether it's a primary or verification build.
type RemoteBuild ¶
type RemoteBuild struct {
// contains filtered or unexported fields
}
RemoteBuild is a build where the source code is hosted remotely. This can be a "primary" or verification build.
func (RemoteBuild) CachedResult ¶
func (RemoteBuild) ChangeRoot ¶
func (RemoteBuild) ChangeToPrimaryRoot ¶
func (b RemoteBuild) ChangeToPrimaryRoot() error
func (RemoteBuild) ChangeToVerificationRoot ¶
func (b RemoteBuild) ChangeToVerificationRoot() error
func (RemoteBuild) Env ¶
func (b RemoteBuild) Env() []string
Env materialises the values for each defined env var as a slice compatible with exec.CMD.Env.
func (RemoteBuild) IsVerification ¶
func (b RemoteBuild) IsVerification() bool
func (*RemoteBuild) Steps ¶
func (rb *RemoteBuild) Steps() []Step
func (RemoteBuild) UpdateBuildRoot ¶
func (b RemoteBuild) UpdateBuildRoot() error
UpdateBuildRoot updates the build root for this build depending whether it's a primary or verification build.
type Result ¶
type Result struct { Config Config Env []string Meta Meta Zip crt.File Executable crt.File ErrorMessage string `json:",omitempty"` Successful bool // contains filtered or unexported fields }
Result captures a single binary build. It's used for both primary and verification builds. Note that the Config will be different for each of them because it contains build-host-specific paths.
func (Result) IsFromCache ¶
type ResultSource ¶
type Runner ¶
type Runner struct { Settings // contains filtered or unexported fields }
Runner is responsible for executing and logging build steps and constructing the build Result.
type Settings ¶
type Settings struct { Log func(string, ...any) Debug func(string, ...any) Loud func(string, ...any) // contains filtered or unexported fields }
Settings contains settings for running builds. These are not to be confused with build.Config, these settings are build-run specific and not part of the _definition_ of the build. Don't use this directly, use the With... functions to set settings when calling New.
type TempDirs ¶
type TempDirs struct {
// contains filtered or unexported fields
}
func NewPrimaryDirs ¶
func NewTempDirs ¶
func NewVerificationDirs ¶
func (TempDirs) BuildResultCacheDir ¶
func (TempDirs) RemoteBuildRoot ¶
func (TempDirs) SourceDownloadDir ¶
func (TempDirs) VerificationResultCachePath ¶
type VerificationResult ¶
type VerificationResult struct { Primary *Result Verification *Result Hashes crt.FileSetHashes ErrorMessage string `json:",omitempty"` Dirty bool ReproducedCorrectly bool }
VerificationResult captures the result of a primary and local verification build together with easy-access hashes and an overall "reproduced correctly" boolean.
func (*VerificationResult) Error ¶
func (vr *VerificationResult) Error() error
func (*VerificationResult) IsFromCache ¶
func (vr *VerificationResult) IsFromCache() bool
type Verifier ¶
type Verifier struct { Settings // contains filtered or unexported fields }
func NewVerifier ¶
func NewVerifier(primary, verification ResultSource, opts ...Option) (*Verifier, error)
func (*Verifier) Verify ¶
func (v *Verifier) Verify() (*VerificationResult, error)
Verify returns a VerificationResult which may or may not be affirmative. It returns an error when issues occur discovering that result, not when the result itself says that the reproduction didn't work. You still need to query the result to find out if it was successful.