moonja

    A Ninja-compatible build tool in MoonBit, verified against ninja 1.13.2

    ninja
    build
    build-system
    cli
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    2 hours ago
    Downloads
    3

    No dependencies

    #moonja

    CI

    A drop-in replacement for Ninja 1.13.2, written in MoonBit. It is verified by porting ninja's own unit tests and by differential testing against the real ninja binary.

    用 MoonBit 实现、可直接替换 Ninja 的构建工具。兼容目标固定为 ninja v1.13.2,验证手段有两条:

    1. 把 ninja 自带的 C++ 单元测试逐个移植成 MoonBit 测试。
    2. 在同一份 build.ninja 上同时运行真实 ninja 和 moonja,要求 stdout、stderr、退出码、产出文件和 .ninja_log 逐字节一致。

    $ moon build --target js --release $ node _build/js/release/build/cmd/cmd.js -C path/to/project [1/3] CC foo.o [2/3] CC bar.o [3/3] LINK app

    需要 Node.js 22.3 或更新版本。核心库不依赖任何 I/O,在 js、wasm-gc、native 三个后端上都通过全部测试。

    #支持什么

    • 清单语言:变量与作用域、rule/build/pool/default、include/subninja、$ 转义、ninja_required_version、phony、隐式与 order-only 依赖、隐式输出、validation(|@)。
    • 增量构建:mtime 比较、命令哈希(rapidhash,与 ninja 的 .ninja_log v7 互通)、restat、generator、清单自重建(最多 100 轮)。
    • 依赖发现:depfile、deps = gcc / deps = msvc 写入 .ninja_deps v4 二进制日志、dyndep 文件。
    • 调度:-j 并行、-k 容错、-l 负载限制、pool 与 console pool、关键路径优先。
    • 输出:$NINJA_STATUS 全部占位符(含 ETA 预测)、智能终端单行刷新与中间省略、失败报告、颜色剥离、-v、--quiet、-d explain。
    • 命令行:-C -f -j -k -l -n -v -d -t -w --version --quiet。参数解析模拟 glibc getopt_long(Linux)和 ninja 自带的 getopt(Windows),报错文本也一致。
    • 子工具:clean(-g -r)、cleandead、commands、inputs、multi-inputs、deps、missingdeps、graph、query、targets、compdb(-x)、compdb-targets、recompact、restat、rules、urtle、wincodepage。
    • 平台细节:
      • mtime 单位与 ninja 相同:POSIX 下是纳秒,Windows 下是以 2000 年为纪元的 FILETIME 刻度。因此 moonja 和 ninja 可以共用同一个构建目录。
      • POSIX 下用 /bin/sh -c 运行命令,非 console 命令放进独立进程组。
      • Windows 下按 CreateProcess 规则解析命令行。ninja 自己的输出走文本模式 CRLF,命令输出原样透传,与 ninja 的 #773 修复一致。
      • 命令退出码原样透传为 moonja 的退出码,中断时为 130。

    #怎么验证的

    #1. 移植 ninja 自己的测试(全部通过)

    ninja 测试文件用例moonja 测试文件
    lexer_test.cc7lexer_test.mbt
    manifest_parser_test.cc53manifest_parser_test.mbt
    depfile_parser_test.cc29depfile_parser_test.mbt
    graph_test.cc51graph_test.mbt
    build_log_test.cc11build_log_test.mbt
    deps_log_test.cc9deps_log_test.mbt
    dyndep_parser_test.cc42dyndep_parser_test.mbt(34 个测试块)
    build_test.cc118plan_test.mbt build_test.mbt build_with_log_test.mbt deps_build_test.mbt dyndep_build_test.mbt
    clean_test.cc19clean_test.mbt
    missing_deps_test.cc / json_test.cc7 + 4missing_deps_test.mbt
    edit_distance_test.cc4edit_distance_test.mbt
    clparser_test.cc / includes_normalize_test.cc8 + 6clparser_test.mbt(Windows 用例注入工作目录,在任何平台上都能运行)
    elide_middle_test.cc / util_test.cc(StripAnsi)3 + 2status_test.mbt
    rapidhash341 个哈希向量rapidhash_vectors_test.mbt(向量取自真实 ninja 写出的 .ninja_log)

    测试名与原版保持一致(如 BuildTest.StatusFormatETA),便于对照。我也做过变异检验:故意改坏实现,确认相应测试会失败。

    #2. 与真实 ninja 做差分测试

    scripts/difftest.mjs 会把 tests/diff/ 下的每个用例复制成两份,让 ninja 1.13.2 和 moonja 交替执行同一组步骤(run、touch、write、rm),然后比较:

    • 每一次运行的 stdout、stderr、退出码;
    • 全部步骤结束后的整个文件树内容;
    • .ninja_log 中每条记录的输出路径和命令哈希。

    目前有 16 个用例、162 次运行:基本构建与增量、失败与 -k、depfile/deps 日志、restat、清单自重建、phony/order-only/validation、rspfile、dyndep、作用域与转义、25 种错误信息、pool 与 console、-C,以及全部子工具在构建前后的输出。CI 在 Linux(ubuntu-latest)和 Windows(windows-latest)上,以 pip install ninja==1.13.2 作为参照运行全部用例,两个平台都逐字节一致。

    $ moon build --target js $ node scripts/difftest.mjs --ninja "$(which ninja)" ok basic (7 runs) ... 16/16 cases identical, 162 runs compared

    差分测试找到并修复了不少单元测试没有覆盖到的问题,例如:
    • 退出码是原样透传,不是固定的 0/1/2。
    • 成功构建后要删除 .ninja_lock(ninja 在 Builder 析构时清理)。
    • ninja_required_version 过新时应输出 fatal 而不是 error。
    • Windows 上读文件出错时用的是 FormatMessage 文本,并且自带 CRLF。
    • Windows 版 getopt 会把未知长选项当作短选项解析。

    我还验证过框架本身:把 no work to do. 改掉一个字符,差分测试会立刻报告。

    #性能

    scripts/bench.mjs 仿照 ninja 的 misc/write_fake_manifests.py 生成工程:1 万个带 gcc deps 的目标文件,分布在 200 个目录中,再链接成库和可执行文件,共 10201 条边,清单 1 MiB。先用 ninja 完整构建一次,再分别计时,每项取 5 次的中位数:

    场景ninja 1.13.2moonja(Node 25)倍数
    只解析清单(-t targets all)42 ms213 ms5.0x
    全部最新的空构建114 ms679 ms5.9x
    从零开始的空跑(-n)1207 ms2197 ms1.8x

    测试环境:Windows 11,i7-10750H。如何解读这些数字:
    • Node 启动本身就要约 80 ms。
    • 空构建中约 250 ms 花在逐个文件的 stat 上。ninja 在 Windows 上用 FindFirstFileEx 按目录批量取 mtime,Node 没有对应的接口,单次 stat 约 11 µs。Linux 上 stat 便宜得多,差距会小很多。
    • 剖析中发现并修掉了两处热点:rapidhash 在 JS 后端逐字节拼 64 位整数(每个字要做 16 次 BigInt 运算),以及每行输出一次系统调用。

    #架构

    moonja(核心库,纯 MoonBit,无 I/O) lexer / manifest_parser / eval_env 清单语言 graph / state / scan 依赖图、脏检查(DependencyScan) build Plan + Builder(可恢复的状态机) build_log / deps_log / dyndep 持久化格式 clean / missing_deps / status ... 子工具与输出 moonja/cli(ninja.cc 的主流程,纯 MoonBit) flags / ninja / runner / tools 参数、构建循环、子工具;系统能力通过 Host 注入 moonja/cmd(Node.js 宿主) fs / child_process / 终端 唯一和操作系统打交道的地方

    几个关键设计:
    • Builder 是可恢复的状态机:start_build → command_finished(每个命令结束时调用一次)。同步宿主可以直接调用 build;Node 宿主在 child_process 的回调里推进构建,不需要线程。
    • 平台是运行时的值:Platform::{Posix, Windows},不是条件编译。路径规范化(slash_bits)、转义、错误文本都按这个值分支,所以 Windows 行为在任何后端上都能测试。
    • I/O 全部经由 trait 注入:Disk、FileReader、Terminal、Processes。单元测试用内存文件系统 MemoryDisk 和假的 Runner;差分测试才使用真实的系统。

    #作为库使用

    let state = @moonja.State::new()
    let parser = @moonja.ManifestParser::without_files(state)
    parser.parse_test("rule cc\n command = cc $in -o $out\nbuild a.o: cc a.c\n")
    for edge in state.edges() {
    println(edge.evaluate_command()) // cc a.c -o a.o
    }

    #与 ninja 的已知差异

    • -t browse 和 -t msvc 不支持(前者需要 Python,后者是已弃用的 Windows 辅助工具)。
    • -d stats 可以接受,但不输出统计信息;没有实现 GNU make jobserver 客户端。
    • 清单按 UTF-8 解码,非 UTF-8 字节会被替换。
    • -t cleandead -v 的删除顺序,以及 "did you mean" 在多个候选距离相同时选哪一个:ninja 这两处取决于哈希表的遍历顺序,moonja 按插入顺序。

    #许可证与来源

    Apache-2.0。核心算法和测试移植自 ninja v1.13.2(Apache-2.0)。项目结构参考了 n2。详见 NOTICE。

    CommandRunner

    pub(open) trait CommandRunner {
    fn can_run_more(Self) -> Int
    fn start_command(Self, Edge) -> Bool
    fn active_edges(Self) -> Array[Edge]
    fn abort(Self) -> Unit
    }

    Runs commands (ninja's CommandRunner). Hosts implement it with real processes; tests with a fake. Waiting for a command is not part of the trait: a synchronous host calls Builder::build, an event loop feeds results to Builder::command_finished.

    Disk

    pub(open) trait Disk {
    fn stat(Self, String) -> Int64 raise NinjaError
    fn make_dir(Self, String) -> Bool
    fn write_file(Self, String, String) -> Bool
    fn read_file(Self, String) -> String? raise NinjaError
    fn read_bytes(Self, String) -> Bytes? raise NinjaError
    fn remove_file(Self, String) -> Int
    fn append_bytes(Self, String, Bytes) -> Unit raise NinjaError
    fn rename_file(Self, String, String) -> Unit raise NinjaError
    fn truncate_file(Self, String, Int) -> Unit raise NinjaError
    }

    The file system as ninja uses it: ninja's DiskInterface, plus the append, rename and truncate operations its logs perform with stdio. Modification times are integers whose unit the host chooses; 0 means "missing". Text is UTF-8.

    Env

    pub(open) trait Env {
    fn lookup_variable(Self, String) -> String raise NinjaError
    }

    A scope for $var lookups.

    FileReader

    pub(open) trait FileReader {
    fn read_file(Self, String) -> String raise NinjaError
    }

    Reads included and subninja files. Errors carry the system message, e.g. "No such file or directory".

    Status

    pub(open) trait Status {
    fn edge_added_to_plan(Self, Edge) -> Unit
    fn edge_removed_from_plan(Self, Edge) -> Unit
    fn build_edge_started(Self, Edge, Int64) -> Unit
    fn build_edge_finished(Self, Edge, Int64, Int64, ExitStatus, String) -> Unit
    fn build_started(Self) -> Unit
    fn build_finished(Self) -> Unit
    fn info(Self, String) -> Unit
    fn warning(Self, String) -> Unit
    fn error(Self, String) -> Unit
    }

    Progress reporting (ninja's Status).

    Terminal

    pub(open) trait Terminal {
    fn write_out(Self, String) -> Unit
    fn write_command_output(Self, String) -> Unit
    fn write_err(Self, String) -> Unit
    fn is_smart(Self) -> Bool
    fn supports_color(Self) -> Bool
    fn width(Self) -> Int
    }

    Where ninja's output goes, and what the terminal can do.

    WaitingCommandRunner

    pub(open) trait WaitingCommandRunner : CommandRunner {
    fn wait_for_command(Self) -> CommandResult?
    }

    A runner that can also block until some command finishes; None when there is nothing to wait for or the user interrupted the build.

    NinjaError

    pub(all) suberror NinjaError {
    Error(String)
    Fatal(String)
    } derive(
    Debug
    )

    Errors raised while loading or evaluating a build manifest.

    Error carries a message that ninja prints as ninja: error: ...; Fatal corresponds to ninja's Fatal(), printed as ninja: fatal: ....

    NinjaError::message

    fn NinjaError::message(self : NinjaError) -> String

    BindingEnv

    pub struct BindingEnv {
    bindings : Map[String, String]
    rules : Map[String, Rule]
    parent : BindingEnv?
    }

    A variable scope with rules, nested in an optional parent scope.
    impl Env for BindingEnv

    BindingEnv::add_binding

    fn BindingEnv::add_binding(self : BindingEnv, key : String, value : String) -> Unit

    BindingEnv::add_rule

    fn BindingEnv::add_rule(self : BindingEnv, rule : Rule) -> Unit

    BindingEnv::lookup

    fn BindingEnv::lookup(self : BindingEnv, name : String) -> String

    The value of name in this scope or the nearest enclosing one.

    BindingEnv::lookup_rule

    fn BindingEnv::lookup_rule(self : BindingEnv, name : String) -> Rule?

    BindingEnv::lookup_rule_current_scope

    fn BindingEnv::lookup_rule_current_scope(self : BindingEnv, name : String) -> Rule?

    BindingEnv::lookup_with_fallback

    fn[E : Env] BindingEnv::lookup_with_fallback(self : BindingEnv, name : String, eval : EvalString?, env : E) -> String raise NinjaError

    Edges look a variable up in this order: (1) the edge's own bindings (self), (2) the rule's binding eval, expanded in env, (3) the scope enclosing the edge.

    BindingEnv::new

    fn BindingEnv::new(parent? : BindingEnv) -> BindingEnv

    BindingEnv::rules

    fn BindingEnv::rules(self : BindingEnv) -> Array[Rule]

    The rules of this scope, ordered by name.

    BuildConfig

    pub(all) struct BuildConfig {
    verbosity : Verbosity
    dry_run : Bool
    parallelism : Int
    failures_allowed : Int
    max_load_average : Double
    keep_depfile : Bool
    keep_rsp : Bool
    explain : Bool
    }

    BuildConfig::default

    fn BuildConfig::default() -> BuildConfig

    BuildLog

    pub struct BuildLog {
    entries : Map[String, LogEntry]
    path : String
    opened : Bool
    needs_recompaction : Bool
    }

    .ninja_log: for each output, the hash of the command that last built it and when. Port of ninja's BuildLog (format v7).

    BuildLog::close

    fn[D : Disk] BuildLog::close(self : BuildLog, disk : D) -> Unit raise NinjaError

    Closes the log, creating the file even if nothing was recorded.

    BuildLog::entries

    fn BuildLog::entries(self : BuildLog) -> Map[String, LogEntry]

    BuildLog::load

    fn[D : Disk] BuildLog::load(self : BuildLog, disk : D, path : String) -> (LoadStatus, String) raise NinjaError

    Loads path. A log of another format version is deleted and reported as NotFound with a message; outputs will simply be rebuilt.

    BuildLog::lookup_by_output

    fn BuildLog::lookup_by_output(self : BuildLog, path : String) -> LogEntry?

    BuildLog::new

    fn BuildLog::new() -> BuildLog

    BuildLog::open_for_write

    fn[D : Disk] BuildLog::open_for_write(self : BuildLog, disk : D, path : String, is_path_dead : (String) -> Bool) -> Unit raise NinjaError

    Prepares to append to path, first rewriting it without redundant or dead entries if loading found that worthwhile. is_path_dead tells which outputs no longer exist in the manifest.

    BuildLog::recompact

    fn[D : Disk] BuildLog::recompact(self : BuildLog, disk : D, path : String, is_path_dead : (String) -> Bool) -> Unit raise NinjaError

    Rewrites the log with one entry per live output.

    BuildLog::record_command

    fn[D : Disk] BuildLog::record_command(self : BuildLog, disk : D, edge : Edge, start_time : Int, end_time : Int, mtime? : Int64) -> Unit raise NinjaError

    Records that edge ran from start_time to end_time (milliseconds since the build started) and left its outputs with mtime.

    BuildLog::restat

    fn[D : Disk] BuildLog::restat(self : BuildLog, disk : D, path : String, outputs : Array[String]) -> Unit raise NinjaError

    Updates the recorded mtimes from the disk (ninja -t restat), for the given outputs or, when outputs is empty, for all of them.

    BuildProgress

    pub(all) enum BuildProgress {
    Waiting
    Finished(ExitStatus, String)
    } derive(Eq,
    Debug
    )

    A step of a build driven by the host.

    Builder

    pub struct Builder {
    state : State
    config : BuildConfig
    plan : Plan
    status : &Status
    disk : &Disk
    scan : DependencyScan
    explanations : Explanations?
    lock_file_path : String
    start_time_millis : Int64
    cwd : String
    clock : () -> Int64
    running_edges : Map[Int, Int64]
    exit_code : ExitStatus
    pending_commands : Int
    failures_allowed : Int
    }

    Runs a plan: starts commands, records their results and updates the graph (ninja's Builder).

    Builder::add_target

    fn Builder::add_target(self : Builder, target : Node) -> Unit raise NinjaError

    Scans target and adds what it needs, and its validations, to the plan.

    Builder::add_target_name

    fn Builder::add_target_name(self : Builder, name : String) -> Node raise NinjaError

    Adds the target named name.

    Builder::already_up_to_date

    fn Builder::already_up_to_date(self : Builder) -> Bool

    Builder::build

    fn[R : WaitingCommandRunner + CommandRunner] Builder::build(self : Builder, runner : R) -> (ExitStatus, String)

    Runs the whole build with a runner that can wait for commands.

    Builder::cleanup

    fn[R : CommandRunner] Builder::cleanup(self : Builder, runner : R) -> Unit

    Stops the running commands and removes their possibly half-written outputs, and the lock file.

    Builder::command_finished

    fn[R : CommandRunner] Builder::command_finished(self : Builder, runner : R, result : CommandResult?) -> BuildProgress

    Reports the result of a running command (None: interrupted) and goes on with the build.

    Builder::exit_code

    fn Builder::exit_code(self : Builder) -> ExitStatus

    Builder::explanations

    fn Builder::explanations(self : Builder) -> Explanations?

    Builder::load_dyndeps

    fn Builder::load_dyndeps(self : Builder, node : Node) -> Unit raise NinjaError

    Loads a dyndep file that just became ready and updates the plan.

    Builder::new

    fn Builder::new(state : State, config : BuildConfig, disk : &Disk, status? : &Status, build_log? : BuildLog, deps_log? : DepsLog, start_time_millis? : Int64, clock? : () -> Int64, cwd? : String) -> Builder

    Builder::plan

    fn Builder::plan(self : Builder) -> Plan

    Builder::scan

    fn Builder::scan(self : Builder) -> DependencyScan

    Builder::set_build_log

    fn Builder::set_build_log(self : Builder, log : BuildLog?) -> Unit

    Builder::start_build

    fn[R : CommandRunner] Builder::start_build(self : Builder, runner : R) -> BuildProgress

    Begins the build: queues the ready edges and starts as many commands as the runner allows.

    ClOutput

    pub struct ClOutput {
    includes : Array[String]
    filtered : String
    }

    The result of filtering MSVC /showIncludes output.

    ClOutput::filtered

    fn ClOutput::filtered(self : ClOutput) -> String

    ClOutput::includes

    fn ClOutput::includes(self : ClOutput) -> Array[String]

    Cleaner

    pub struct Cleaner {
    state : State
    config : BuildConfig
    disk : &Disk
    reader : &FileReader?
    terminal : &Terminal?
    removed : Map[String, Unit]
    cleaned : Map[Int, Unit]
    cleaned_files_count : Int
    status : Int
    }

    Removes built files: ninja -t clean and -t cleandead (ninja's Cleaner). Each clean_* method returns 0, or 1 if something could not be removed or was not found.

    Cleaner::clean_all

    fn Cleaner::clean_all(self : Cleaner, generator? : Bool) -> Int

    Removes every output but phony ones, and generator outputs unless generator is set.

    Cleaner::clean_dead

    fn Cleaner::clean_dead(self : Cleaner, entries : Map[String, LogEntry]) -> Int

    Removes the build log's outputs that the manifest no longer mentions.

    Cleaner::clean_rule

    fn Cleaner::clean_rule(self : Cleaner, name : String) -> Int

    Cleaner::clean_rules

    fn Cleaner::clean_rules(self : Cleaner, names : Array[String]) -> Int

    Cleaner::clean_target

    fn Cleaner::clean_target(self : Cleaner, target : String) -> Int

    Cleaner::clean_target_node

    fn Cleaner::clean_target_node(self : Cleaner, target : Node) -> Int

    Removes target and everything it is built from.

    Cleaner::clean_targets

    fn Cleaner::clean_targets(self : Cleaner, targets : Array[String]) -> Int

    Cleaner::cleaned_files_count

    fn Cleaner::cleaned_files_count(self : Cleaner) -> Int

    Cleaner::new

    fn Cleaner::new(state : State, config : BuildConfig, disk : &Disk, reader? : &FileReader, terminal? : &Terminal) -> Cleaner

    CommandCollector

    pub struct CommandCollector {
    visited_nodes : Map[String, Unit]
    visited_edges : Map[Int, Unit]
    in_edges : Array[Edge]
    }

    Collects the non-phony edges leading to nodes, dependencies first (ninja -t compdb-targets).

    CommandCollector::collect_from

    fn CommandCollector::collect_from(self : CommandCollector, node : Node) -> Unit

    CommandCollector::in_edges

    fn CommandCollector::in_edges(self : CommandCollector) -> Array[Edge]

    CommandCollector::new

    CommandResult

    pub struct CommandResult {
    edge : Edge
    status : ExitStatus
    output : String
    }

    The outcome of one command.

    CommandResult::edge

    fn CommandResult::edge(self : CommandResult) -> Edge

    CommandResult::new

    fn CommandResult::new(edge : Edge, status : ExitStatus, output? : String) -> CommandResult

    CommandResult::output

    fn CommandResult::output(self : CommandResult) -> String

    CommandResult::status

    fn CommandResult::status(self : CommandResult) -> ExitStatus

    DependencyScan

    pub struct DependencyScan {
    state : State
    build_log : BuildLog?
    disk : &Disk
    dep_loader : ImplicitDepLoader
    explanations : Explanations?
    }

    Decides which nodes are dirty: port of ninja's DependencyScan.

    DependencyScan::build_log

    fn DependencyScan::build_log(self : DependencyScan) -> BuildLog?

    DependencyScan::deps_log

    fn DependencyScan::deps_log(self : DependencyScan) -> DepsLog?

    DependencyScan::load_dyndeps

    fn DependencyScan::load_dyndeps(self : DependencyScan, node : Node, file? : DyndepFile) -> Unit raise NinjaError

    Loads the dyndep file node into the graph.

    DependencyScan::new

    fn DependencyScan::new(state : State, disk : &Disk, build_log? : BuildLog, deps_log? : DepsLog, explanations? : Explanations) -> DependencyScan

    DependencyScan::recompute_dirty

    fn DependencyScan::recompute_dirty(self : DependencyScan, initial : Node, validation_nodes? : Array[Node]) -> Unit raise NinjaError

    Updates the dirty state of node and everything it depends on. The validation nodes found along the way are scanned too and appended to validation_nodes.

    DependencyScan::recompute_outputs_dirty

    fn DependencyScan::recompute_outputs_dirty(self : DependencyScan, edge : Edge, most_recent_input : Node?) -> Bool raise NinjaError

    Whether any output of edge is out of date.

    DependencyScan::set_build_log

    fn DependencyScan::set_build_log(self : DependencyScan, log : BuildLog?) -> Unit

    Depfile

    pub struct Depfile {
    outs : Array[String]
    ins : Array[String]
    }

    The targets and dependencies of a Makefile-style depfile, as written by gcc -M/clang -M. Duplicates are removed; order is preserved.

    Depfile::ins

    fn Depfile::ins(self : Depfile) -> Array[String]

    Depfile::outs

    fn Depfile::outs(self : Depfile) -> Array[String]

    Deps

    pub struct Deps {
    mtime : Int64
    nodes : Array[Node]
    }

    The dependencies discovered for one output, and its mtime when they were recorded.

    Deps::mtime

    fn Deps::mtime(self : Deps) -> Int64

    Deps::nodes

    fn Deps::nodes(self : Deps) -> Array[Node]

    DepsLog

    pub struct DepsLog {
    nodes : Array[Node]
    deps : Array[Deps?]
    pending_path : String
    file : String?
    needs_recompaction : Bool
    }

    .ninja_deps: discovered dependencies (from depfiles or /showIncludes) in ninja's binary format v4. Every path gets an id; records are little-endian 32-bit words.

    DepsLog::close

    fn[D : Disk] DepsLog::close(self : DepsLog, disk : D) -> Unit raise NinjaError

    Closes the log, creating the file even if nothing was recorded.

    DepsLog::deps

    fn DepsLog::deps(self : DepsLog) -> Array[Deps?]

    Deps by node id.

    DepsLog::get_deps

    fn DepsLog::get_deps(self : DepsLog, node : Node) -> Deps?

    DepsLog::get_first_reverse_deps_node

    fn DepsLog::get_first_reverse_deps_node(self : DepsLog, node : Node) -> Node?

    Some output whose deps include node.

    DepsLog::load

    fn[D : Disk] DepsLog::load(self : DepsLog, disk : D, path : String, state : State) -> (LoadStatus, String) raise NinjaError

    Loads path into state. A file with a bad header is deleted and a damaged tail is cut off; both are reported as a message, not a failure.

    DepsLog::new

    fn DepsLog::new() -> DepsLog

    DepsLog::nodes

    fn DepsLog::nodes(self : DepsLog) -> Array[Node]

    Nodes by id.

    DepsLog::open_for_write

    fn[D : Disk] DepsLog::open_for_write(self : DepsLog, disk : D, path : String) -> Unit raise NinjaError

    DepsLog::recompact

    fn[D : Disk] DepsLog::recompact(self : DepsLog, disk : D, path : String) -> Unit raise NinjaError

    Rewrites the log with only the live entries, renumbering the nodes.

    DepsLog::record_deps

    fn[D : Disk] DepsLog::record_deps(self : DepsLog, disk : D, node : Node, mtime : Int64, nodes : Array[Node]) -> Unit raise NinjaError

    Records that node, with mtime, depends on nodes. Nothing is written when the log already says so.

    DyndepFile

    pub struct DyndepFile {
    entries : Map[Int, Dyndeps]
    }

    The contents of a dyndep file, by edge (ninja's DyndepFile).

    DyndepFile::get

    fn DyndepFile::get(self : DyndepFile, edge : Edge) -> Dyndeps?

    DyndepFile::length

    fn DyndepFile::length(self : DyndepFile) -> Int

    DyndepFile::new

    fn DyndepFile::new() -> DyndepFile

    DyndepParser

    pub struct DyndepParser {
    state : State
    read : (String) -> String raise NinjaError?
    file : DyndepFile
    lexer : Lexer
    env : BindingEnv
    }

    Parses dyndep files: ninja_dyndep_version = 1 followed by build out | implicit-outs: dyndep | implicit-ins statements for edges that already exist.

    DyndepParser::load

    fn DyndepParser::load(self : DyndepParser, filename : String) -> Unit raise NinjaError

    DyndepParser::new

    fn[R : FileReader] DyndepParser::new(state : State, reader : R, file : DyndepFile) -> DyndepParser

    DyndepParser::parse

    fn DyndepParser::parse(self : DyndepParser, filename : String, input : String) -> Unit raise NinjaError

    DyndepParser::parse_test

    fn DyndepParser::parse_test(self : DyndepParser, input : String) -> Unit raise NinjaError

    DyndepParser::without_files

    fn DyndepParser::without_files(state : State, file : DyndepFile) -> DyndepParser

    Dyndeps

    pub struct Dyndeps {
    edge : Edge
    used : Bool
    restat : Bool
    implicit_inputs : Array[Node]
    implicit_outputs : Array[Node]
    }

    What a dyndep file says about one edge.

    Dyndeps::implicit_inputs

    fn Dyndeps::implicit_inputs(self : Dyndeps) -> Array[Node]

    Dyndeps::implicit_outputs

    fn Dyndeps::implicit_outputs(self : Dyndeps) -> Array[Node]

    Dyndeps::restat

    fn Dyndeps::restat(self : Dyndeps) -> Bool

    Edge

    pub struct Edge {
    id : Int
    rule : Rule
    pool : Pool
    inputs : Array[Node]
    outputs : Array[Node]
    validations : Array[Node]
    env : BindingEnv
    implicit_deps : Int
    order_only_deps : Int
    implicit_outs : Int
    dyndep : Node?
    platform : Platform
    mark : VisitMark
    outputs_ready : Bool
    deps_loaded : Bool
    deps_missing : Bool
    critical_path_weight : Int64
    command_start_time : Int64
    prev_elapsed_time_millis : Int64
    }

    A build statement. Inputs are ordered explicit, implicit, then order-only; outputs are ordered explicit, then implicit.

    Edge::all_inputs_ready

    fn Edge::all_inputs_ready(self : Edge) -> Bool

    Whether every input produced by another edge is ready.

    Edge::critical_path_weight

    fn Edge::critical_path_weight(self : Edge) -> Int64

    Edge::dyndep

    fn Edge::dyndep(self : Edge) -> Node?

    Edge::evaluate_command

    fn Edge::evaluate_command(self : Edge, incl_rsp_file? : Bool) -> String raise NinjaError

    The command line; with incl_rsp_file, the response file contents are appended as ;rspfile=... (this is what the build log hashes).

    Edge::get_binding

    fn Edge::get_binding(self : Edge, key : String) -> String raise NinjaError

    The value of key for this edge, with $in and $out shell-escaped.

    Edge::get_binding_bool

    fn Edge::get_binding_bool(self : Edge, key : String) -> Bool raise NinjaError

    Edge::get_unescaped_depfile

    fn Edge::get_unescaped_depfile(self : Edge) -> String raise NinjaError

    Edge::get_unescaped_dyndep

    fn Edge::get_unescaped_dyndep(self : Edge) -> String raise NinjaError

    Edge::get_unescaped_rspfile

    fn Edge::get_unescaped_rspfile(self : Edge) -> String raise NinjaError

    Edge::id

    fn Edge::id(self : Edge) -> Int

    Edge::implicit_deps

    fn Edge::implicit_deps(self : Edge) -> Int

    Edge::implicit_outs

    fn Edge::implicit_outs(self : Edge) -> Int

    Edge::inputs

    fn Edge::inputs(self : Edge) -> Array[Node]

    Edge::is_implicit

    fn Edge::is_implicit(self : Edge, index : Int) -> Bool

    Edge::is_implicit_out

    fn Edge::is_implicit_out(self : Edge, index : Int) -> Bool

    Edge::is_order_only

    fn Edge::is_order_only(self : Edge, index : Int) -> Bool

    Edge::is_phony

    fn Edge::is_phony(self : Edge) -> Bool

    Edge::maybe_phonycycle_diagnostic

    fn Edge::maybe_phonycycle_diagnostic(self : Edge) -> Bool

    CMake 2.8.12.x and 3.0.x wrote build a: phony ... a ...; ninja's phonycycle diagnostic only applies to that form.

    Edge::order_only_deps

    fn Edge::order_only_deps(self : Edge) -> Int

    Edge::outputs

    fn Edge::outputs(self : Edge) -> Array[Node]

    Edge::outputs_ready

    fn Edge::outputs_ready(self : Edge) -> Bool

    Edge::pool

    fn Edge::pool(self : Edge) -> Pool

    Edge::prev_elapsed_time_millis

    fn Edge::prev_elapsed_time_millis(self : Edge) -> Int64

    Edge::rule

    fn Edge::rule(self : Edge) -> Rule

    Edge::set_critical_path_weight

    fn Edge::set_critical_path_weight(self : Edge, weight : Int64) -> Unit

    Edge::set_prev_elapsed_time_millis

    fn Edge::set_prev_elapsed_time_millis(self : Edge, millis : Int64) -> Unit

    Edge::use_console

    fn Edge::use_console(self : Edge) -> Bool

    Edge::validations

    fn Edge::validations(self : Edge) -> Array[Node]

    Edge::weight

    fn Edge::weight(_self : Edge) -> Int

    EdgePriorityQueue

    pub struct EdgePriorityQueue {
    heap : Array[Edge]
    }

    Ready edges, highest critical path weight first and lowest id on ties (ninja's EdgePriorityQueue).

    EdgePriorityQueue::clear

    fn EdgePriorityQueue::clear(self : EdgePriorityQueue) -> Unit

    EdgePriorityQueue::is_empty

    fn EdgePriorityQueue::is_empty(self : EdgePriorityQueue) -> Bool

    EdgePriorityQueue::length

    fn EdgePriorityQueue::length(self : EdgePriorityQueue) -> Int

    EdgePriorityQueue::new

    EdgePriorityQueue::pop

    EdgePriorityQueue::push

    fn EdgePriorityQueue::push(self : EdgePriorityQueue, edge : Edge) -> Unit

    EdgePriorityQueue::top

    EdgeResult

    pub(all) enum EdgeResult {
    EdgeFailed
    EdgeSucceeded
    } derive(Eq,
    Debug
    )

    EvalString

    pub struct EvalString {
    tokens : Array[EvalToken]
    }

    A manifest string with unexpanded variable references.

    EvalString::add_special

    fn EvalString::add_special(self : EvalString, name : String) -> Unit

    EvalString::add_text

    fn EvalString::add_text(self : EvalString, text : String) -> Unit

    EvalString::clear

    fn EvalString::clear(self : EvalString) -> Unit

    EvalString::evaluate

    fn[E : Env] EvalString::evaluate(self : EvalString, env : E) -> String raise NinjaError

    Expands the variable references in env.

    EvalString::is_empty

    fn EvalString::is_empty(self : EvalString) -> Bool

    EvalString::new

    fn EvalString::new() -> EvalString

    EvalString::serialize

    fn EvalString::serialize(self : EvalString) -> String

    The parsed form, for tests: [text][$var].

    EvalString::unparse

    fn EvalString::unparse(self : EvalString) -> String

    The string with references written as ${var}.

    EvalToken

    pub(all) enum EvalToken {
    Raw(String)
    Special(String)
    } derive(Eq,
    Debug
    )

    Existence

    pub(all) enum Existence {
    Unknown
    Missing
    Exists
    } derive(Eq,
    Debug
    )

    ExitStatus

    pub(all) enum ExitStatus {
    Success
    Failure
    Interrupted
    Exited(Int)
    } derive(Eq,
    Debug
    )

    How a build or a command ended (ninja's ExitStatus).

    ExitStatus::code

    fn ExitStatus::code(self : ExitStatus) -> Int

    The process exit code for the status.

    ExitStatus::from_code

    fn ExitStatus::from_code(code : Int) -> ExitStatus

    The status for a process exit code. ninja's ExitStatus is the exit code itself, so a command exiting with 127 makes ninja exit with 127.

    Explanations

    pub struct Explanations {
    map : Map[String, Array[String]]
    }

    Why nodes are dirty, for -d explain (ninja's Explanations).

    Explanations::lookup

    fn Explanations::lookup(self : Explanations, node : Node) -> Array[String]

    Explanations::new

    Explanations::record

    fn Explanations::record(self : Explanations, node : Node, message : String) -> Unit

    GraphViz

    pub struct GraphViz {
    state : State
    reader : &FileReader?
    out : (String) -> Unit
    warn : (String) -> Unit
    windows : Bool
    visited_nodes : Map[Int, Unit]
    visited_edges : Map[Int, Unit]
    }

    Writes a Graphviz dot graph of the targets (-t graph, ninja's GraphViz). ninja names graph vertices by their addresses; these stand-ins are stable but just as arbitrary.

    GraphViz::add_target

    fn GraphViz::add_target(self : GraphViz, node : Node) -> Unit

    GraphViz::finish

    fn GraphViz::finish(self : GraphViz) -> Unit

    GraphViz::new

    fn GraphViz::new(state : State, out : (String) -> Unit, reader? : &FileReader, warn? : (String) -> Unit) -> GraphViz

    GraphViz::start

    fn GraphViz::start(self : GraphViz) -> Unit

    ImplicitDepLoader

    pub struct ImplicitDepLoader {
    state : State
    deps_log : DepsLog?
    disk : &Disk
    explanations : Explanations?
    store : Array[Node]?
    }

    Adds the dependencies an edge discovered when it last ran: from the deps log for deps = gcc|msvc, or from its depfile.

    ImplicitDepLoader::load_deps

    fn ImplicitDepLoader::load_deps(self : ImplicitDepLoader, edge : Edge) -> Bool raise NinjaError

    Loads the edge's discovered deps. False when they are missing or stale, so the edge must run to regenerate them.

    ImplicitDepLoader::new

    fn ImplicitDepLoader::new(state : State, disk : &Disk, deps_log? : DepsLog, explanations? : Explanations, store? : Array[Node]) -> ImplicitDepLoader

    IncludesNormalize

    pub struct IncludesNormalize {
    cwd : String
    relative_to : String
    split_relative_to : Array[String]
    }

    Makes the include paths of /showIncludes relative to a directory, as ninja does on Windows for deps = msvc (ninja's IncludesNormalize).

    IncludesNormalize::abs_path

    fn IncludesNormalize::abs_path(s : String, cwd : String) -> String raise NinjaError

    s made absolute, with forward slashes.

    IncludesNormalize::new

    fn IncludesNormalize::new(relative_to : String, cwd : String) -> IncludesNormalize raise NinjaError

    relative_to is resolved against cwd, the working directory.

    IncludesNormalize::normalize

    fn IncludesNormalize::normalize(self : IncludesNormalize, input : String) -> String raise NinjaError

    input canonicalized and made relative to the directory, unless it is on another drive.

    InputsCollector

    pub struct InputsCollector {
    inputs : Array[Node]
    visited : Map[String, Unit]
    platform : Platform
    }

    Collects the inputs that lead to nodes, skipping outputs of phony edges (ninja -t inputs).

    InputsCollector::inputs

    fn InputsCollector::inputs(self : InputsCollector) -> Array[Node]

    InputsCollector::inputs_as_strings

    fn InputsCollector::inputs_as_strings(self : InputsCollector, escape? : Bool) -> Array[String]

    InputsCollector::new

    fn InputsCollector::new(platform? : Platform) -> InputsCollector

    InputsCollector::reset

    fn InputsCollector::reset(self : InputsCollector) -> Unit

    InputsCollector::visit_node

    fn InputsCollector::visit_node(self : InputsCollector, node : Node) -> Unit

    Lexer

    pub struct Lexer {
    filename : String
    input : String
    ofs : Int
    last_token : Int
    }

    Port of ninja's re2c lexer. Positions are code-unit offsets into input; the end of the input, like an embedded NUL, reads as NUL.

    Lexer::describe_last_error

    fn Lexer::describe_last_error(self : Lexer) -> String

    Lexer::error

    fn Lexer::error(self : Lexer, message : String) -> String

    Formats an error at the last token as ninja does: file:line: message, followed by the line and a caret when the column is between 1 and 71.

    Lexer::new

    fn Lexer::new(input : String, filename? : String) -> Lexer

    Lexer::peek_token

    fn Lexer::peek_token(self : Lexer, token : Token) -> Bool

    Reads the next token if it is token; otherwise leaves the input as it was.

    Lexer::read_ident

    fn Lexer::read_ident(self : Lexer) -> String?

    Reads a variable or rule name; None (consuming nothing) when the input does not start with one.

    Lexer::read_path

    fn Lexer::read_path(self : Lexer) -> EvalString raise NinjaError

    Reads a path; an empty result means there was none.

    Lexer::read_token

    fn Lexer::read_token(self : Lexer) -> Token

    Reads the next token. Comments and blank space between tokens are skipped; leading spaces on a line are an Indent.

    Lexer::read_var_value

    fn Lexer::read_var_value(self : Lexer) -> EvalString raise NinjaError

    Reads the rest of the line as a variable value.

    Lexer::unread_token

    fn Lexer::unread_token(self : Lexer) -> Unit

    LinePrinter

    pub struct LinePrinter {
    terminal : &Terminal
    smart : Bool
    color : Bool
    have_blank_line : Bool
    console_locked : Bool
    line_buffer : String
    line_type : LineType
    output_buffer : StringBuilder
    }

    Prints status lines that overwrite each other on a smart terminal, and holds output back while a console-pool command owns the terminal (ninja's LinePrinter).

    LinePrinter::is_smart_terminal

    fn LinePrinter::is_smart_terminal(self : LinePrinter) -> Bool

    LinePrinter::new

    fn LinePrinter::new(terminal : &Terminal, smart_terminal? : Bool) -> LinePrinter

    LinePrinter::print

    fn LinePrinter::print(self : LinePrinter, line : String, line_type : LineType) -> Unit

    Prints line, overwriting the previous status line on a smart terminal.

    LinePrinter::print_on_new_line

    fn LinePrinter::print_on_new_line(self : LinePrinter, text : String, raw? : Bool) -> Unit

    Prints text starting on a fresh line.

    LinePrinter::set_console_locked

    fn LinePrinter::set_console_locked(self : LinePrinter, locked : Bool) -> Unit

    While locked, a console-pool command writes to the terminal directly and everything else is buffered.

    LinePrinter::supports_color

    fn LinePrinter::supports_color(self : LinePrinter) -> Bool

    LineType

    pub(all) enum LineType {
    Full
    Elide
    } derive(Eq,
    Debug
    )

    LoadStatus

    pub(all) enum LoadStatus {
    Success
    NotFound
    } derive(Eq,
    Debug
    )

    LogEntry

    pub(all) struct LogEntry {
    output : String
    command_hash : UInt64
    start_time : Int
    end_time : Int
    mtime : Int64
    } derive(Eq,
    Debug
    )

    One output's record in .ninja_log.

    ManifestParser

    pub struct ManifestParser {
    state : State
    read : (String) -> String raise NinjaError?
    options : ManifestParserOptions
    env : BindingEnv
    quiet : Bool
    lexer : Lexer
    warnings : Array[String]
    }

    Parses .ninja files into a State.

    ManifestParser::load

    fn ManifestParser::load(self : ManifestParser, filename : String, parent? : Lexer) -> Unit raise NinjaError

    Loads and parses filename. When parent is given (an include or subninja), a read failure is reported at the parent's position.

    ManifestParser::new

    fn[R : FileReader] ManifestParser::new(state : State, reader? : R, options? : ManifestParserOptions) -> ManifestParser

    ManifestParser::parse

    fn ManifestParser::parse(self : ManifestParser, filename : String, input : String) -> Unit raise NinjaError

    ManifestParser::parse_test

    fn ManifestParser::parse_test(self : ManifestParser, input : String) -> Unit raise NinjaError

    Parses input as a file named "input", without warnings (ninja's ParseTest).

    ManifestParser::warnings

    fn ManifestParser::warnings(self : ManifestParser) -> Array[String]

    ManifestParser::without_files

    fn ManifestParser::without_files(state : State, options? : ManifestParserOptions) -> ManifestParser

    A parser that cannot read other files.

    ManifestParserOptions

    pub(all) struct ManifestParserOptions {
    phony_cycle_action : PhonyCycleAction
    }

    ManifestParserOptions::default

    MemoryDisk

    pub struct MemoryDisk {
    files : Map[String, MemoryFile]
    now : Int64
    directories_made : Array[String]
    files_read : Array[String]
    files_created : Array[String]
    files_removed : Array[String]
    }

    An in-memory Disk with a logical clock, ported from ninja's test VirtualFileSystem. It records what was read, created, removed and which directories were made.
    impl Disk for MemoryDisk

    MemoryDisk::bytes

    fn MemoryDisk::bytes(self : MemoryDisk, path : String) -> Bytes?

    MemoryDisk::contents

    fn MemoryDisk::contents(self : MemoryDisk, path : String) -> String?

    MemoryDisk::create

    fn MemoryDisk::create(self : MemoryDisk, path : String, contents : String) -> Unit

    Creates or replaces path with UTF-8 text.

    MemoryDisk::create_bytes

    fn MemoryDisk::create_bytes(self : MemoryDisk, path : String, contents : Bytes) -> Unit

    Creates or replaces path with the current time as its mtime.

    MemoryDisk::directories_made

    fn MemoryDisk::directories_made(self : MemoryDisk) -> Array[String]

    MemoryDisk::exists

    fn MemoryDisk::exists(self : MemoryDisk, path : String) -> Bool

    MemoryDisk::files_created

    fn MemoryDisk::files_created(self : MemoryDisk) -> Array[String]

    MemoryDisk::files_read

    fn MemoryDisk::files_read(self : MemoryDisk) -> Array[String]

    MemoryDisk::files_removed

    fn MemoryDisk::files_removed(self : MemoryDisk) -> Array[String]

    MemoryDisk::new

    fn MemoryDisk::new() -> MemoryDisk

    MemoryDisk::now

    fn MemoryDisk::now(self : MemoryDisk) -> Int64

    MemoryDisk::set_mtime

    fn MemoryDisk::set_mtime(self : MemoryDisk, path : String, mtime : Int64) -> Unit

    MemoryDisk::set_stat_error

    fn MemoryDisk::set_stat_error(self : MemoryDisk, path : String, message : String) -> Unit

    Makes stat of path fail with message.

    MemoryDisk::tick

    fn MemoryDisk::tick(self : MemoryDisk) -> Int64

    Advances the clock; later writes are newer than earlier ones.

    MemoryFile

    type MemoryFile

    MissingDependencyScanner

    pub struct MissingDependencyScanner {
    on_missing_dep : (Node, String, Rule) -> Unit
    deps_log : DepsLog
    state : State
    disk : &Disk
    seen : Map[Int, Unit]
    nodes_missing_deps : Map[Int, Node]
    generated_nodes : Map[Int, Node]
    generator_rules : Array[Rule]
    missing_dep_path_count : Int
    adjacency : Map[(Int, Int), Bool]
    }

    Finds discovered dependencies (from the deps log or depfiles) on generated files with no build-graph path to their generator: such targets may build before the file exists (-t missingdeps, ninja's MissingDependencyScanner).

    MissingDependencyScanner::generated_nodes

    MissingDependencyScanner::generator_rules

    MissingDependencyScanner::had_missing_deps

    fn MissingDependencyScanner::had_missing_deps(self : MissingDependencyScanner) -> Bool

    MissingDependencyScanner::missing_dep_path_count

    fn MissingDependencyScanner::missing_dep_path_count(self : MissingDependencyScanner) -> Int

    MissingDependencyScanner::new

    fn MissingDependencyScanner::new(deps_log : DepsLog, state : State, disk : &Disk, on_missing_dep? : (Node, String, Rule) -> Unit) -> MissingDependencyScanner

    MissingDependencyScanner::nodes_missing_deps

    fn MissingDependencyScanner::nodes_missing_deps(self : MissingDependencyScanner) -> Array[Node]

    MissingDependencyScanner::process_node

    fn MissingDependencyScanner::process_node(self : MissingDependencyScanner, node : Node) -> Unit

    MissingDependencyScanner::stats

    The summary ninja -t missingdeps ends with.

    Node

    pub struct Node {
    path : String
    slash_bits : UInt64
    in_edge : Edge?
    out_edges : Array[Edge]
    validation_out_edges : Array[Edge]
    generated_by_dep_loader : Bool
    dyndep_pending : Bool
    id : Int
    index : Int
    mtime : Int64
    existence : Existence
    dirty : Bool
    }

    A file in the build graph.

    Node::dirty

    fn Node::dirty(self : Node) -> Bool

    Node::dyndep_pending

    fn Node::dyndep_pending(self : Node) -> Bool

    Node::exists

    fn Node::exists(self : Node) -> Bool

    Node::generated_by_dep_loader

    fn Node::generated_by_dep_loader(self : Node) -> Bool

    Node::id

    fn Node::id(self : Node) -> Int

    Node::in_edge

    fn Node::in_edge(self : Node) -> Edge?

    Node::mark_missing

    fn Node::mark_missing(self : Node) -> Unit

    Node::mtime

    fn Node::mtime(self : Node) -> Int64

    Node::new

    fn Node::new(path : String, slash_bits : UInt64) -> Node

    Node::out_edges

    fn Node::out_edges(self : Node) -> Array[Edge]

    Node::path

    fn Node::path(self : Node) -> String

    Node::path_decanonicalized

    fn Node::path_decanonicalized(self : Node, platform : Platform) -> String

    The path with its original separators.

    Node::reset_state

    fn Node::reset_state(self : Node) -> Unit

    Node::set_dirty

    fn Node::set_dirty(self : Node, dirty : Bool) -> Unit

    Node::slash_bits

    fn Node::slash_bits(self : Node) -> UInt64

    Node::stat

    fn Node::stat(self : Node, disk : &Disk) -> Unit raise NinjaError

    Reads the mtime from disk.

    Node::stat_if_necessary

    fn Node::stat_if_necessary(self : Node, disk : &Disk) -> Unit raise NinjaError

    Node::status_known

    fn Node::status_known(self : Node) -> Bool

    Node::update_phony_mtime

    fn Node::update_phony_mtime(self : Node, mtime : Int64) -> Unit

    A phony output that does not exist takes the newest mtime of its inputs, so that its dependents compare against them.

    Node::validation_out_edges

    fn Node::validation_out_edges(self : Node) -> Array[Edge]

    NullStatus

    pub struct NullStatus {
    }

    A Status that reports nothing.

    NullStatus::new

    fn NullStatus::new() -> NullStatus

    PhonyCycleAction

    pub(all) enum PhonyCycleAction {
    Warn
    Error
    } derive(Eq,
    Debug
    )

    What to do with build a: phony a (written by CMake 2.8.12.x/3.0.x).

    Plan

    pub struct Plan {
    want : Map[Int, Wanted]
    ready : EdgePriorityQueue
    targets : Array[Node]
    wanted_edges : Int
    command_edges : Int
    status : &Status
    dyndep_loader : (Node) -> Unit raise NinjaError?
    }

    What to build and in which order (ninja's Plan).

    Plan::add_target

    fn Plan::add_target(self : Plan, target : Node) -> Unit raise NinjaError

    Adds target and what it needs to the plan. Fails if a needed source file is missing.

    Plan::clean_node

    fn Plan::clean_node(self : Plan, scan : DependencyScan, node : Node) -> Unit raise NinjaError

    Marks node clean after a restat rule left it unchanged, and drops the edges that no longer need to run.

    Plan::command_edge_count

    fn Plan::command_edge_count(self : Plan) -> Int

    Plan::dyndeps_loaded

    fn Plan::dyndeps_loaded(self : Plan, scan : DependencyScan, node : Node, file : DyndepFile) -> Unit raise NinjaError

    Updates the plan after the dyndep file node was loaded into file.

    Plan::edge_finished

    fn Plan::edge_finished(self : Plan, edge : Edge, result : EdgeResult) -> Unit raise NinjaError

    Marks edge as finished and schedules what that makes ready.

    Plan::find_work

    fn Plan::find_work(self : Plan) -> Edge?

    The next edge to run, if one is ready.

    Plan::more_to_do

    fn Plan::more_to_do(self : Plan) -> Bool

    Plan::new

    fn Plan::new() -> Plan

    Plan::prepare_queue

    fn Plan::prepare_queue(self : Plan) -> Unit

    Computes priorities and queues the edges that can start.

    Plan::reset

    fn Plan::reset(self : Plan) -> Unit

    Platform

    pub(all) enum Platform {
    Posix
    Windows
    } derive(Eq,
    Debug
    )

    The host conventions that ninja selects at compile time with _WIN32. moonja takes them as a value, so both variants run on every host and in every test.

    Pool

    pub struct Pool {
    name : String
    depth : Int
    current_use : Int
    delayed : Array[Edge]
    }

    A pool limits how many of its edges run at once; depth 0 is unlimited.

    Pool::current_use

    fn Pool::current_use(self : Pool) -> Int

    Pool::delay_edge

    fn Pool::delay_edge(self : Pool, edge : Edge) -> Unit

    Pool::depth

    fn Pool::depth(self : Pool) -> Int

    Pool::edge_finished

    fn Pool::edge_finished(self : Pool, edge : Edge) -> Unit

    Pool::edge_scheduled

    fn Pool::edge_scheduled(self : Pool, edge : Edge) -> Unit

    Pool::name

    fn Pool::name(self : Pool) -> String

    Pool::new

    fn Pool::new(name : String, depth : Int) -> Pool

    Pool::retrieve_ready_edges

    fn Pool::retrieve_ready_edges(self : Pool, ready : EdgePriorityQueue) -> Unit

    Moves delayed edges to ready while the pool has room.

    Pool::should_delay_edge

    fn Pool::should_delay_edge(self : Pool) -> Bool

    Pools with a depth limit hold edges back until there is room.

    Rule

    pub struct Rule {
    name : String
    bindings : Map[String, EvalString]
    phony : Bool
    }

    A build rule: its name and its unexpanded bindings.

    Rule::add_binding

    fn Rule::add_binding(self : Rule, key : String, value : EvalString) -> Unit

    Rule::get_binding

    fn Rule::get_binding(self : Rule, key : String) -> EvalString?

    Rule::is_phony

    fn Rule::is_phony(self : Rule) -> Bool

    Rule::name

    fn Rule::name(self : Rule) -> String

    Rule::new

    fn Rule::new(name : String) -> Rule

    Rule::phony

    fn Rule::phony() -> Rule

    The built-in phony rule.

    SlidingRate

    type SlidingRate

    The edge rate over the last N finished edges (ninja's SlidingRateInfo).

    State

    pub struct State {
    platform : Platform
    paths : Map[String, Node]
    edges : Array[Edge]
    pools : Map[String, Pool]
    bindings : BindingEnv
    defaults : Array[Node]
    default_pool : Pool
    console_pool : Pool
    }

    The build graph: every file, every edge, the pools and the top-level scope.

    State::add_default

    fn State::add_default(self : State, path : String) -> Unit raise NinjaError

    State::add_edge

    fn State::add_edge(self : State, rule : Rule) -> Edge

    State::add_in

    fn State::add_in(self : State, edge : Edge, path : String, slash_bits : UInt64) -> Unit

    State::add_out

    fn State::add_out(self : State, edge : Edge, path : String, slash_bits : UInt64) -> Unit raise NinjaError

    Adds an output; fails if another edge, or this one, already produces it.

    State::add_pool

    fn State::add_pool(self : State, pool : Pool) -> Unit

    State::add_validation

    fn State::add_validation(self : State, edge : Edge, path : String, slash_bits : UInt64) -> Unit

    State::bindings

    fn State::bindings(self : State) -> BindingEnv

    State::default_nodes

    fn State::default_nodes(self : State) -> Array[Node] raise NinjaError

    The default targets, or the root nodes when there are none.

    State::edges

    fn State::edges(self : State) -> Array[Edge]

    State::get_node

    fn State::get_node(self : State, path : String, slash_bits : UInt64) -> Node

    The node for a canonical path, created on first use.

    State::lookup_node

    fn State::lookup_node(self : State, path : String) -> Node?

    State::lookup_pool

    fn State::lookup_pool(self : State, name : String) -> Pool?

    State::new

    fn State::new(platform? : Platform) -> State

    State::paths

    fn State::paths(self : State) -> Map[String, Node]

    State::platform

    fn State::platform(self : State) -> Platform

    State::reset

    fn State::reset(self : State) -> Unit

    Forgets everything learned by scanning or building, for another scan.

    State::root_nodes

    fn State::root_nodes(self : State) -> Array[Node] raise NinjaError

    Outputs that no edge uses as an input.

    State::spellcheck_node

    fn State::spellcheck_node(self : State, path : String) -> Node?

    The known path closest to path, within 3 edits, for "did you mean" hints (ninja's State::SpellcheckNode). Ties go to the earliest node.

    StatusPrinter

    pub struct StatusPrinter {
    config : BuildConfig
    printer : LinePrinter
    format : String
    explanations : Explanations?
    started_edges : Int
    finished_edges : Int
    total_edges : Int
    running_edges : Int
    time_millis : Int64
    cpu_time_millis : Int64
    time_predicted_percentage : Double
    eta_predictable_edges_total : Int
    eta_predictable_cpu_time_total_millis : Int64
    eta_predictable_edges_remaining : Int
    eta_predictable_cpu_time_remaining_millis : Int64
    eta_unpredictable_edges_remaining : Int
    current_rate : SlidingRate
    }

    ninja's console status: [finished/total] description lines, failure reports and command output (ninja's StatusPrinter).

    StatusPrinter::format_progress_status

    fn StatusPrinter::format_progress_status(self : StatusPrinter, format : String, time_millis : Int64) -> String raise NinjaError

    Expands a $NINJA_STATUS format: %s started, %t total, %r running, %u unstarted, %f finished, %o overall rate, %c current rate, %p percentage, %e/%w elapsed, %E/%W ETA, %P time percentage, %% '%'.

    StatusPrinter::new

    fn StatusPrinter::new(config : BuildConfig, terminal : &Terminal, format? : String) -> StatusPrinter

    StatusPrinter::printer

    fn StatusPrinter::printer(self : StatusPrinter) -> LinePrinter

    StatusPrinter::set_explanations

    fn StatusPrinter::set_explanations(self : StatusPrinter, explanations : Explanations?) -> Unit

    Token

    pub(all) enum Token {
    Error
    Build
    Colon
    Default
    Equals
    Ident
    Include
    Indent
    Newline
    Pipe
    Pipe2
    PipeAt
    Pool
    Rule
    Subninja
    Eof
    } derive(Eq,
    Debug
    )

    Tokens of the ninja manifest language.

    Token::error_hint

    fn Token::error_hint(self : Token) -> String

    Extra advice appended to "expected X" errors.

    Token::name

    fn Token::name(self : Token) -> String

    Verbosity

    pub(all) enum Verbosity {
    Quiet
    NoStatusUpdate
    Normal
    Verbose
    } derive(Eq,
    Debug
    )

    VisitMark

    pub(all) enum VisitMark {
    VisitNone
    VisitInStack
    VisitDone
    } derive(Eq,
    Debug
    )

    Wanted

    type Wanted

    append_text

    fn[D : Disk] append_text(disk : D, path : String, text : String) -> Unit raise NinjaError

    Appends UTF-8 text.

    atoi

    fn atoi(text : String) -> Int

    C atoi: optional leading whitespace and sign, then decimal digits up to the first other character; 0 when there are none.

    canonicalize_path

    fn canonicalize_path(path : String, platform? : Platform) -> (String, UInt64)

    Port of ninja's CanonicalizePath: removes . components, empty components and .. where possible, without touching the file system. On Windows, backslashes become / and the returned bits record which separators were backslashes (bit i for the i-th separator), so the path can be decanonicalized for command lines.

    compare_lexical

    fn compare_lexical(a : String, b : String) -> Int

    Orders strings by code unit, like std::map<std::string, ...> does for ASCII keys (String::compare puts shorter strings first).

    decanonicalize_path

    fn decanonicalize_path(path : String, slash_bits : UInt64, platform? : Platform) -> String

    The path as written in the manifest: on Windows, the separators recorded in slash_bits become backslashes again.

    edit_distance

    fn edit_distance(s1 : String, s2 : String, allow_replacements? : Bool, max_edit_distance? : Int) -> Int

    The Levenshtein distance between s1 and s2 (ninja's EditDistance). Without replacements a substitution costs two edits. When max_edit_distance is positive, the search stops early and returns max_edit_distance + 1 once every alignment is farther than that.

    elide_middle

    fn elide_middle(text : String, max_width : Int) -> String

    Shortens text to max_width visible characters by replacing its middle with "...", keeping ANSI color sequences intact (ninja's ElideMiddleInPlace).

    encode_json_string

    fn encode_json_string(text : String) -> String

    text as the inside of a JSON string (ninja's EncodeJSONString). Characters outside ASCII control codes pass through.

    filter_input_filename

    fn filter_input_filename(line : String) -> Bool

    cl.exe echoes the name of the file it compiles.

    filter_show_includes

    fn filter_show_includes(line : String, deps_prefix : String) -> String

    The included path if line is an include note: deps_prefix (by default English "Note: including file: "), then spaces, then the path.

    full_path_name

    fn full_path_name(path : String, cwd : String) -> String raise NinjaError

    GetFullPathNameA: path made absolute against cwd with . and .. resolved and backslashes as separators.

    hash_command

    fn hash_command(command : String) -> UInt64

    ninja's BuildLog::LogEntry::HashCommand: rapidhash of the command's UTF-8 bytes.

    is_deps_entry_live_for

    fn is_deps_entry_live_for(node : Node) -> Bool raise NinjaError

    Whether node still needs its deps: it is built by an edge with deps.

    is_reserved_binding

    fn is_reserved_binding(name : String) -> Bool

    The variables a rule may set.

    is_system_include

    fn is_system_include(path : String) -> Bool

    A guess: headers under Program Files or Visual Studio are system ones.

    load_dyndeps

    fn[R : FileReader] load_dyndeps(state : State, reader : R, node : Node, file? : DyndepFile) -> Unit raise NinjaError

    Loads the dyndep file node and adds what it says to the edges that name it in their dyndep binding. The file's contents go to file.

    make_dirs

    fn make_dirs(disk : &Disk, path : String, platform? : Platform) -> Bool raise NinjaError

    Creates the directories leading to path (ninja's MakeDirs).

    missing_dep_message

    fn missing_dep_message(node : Node, path : String, generator : Rule) -> String

    The report ninja -t missingdeps prints for each missing dependency.

    ninja_version

    let ninja_version : String

    The ninja release whose behavior moonja reproduces. It is reported by --version and checked against ninja_required_version.

    parse_cl_output

    fn parse_cl_output(output : String, deps_prefix : String, normalizer? : IncludesNormalize) -> ClOutput raise NinjaError

    Port of ninja's CLParser::Parse. With a normalizer (ninja on Windows) include paths are made relative to its directory; without one they are only canonicalized, as on other systems.

    parse_depfile

    fn parse_depfile(content : String) -> Depfile raise NinjaError

    Port of ninja's re2c depfile parser. Following GCC and Clang, a backslash escapes a space or #: 2N+1 backslashes and a space are N backslashes and a space; 2N backslashes and a space are 2N backslashes that end the name. \: is a colon unless whitespace follows it, and $$ is a dollar sign. Other backslashes are kept.

    rapidhash

    fn rapidhash(key : Bytes) -> UInt64

    rapidhash of key with ninja's default seed.

    shell_escape

    fn shell_escape(input : String, out : StringBuilder) -> Unit

    Port of GetShellEscapedString: single-quotes a path for /bin/sh when it contains anything outside [A-Za-z0-9_+\-./].

    strip_ansi_escape_codes

    fn strip_ansi_escape_codes(text : String) -> String

    The visible part of text minus ANSI CSI sequences (ninja's StripAnsiEscapeCodes).

    win32_escape

    fn win32_escape(input : String, out : StringBuilder) -> Unit

    Port of GetWin32EscapedString: quotes a path for CommandLineToArgvW when it contains a space or a double quote, doubling the backslashes that precede a quote or the closing quote.