build

package
v0.0.4-d-oss Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package build schedules and executes the build steps in a Ninja graph, tracking per-step state and delegating command execution and on-disk effects to a pluggable BuildBackend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildBackend

type BuildBackend interface {
	BuildInit(engine *Engine) error
	IsClean(step *Step) (bool, error)
	ApplyIfCached(step *Step) (bool, error)
	IsRemotable(step *Step) bool
	ExecRemote(ctx context.Context, step *Step) ExecResult
	CreateDirs(step *Step) error
	CreateRSP(step *Step) error
	ExecLocal(ctx context.Context, step *Step) ExecResult
	FinalizeStep(step *Step)
	FinalizeBuild(err error) error
}

BuildBackend is implemented by execution backends used by the build engine.

type BuildState

type BuildState int

BuildState identifies a step's position in the build state machine.

const (
	StateInit BuildState = iota
	StateBlocked
	StateCleanCheck
	StateClean
	StateCacheCheck
	StateCached
	StateRemoteQueued
	StateRemoteRunning
	StateLocalQueued
	StateLocalRunning
	StateFailed
	StateDone
	MaxState
)

BuildState values, in roughly the order steps move through them.

func (BuildState) IsFinal

func (s BuildState) IsFinal() bool

IsFinal reports whether s is a terminal state.

func (BuildState) IsSuccess

func (s BuildState) IsSuccess() bool

IsSuccess reports whether s is a terminal state that indicates success.

func (BuildState) String

func (s BuildState) String() string

String returns a human-readable name for s.

type Engine

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

Engine drives the build: it owns the build state machine, dispatches work to schedulers, and invokes the backend for clean checks, cache lookups, and command execution.

func NewEngine

func NewEngine(ctx context.Context, graph *graph.Graph) *Engine

NewEngine constructs an Engine for graph using the backend and parameters stored on ctx.

func (*Engine) Build

func (e *Engine) Build(ctx context.Context) error

Build runs the configured backend and engine to completion, returning a non-nil error if any step failed.

func (*Engine) Pools

func (e *Engine) Pools() map[string]*ninja.Pool

Pools returns all build pools, including the implicit "default" pool sized according to the configured concurrency level.

func (*Engine) StateCounts

func (e *Engine) StateCounts() map[BuildState]int64

StateCounts returns a snapshot of the number of steps in each BuildState.

type ExecResult

type ExecResult struct {
	Err      error
	ExitCode int
	Stdout   string
	Stderr   string
}

ExecResult holds the outcome of running a build step.

type ExecutionCallback

type ExecutionCallback func(s *Step)

ExecutionCallback is invoked by the scheduler to run a step.

type Pressure

type Pressure struct {
	Some PressureItem
	Full PressureItem
}

Pressure holds the "some" and "full" lines reported by /proc/pressure/*.

type PressureItem

type PressureItem struct {
	Avg10  float64
	Avg60  float64
	Avg300 float64
	Total  int64
}

PressureItem holds the four values reported on each line of a PSI file.

type SchedMonitor

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

SchedMonitor watches Linux pressure-stall information (PSI) and pauses scheduling when CPU, IO, or memory pressure exceeds the configured limits.

func (*SchedMonitor) MayI

func (m *SchedMonitor) MayI() bool

MayI blocks while any monitored resource is above its configured threshold, returning true once it is safe to schedule a new job.

type Scheduler

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

Scheduler dispatches ready steps to a fixed pool of worker goroutines.

func NewScheduler

func NewScheduler(pool *ninja.Pool, maxCount int, callback ExecutionCallback, monitor *SchedMonitor) *Scheduler

NewScheduler returns a Scheduler bound to pool, sized for at most maxCount queued steps and using callback to execute them.

func (*Scheduler) Pool

func (s *Scheduler) Pool() *ninja.Pool

Pool returns the ninja pool that backs this scheduler.

func (*Scheduler) Start

func (s *Scheduler) Start()

Start launches the dispatch and worker goroutines.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop closes the input channel and blocks until all worker goroutines exit.

type Step

type Step struct {
	ID int

	// Node is the graph node that this step is associated with.
	Node *graph.Node

	// Pool is the scheduler that owns this step once it has been queued locally.
	Pool *Scheduler
	// contains filtered or unexported fields
}

Step represents the build information for a given node.

func NewStep

func NewStep(node *graph.Node) *Step

NewStep returns a Step in StateInit for the given graph node.

func (*Step) ClearCommand

func (s *Step) ClearCommand()

ClearCommand discards the command and response-file fields so they can be garbage collected after execution.

func (*Step) CmdHash

func (s *Step) CmdHash() uint64

CmdHash returns the hash of the command and response-file contents. It panics if no command is loaded.

func (*Step) Command

func (s *Step) Command() string

Command returns the expanded command. It panics if no command is loaded.

func (*Step) IsCommandLoaded

func (s *Step) IsCommandLoaded() bool

IsCommandLoaded reports whether LoadCommand has been called and ClearCommand has not.

func (*Step) IsConsole

func (s *Step) IsConsole() bool

IsConsole reports whether s is in the console pool.

func (*Step) IsGenerator

func (s *Step) IsGenerator() bool

IsGenerator reports whether s sets the generator attribute.

func (*Step) IsPhony

func (s *Step) IsPhony() bool

IsPhony reports whether s wraps a phony build edge.

func (*Step) IsPhonyOutput

func (s *Step) IsPhonyOutput() bool

IsPhonyOutput reports whether s declares phony_output.

func (*Step) LoadCommand

func (s *Step) LoadCommand()

LoadCommand expands the command, response file, and command hash and stores them on s in preparation for execution.

func (*Step) RSPContent

func (s *Step) RSPContent() string

RSPContent returns the response-file contents, if any. It panics if no command is loaded.

func (*Step) RSPFile

func (s *Step) RSPFile() string

RSPFile returns the path of the response file, if any. It panics if no command is loaded.

func (*Step) Restat

func (s *Step) Restat() bool

Restat reports whether s sets the restat attribute.

func (*Step) String

func (s *Step) String() string

String returns a human-readable identifier for s.

Jump to

Keyboard shortcuts

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