ninjabuild

package
v0.0.0-...-3a98d3a Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: BSD-3-Clause Imports: 30 Imported by: 0

Documentation

Overview

Package ninjabuild provides build steps by ninja.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(ctx context.Context, fname string, buildPath *build.Path) (*ninjautil.State, error)

Load loads build.ninja file specified by fname and returns parsed states.

Types

type Graph

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

Graph holds build graph, i.e. all step defs described in build.ninja.

func NewGraph

func NewGraph(ctx context.Context, fname string, nstate *ninjautil.State, config *buildconfig.Config, p *build.Path, hashFS *hashfs.HashFS, stepConfig *StepConfig, depsLog *ninjautil.DepsLog) *Graph

NewGraph creates new Graph from fname (usually "build.ninja") with stepConfig.

func (*Graph) CleanDead

func (g *Graph) CleanDead(ctx context.Context) (int, int, error)

CleanDead cleans dead generated files, and returns number of removed files and number of last generated files.

func (*Graph) ConfigProperties

func (g *Graph) ConfigProperties() map[string]string

ConfigProperties returns configuration properties.

func (*Graph) Filename

func (g *Graph) Filename() string

Filename returns filename of build manifest (e.g. build.ninja).

func (*Graph) Filenames

func (g *Graph) Filenames() []string

Filenames returns filenames of build manifest (all files loaded by build.ninja).

func (*Graph) InputDeps

func (g *Graph) InputDeps(ctx context.Context) map[string][]string

InputDeps returns input deps.

func (*Graph) NumTargets

func (g *Graph) NumTargets() int

func (*Graph) Reload

func (g *Graph) Reload(ctx context.Context) error

Reload reloads hashfs, filegroups and build.ninja.

func (*Graph) Reset

func (g *Graph) Reset(ctx context.Context) error

Reset resets graph status and hashfs.

func (*Graph) SpellcheckTarget

func (g *Graph) SpellcheckTarget(t string) (string, error)

SpellcheckTarget finds closest target name from t.

func (*Graph) StepDef

func (g *Graph) StepDef(ctx context.Context, target build.Target, next build.StepDef) (build.StepDef, []build.Target, []build.Target, []build.Target, error)

StepDef creates new StepDef to build target (exec-root relative), needed for next. top-level target will use nil for next. It returns a StepDef for the target and inputs/orderOnly/outputs targets.

func (*Graph) StepLimits

func (g *Graph) StepLimits(ctx context.Context) map[string]int

StepLimits returns a map of maximum number of concurrent steps by pool name.

func (*Graph) TargetPath

func (g *Graph) TargetPath(ctx context.Context, target build.Target) (string, error)

TargetPath returns exec-root relative path of the target.

func (*Graph) Targets

func (g *Graph) Targets(ctx context.Context, args ...string) ([]build.Target, error)

Targets returns targets for ninja args. If args is not given, returns default build targets.

func (*Graph) Validations

func (g *Graph) Validations() []build.Target

Validations returns validation targets detected by past StepDef calls.

type IndirectInputs

type IndirectInputs struct {
	// glob pattern to use as action inputs from indirect inputs.
	Includes []string `json:"includes,omitempty"`
}

IndirectInputs specifies what indirect inputs are used as action inputs.

type StepConfig

type StepConfig struct {
	// Properties are config properties.
	// Used for resultstore if enabled.
	Properties map[string]string `json:"properties,omitempty"`

	// Platforms specifies platform properties.
	Platforms map[string]map[string]string `json:"platforms,omitempty"`

	// InputDeps specifies additional input files for a input file.
	// If key contains ":", it is considered as label, and
	// label itself is removed from expanded input list, but
	// label's values are added to expanded input list.
	InputDeps map[string][]string `json:"input_deps,omitempty"`

	// CaseSensitiveInputs lists case sensitive input filenames.
	// use these case sensitive filename. apply only for deps?
	CaseSensitiveInputs []string `json:"case_sensitive_inputs,omitempty"`

	// Rules lists step rules.
	Rules []*StepRule `json:"rules,omitempty"`

	// BadDeps specifies known targets with bad deps,
	// i.e. target has other generated targets not in direct/indirect
	// dependencies in depfile.
	// This target won't cause error with bad deps even with
	// `SISO_EXPERIMENTS=fail-on-bad-deps` to make it easy to
	// detect new bad deps.
	// key is output target known to have bad deps.
	// value is annotation (usually bug link).
	BadDeps map[string]string `json:"bad_deps,omitempty"`

	// Executables are files that need to have executable bit on Linux worker.
	// This field is used to upload Linux executables from Windows host.
	Executables []string `json:"executables,omitempty"`
}

StepConfig is a config for ninja build manifest.

func NewStepConfig

func NewStepConfig(ctx context.Context, config *buildconfig.Config, p *build.Path, hashFS *hashfs.HashFS, fname string) (*StepConfig, error)

NewStepConfig creates new *StepConfig and stores it in .siso_config and .siso_filegroups.

func (StepConfig) ExpandInputs

func (sc StepConfig) ExpandInputs(ctx context.Context, p *build.Path, hashFS *hashfs.HashFS, paths []string) []string

ExpandInputs expands inputs, and returns paths separated by slash.

func (StepConfig) Init

func (sc StepConfig) Init(ctx context.Context) error

Init initializes StepConfig.

func (StepConfig) Lookup

func (sc StepConfig) Lookup(ctx context.Context, bpath *build.Path, edge *ninjautil.Edge) (StepRule, bool)

Lookup returns a step rule for the edge.

func (StepConfig) UpdateFilegroups

func (sc StepConfig) UpdateFilegroups(ctx context.Context, filegroups map[string][]string) error

UpdateFilegroups updates filegroups (input_deps) in the step config.

type StepDef

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

StepDef is a ninja build step definition.

func (*StepDef) ActionName

func (s *StepDef) ActionName() string

ActionName returns action name of the step.

func (*StepDef) Args

func (s *StepDef) Args(ctx context.Context) []string

Args returns command line arguments of the step.

func (*StepDef) Binding

func (s *StepDef) Binding(name string) string

Binding returns a binding of the step.

Ninja bindings are explained in https://ninja-build.org/manual.html#ref_rule:~:text=bindings StepDef may overwrites Ninja bindings. e.g. deps, restat. StepDef also has custom bindings. e.g. remote_wrapper, remote_command.

func (*StepDef) CheckInputDeps

func (s *StepDef) CheckInputDeps(ctx context.Context, depInputs []string) (bool, error)

CheckInputDeps checks dep can be found in its direct/indirect inputs. Returns true if it is unknown bad deps, false otherwise.

func (*StepDef) DepInputs

func (s *StepDef) DepInputs(ctx context.Context) (func(yield func(string) bool), error)

DepInputs returns inputs stored in depfile / depslog.

func (*StepDef) Depfile

func (s *StepDef) Depfile(ctx context.Context) string

Depfile returns exec-root relative depfile path or empty if not set.

func (*StepDef) EnsureRule

func (s *StepDef) EnsureRule(ctx context.Context)

EnsureRule ensures siso rule for StepDef when it needs to run. It may not be called when skipped.

func (StepDef) ExpandedCaseSensitives

func (s StepDef) ExpandedCaseSensitives(ctx context.Context, inputs []string) []string

ExpandedCaseSensitives returns expanded filenames if platform is case-sensitive.

func (*StepDef) ExpandedInputs

func (s *StepDef) ExpandedInputs(ctx context.Context) []string

ExpandedInputs returns expanded inputs

  • Include indirect inputs.
  • Add solibs for input (to execute the executable).
  • Add the inputs from accumulate steps.
  • Replace the inputs from replace steps.
  • Exclude by ExcludeInputPatterns. etc

func (*StepDef) Handle

func (s *StepDef) Handle(ctx context.Context, cmd *execute.Cmd) error

Handle runs a handler for the cmd.

func (*StepDef) Inputs

func (s *StepDef) Inputs(ctx context.Context) []string

Inputs returns inputs of the step.

func (*StepDef) IsPhony

func (s *StepDef) IsPhony() bool

IsPhony returns whether the step if phony or not.

func (*StepDef) LocalOutputs

func (s *StepDef) LocalOutputs(ctx context.Context) []string

LocalOutputs returns outputs of the step that should be written to local disk.

func (*StepDef) Next

func (s *StepDef) Next() build.StepDef

Next returns next step def.

func (*StepDef) Outputs

func (s *StepDef) Outputs(ctx context.Context) []string

Outputs returns outputs of the step.

func (*StepDef) Platform

func (s *StepDef) Platform() map[string]string

Platform returns platform properties for remote execution.

func (*StepDef) Pure

func (s *StepDef) Pure() bool

Pure checks if the step is pure or not.

func (*StepDef) REProxyConfig

func (s *StepDef) REProxyConfig() *execute.REProxyConfig

REProxyConfig returns configuration options for using reproxy.

func (*StepDef) RecordDeps

func (s *StepDef) RecordDeps(ctx context.Context, output string, t time.Time, deps []string) (bool, error)

RecordDeps records deps of the step.

func (*StepDef) RemoteInputs

func (s *StepDef) RemoteInputs() map[string]string

RemoteInputs returns remote input mappings.

func (*StepDef) Rspfile

func (s *StepDef) Rspfile(ctx context.Context) string

Rspfile returns exec-root relative rspfile path or empty if not set.

func (*StepDef) RuleFix

func (s *StepDef) RuleFix(ctx context.Context, inadds, outadds []string) []byte

RuleFix shows suggested fix for the rule.

func (*StepDef) RuleName

func (s *StepDef) RuleName() string

RuleName returns rule name of the step.

func (*StepDef) String

func (s *StepDef) String() string

String returns step id.

func (*StepDef) ToolInputs

func (s *StepDef) ToolInputs(ctx context.Context) []string

ToolInputs returns tool inputs of the step.

func (*StepDef) TriggerInputs

func (s *StepDef) TriggerInputs(ctx context.Context) []string

TriggerInputs returns inputs of the step that would trigger the step's action.

type StepDeps

type StepDeps struct {
	Inputs      []string          `json:"inputs,omitempty"`
	Outputs     []string          `json:"outputs,omitempty"`
	Platform    map[string]string `json:"platform,omitempty"`
	PlatformRef string            `json:"platform_ref,omitempty"`
}

StepDeps is a dependency of a step.

type StepRule

type StepRule struct {

	// Name is a step rule label. required.
	// must be unique to identify the step rule to make it easy
	// to maintain rules.
	Name string `json:"name"`

	// ActionName is a regexp to match with rule name.
	ActionName string `json:"action,omitempty"`

	// ActionOuts matches  with outputs of the step.
	ActionOuts []string `json:"action_outs,omitempty"`

	// CommandPreifx matches with command prefix of the step.
	// If argv[0] is absolute path outside of execroot,
	// it is compared with basename of argv[0].
	// Note: it doesn't support space in argv[0] for such case.
	CommandPrefix string `json:"command_prefix,omitempty"`

	// Inputs are inputs to add to the step.
	Inputs []string `json:"inputs,omitempty"`

	// ExcludeInputPatterns are path glob patterns to exclude from the expanded inputs.
	ExcludeInputPatterns []string `json:"exclude_input_patterns,omitempty"`

	// IndirectInputs enables indirect (transitive, recursive) inputs
	// as action input of the step.
	IndirectInputs *IndirectInputs `json:"indirect_inputs,omitempty"`

	// Outputs are outputs to add to the step.
	Outputs []string `json:"outputs,omitempty"`
	// OutputsMap is a map to fix inputs/outputs per outputs.
	OutputsMap map[string]StepDeps `json:"outputs_map,omitempty"`

	// Restat means the step command will read its output
	// and may not write output when no update needed.
	// Output will be considered as clean if output mtime
	// is not changed by the command execution.
	// https://ninja-build.org/manual.html#ref_rule:~:text=appears%20in%20commands.-,restat,-if%20present%2C%20causes
	Restat bool `json:"restat,omitempty"`

	// RestatContent means output will be considered as clean
	// if output content is the same as before.
	RestatContent bool `json:"restat_content,omitempty"`

	// PlatformRef is reference to platform properties.
	PlatformRef string `json:"platform_ref,omitempty"`
	// Platform is platform properties.
	// TODO: siso: prefix will not send to remote backend.
	Platform map[string]string `json:"platform,omitempty"`

	// Remote marks the step is remote executable.
	Remote bool `json:"remote,omitempty"`
	// RemoteWrapper is a wrapper used in remote execution.
	// TODO: put RemoteWrapper in Platform["siso:remote_wrapper"]
	RemoteWrapper string `json:"remote_wrapper,omitempty"`
	// RemoteCommand is a command used in the first argument.
	RemoteCommand string `json:"remote_command,omitempty"`
	// RemoteInputs is a map for remote execution.
	// path in remote action -> local path
	RemoteInputs map[string]string `json:"remote_inputs,omitempty"`
	// InputRootAbsolutePath indicates the step requires absolute path for the input root, i.e. not relocatable.
	InputRootAbsolutePath bool `json:"input_root_absolute_path,omitempty"`
	// CanonicalizeDir indicates the step can canonicalize the working dir.
	CanonicalizeDir bool `json:"canonicalize_dir,omitempty"`

	// UseSystemInput indicates to allow extra inputs outside exec root.
	UseSystemInput bool `json:"use_system_input,omitempty"`

	// UseRemoteExecWrapper indicates the command uses remote exec wrapper
	// (e.g. gomacc, rewrapper), so
	// - no need to run `clang -M`
	// - run locally but more parallelism
	// - no file access trace
	UseRemoteExecWrapper bool `json:"use_remote_exec_wrapper,omitempty"`
	// REProxyConfig specifies configuration options for using reproxy.
	REProxyConfig *execute.REProxyConfig `json:"reproxy_config,omitempty"`

	// Timeout specifies time duration for the remote execution call of the step.
	// Timeout*2 will be set to remote action's timeout to
	// expect cache hit for long command execution.
	Timeout string `json:"timeout,omitempty"` // duration format

	// Handler name.
	Handler string `json:"handler,omitempty"`

	// Deps specifies deps type.
	//
	//   deps="gcc": Use `gcc -M` or deps log.
	//   deps="msvc": Use `clang-cl /showIncludes` or deps log.
	//   deps="depfile": Use `depfile` if `depfile` is specified.
	//   deps="none": ignore deps of the step.
	Deps string `json:"deps,omitempty"`

	// NoFastDeps disables fast-deps.
	NoFastDeps bool `json:"no_fast_deps,omitempty"`

	// OutputLocal indicates to force to write output files to local disk
	// for subsequent steps.
	// TODO: better to have `require_local_inputs`=[<globs>] to reduce unnecessary downloads?
	OutputLocal bool `json:"output_local,omitempty"`

	// IgnoreExtraInputPattern specifies regexp to ignore extra inputs.
	// ignore extra input detected by strace if it matches with this pattern
	// e.g. cache file
	IgnoreExtraInputPattern string `json:"ignore_extra_input_pattern,omitempty"`

	// IgnoreExtraOutputPattern specifies regexp to ignore extra outputs.
	// ignore extra output detected by strace if it matches with this pattern
	// e.g. cache file
	IgnoreExtraOutputPattern string `json:"ignore_extra_output_pattern,omitempty"`

	// Impure marks the step is impure, i.e. allow extra inputs/outputs.
	// Better to use above options if possible.
	// Impure disables file access trace.
	Impure bool `json:"impure,omitempty"`

	// Replace replaces the outputs, when used by other step,
	// to the inputs of the step.
	// e.g. stamp.
	Replace bool `json:"replace,omitempty"`

	// Accumulate accumulates the inputs of the step to
	// the outputs, when used by other step.
	// e.g. thin archive.
	Accumulate bool `json:"accumulate,omitempty"`

	// Debug indicates to log debug information for the step.
	Debug bool `json:"debug,omitempty"`
	// contains filtered or unexported fields
}

StepRule is a rule for step.

func (*StepRule) Init

func (r *StepRule) Init() error

Init initializes the step rule.

Jump to

Keyboard shortcuts

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