ninjautil

package
v0.0.0-...-7220889 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: 23 Imported by: 0

Documentation

Overview

Package ninjautil provides utilitites for ninja.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDepsLog = errors.New("deps not found")

Functions

func OpenNinjaLog

func OpenNinjaLog(ctx context.Context) (*os.File, error)

OpenNinjaLog opens ninja log file or creates a new file with a version header.

func WriteNinjaLogEntries

func WriteNinjaLogEntries(ctx context.Context, w io.Writer, start, end int64, mtime time.Time, outputs, command []string)

WriteNinjaLogEntries writes ninja log entries for a command. Note that the log entries are not compatible with Ninja, yet. TODO: b/298594790

  • Implement MurmurHash64A as Ninja.
  • Make mtime compatible on Windows.

Types

type DepsLog

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

DepsLog is an in-memory representation of ninja's depslog. It supports creating new depslog files and reading existing depslog files, as well as adding new records to open depslog files. Format: https://github.com/ninja-build/ninja/blob/87111bff382655075f2577c591745a335f0103c7/src/deps_log.h

func NewDepsLog

func NewDepsLog(ctx context.Context, fname string) (*DepsLog, error)

NewDepsLog reads or creates a new deps log. If there are read errors, returns a truncated deps log.

func (*DepsLog) Close

func (d *DepsLog) Close() error

Close closes the deps log.

func (*DepsLog) Get

func (d *DepsLog) Get(ctx context.Context, output string) ([]string, time.Time, error)

Get returns deps log for the output.

func (*DepsLog) NeedsRecompact

func (d *DepsLog) NeedsRecompact() bool

NeedsRecompact reports whether it needs recompact or not.

func (*DepsLog) Recompact

func (d *DepsLog) Recompact(ctx context.Context) error

Recompact recompacts deps log file, i.e. rewrites the known log entries, throwing away old data.

func (*DepsLog) Record

func (d *DepsLog) Record(ctx context.Context, output string, mtime time.Time, deps []string) (bool, error)

Record records deps log for the output. This will write to disk. Returns whether any deps were updated.

func (*DepsLog) RecordedTargets

func (d *DepsLog) RecordedTargets() []string

RecordedTargets returns a list of targets that have deps log.

func (*DepsLog) Reset

func (d *DepsLog) Reset()

Reset resets deps log, so recorded entries is available for Get.

type Edge

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

Edge represents an edge (action) in build graph. TODO(b/267409605): Add tests for Edge methods.

func (*Edge) Binding

func (e *Edge) Binding(name string) string

Binding returns binding value in the edge.

func (*Edge) BindingBool

func (e *Edge) BindingBool(name string) bool

BindingBool returns true if binding is defined in the edge.

func (*Edge) Inputs

func (e *Edge) Inputs() []*Node

Inputs returns input nodes of the edge.

func (*Edge) Ins

func (e *Edge) Ins() []*Node

Ins returns explicit input nodes (for $in) of the edge.

func (*Edge) IsPhony

func (e *Edge) IsPhony() bool

IsPhony returns true iff phony edge.

func (*Edge) Outputs

func (e *Edge) Outputs() []*Node

Outputs returns output nodes of the edge.

func (*Edge) Pool

func (e *Edge) Pool() *Pool

Pool returns a pool associated to the edge.

func (*Edge) Print

func (e *Edge) Print(w io.Writer)

Print writes edge information in writer. TODO: add test for print.

func (*Edge) RawBinding

func (e *Edge) RawBinding(name string) string

RawBinding returns raw eval string of binding value in the edge.

func (*Edge) RuleName

func (e *Edge) RuleName() string

RuleName returns a rule name used by the edge.

func (*Edge) TriggerInputs

func (e *Edge) TriggerInputs() []*Node

TriggerInputs returns inputs nodes of the edge that would trigger the edge command. i.e. not including order_only inputs.

func (*Edge) UnescapedBinding

func (e *Edge) UnescapedBinding(name string) string

UnescapedBinding returns binding value without shell escape.

func (*Edge) Validations

func (e *Edge) Validations() []*Node

Validations returns validations node of the edge.

type ManifestParser

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

ManifestParser parses Ninja manifests. (i.e. .ninja files)

func NewManifestParser

func NewManifestParser(state *State) *ManifestParser

NewManifestParser creates a new manifest parser.

func (*ManifestParser) Load

func (p *ManifestParser) Load(ctx context.Context, fname string) error

Load loads the Ninja manifest given an fname.

func (*ManifestParser) SetWd

func (p *ManifestParser) SetWd(wd string)

SetWd sets working directory to use for loading files.

type Node

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

Node represents a node (target file) in build graph.

func (*Node) ID

func (n *Node) ID() int

func (*Node) InEdge

func (n *Node) InEdge() (*Edge, bool)

InEdge returns in-edge of the node.

func (*Node) OutEdges

func (n *Node) OutEdges() []*Edge

OutEdges returns out-edges of the node.

func (*Node) Path

func (n *Node) Path() string

Path is the path of the node.

func (*Node) String

func (n *Node) String() string

type Pool

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

A Pool limits the number of concurrently running actions.

func (*Pool) Depth

func (p *Pool) Depth() int

Depth returns the depth of the pool.

func (*Pool) Name

func (p *Pool) Name() string

Name returns the pool name.

type State

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

State contains all information in a scope about Ninja primitives relevant during execution time, such as pools, edges (= actions) and variable bindings.

func NewState

func NewState() *State

NewState creates new state.

func (*State) AddBinding

func (s *State) AddBinding(name, value string)

AddBinding adds bindings.

func (*State) AllNodes

func (s *State) AllNodes() []*Node

AllNodes returns all nodes.

func (*State) DefaultNodes

func (s *State) DefaultNodes() ([]*Node, error)

DefaultNodes returns default nodes.

func (*State) Filenames

func (s *State) Filenames() []string

Filenames returns files parsed by the parser (e.g. build.ninja and its subninja etc.)

func (*State) LookupNode

func (s *State) LookupNode(id int) (*Node, bool)

LookupNode returns a node.

func (*State) LookupNodeByPath

func (s *State) LookupNodeByPath(path string) (*Node, bool)

LookupNodeByPath returns a node.

func (*State) LookupPool

func (s *State) LookupPool(poolName string) (*Pool, bool)

LookupPool looks up pool.

func (*State) NumNodes

func (s *State) NumNodes() int

NumNodes returns a number of nodes.

func (*State) PhonyNodes

func (s *State) PhonyNodes() []*Node

PhonyNodes returns phony's output nodes.

func (*State) Pools

func (s *State) Pools() map[string]*Pool

Pools returns a map of pools

func (*State) RootNodes

func (s *State) RootNodes() ([]*Node, error)

RootNodes returns root nodes, that are nodes without output actions. (Hence can be considered final artifacts, i.e. other nodes will not use root nodes as inputs.)

func (*State) SpellcheckTarget

func (s *State) SpellcheckTarget(t string) (string, error)

SpellcheckTarget returns the most similar target from given target.

func (*State) Targets

func (s *State) Targets(args []string) ([]*Node, error)

Targets returns target nodes for given args. If args is empty, returns default nodes. If arg has ^-suffix, it is treated as source of target. e.g. "foo.cc^" will be "foo.o", which is generated from foo.cc

Jump to

Keyboard shortcuts

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