Title: Theory / Important / CS / Programming / Build / Ninja

Name: Ninja
Definition: a small build system with a focus on speed
Page: https://ninja-build.org/
Context: google

Question: What makes Ninja different
Answer: designed to have its input files generated by a higher-level build system
Page: https://ninja-build.org/
Context: Ninja
Answer2: have very simple rules, quick to execute

Extension: .ninja
Means: ninja build system rules
Other fields (not shown on cards):
Page: https://ninja-build.org/

Question: How does ninja treat change in compilation flag
Answer: it is treated as a change in dependency and cause output to rebuild
Page: https://ninja-build.org/

Question: How does ninja deal with parallelism
Answer: uses as much core as available
Page: https://ninja-build.org/
Answer2: buffer all output, and print at the end of a compilation rule. So that they don't get intermixed with other compilation output

Question: What system generates ninja file
Answer: gn
Page: https://ninja-build.org/
Answer2: CMake

Instruction: ninja -t query target
Page: https://ninja-build.org/
Returns: dump the inputs and outputs of target

Instruction: ninja -t browse
Page: https://ninja-build.org/
Language: sh
Context: ninja
Returns: browse the dependency graph of the build system in a browser

Fla: -t graph
Page: https://ninja-build.org/
Prefix: ninja
Print: dependency graph in graphviz language

Fla: -t targets
Page: https://ninja-build.org/
Prefix: ninja
Print: output a list of targets, depending on the options

Fla: -t command target1 ... targetn
Page: https://ninja-build.org/
Prefix: ninja
Print: list of commands which, if
executed in order, may be used to rebuild target1 ..., targetn assuming all output files are out of date

Fla: -t clean
Page: https://ninja-build.org/
Prefix: ninja
Print: remove all build file except for those created by the generator

Fla: -g
Page: https://ninja-build.org/
Prefix: ninja -t clean
Context: ninja
Print: also cleans files created by the generator

Fla: -t cleandead
Page: https://ninja-build.org/
Prefix: ninja
Print: remove files  produced by previous builds that are no longer in the build file

Fla: -t compdb
Page: https://ninja-build.org/
Prefix: ninja
Print: given a list of rules, each of which is expected to be a C family language compiler rule whose first input is the name of the source file, prints on standard output a compilation database in the JSON format expected by the Clang tooling interface

Fla: -t deps
Page: https://ninja-build.org/
Prefix: ninja
Print: all dependencies stored in the .ninja_deps file

Fla: -t deps target
Page: https://ninja-build.org/
Prefix: ninja
Print: the dependencies of target stored in the .ninja_deps file

Fla: -t recompact
Effect: recompact the .ninja_deps file
Page: https://ninja-build.org/
Prefix: ninja

Fla: -t restat
Effect: updates all recorded file modification timestamps in the .ninja_log file
Page: https://ninja-build.org/
Prefix: ninja

Fla: -t rules
Page: https://ninja-build.org/
Prefix: ninja
Print: the list of all rules (eventually with their description if they have one)

Name: A ninja file
Definition: a list of rules
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja
Definition2: a list of build statements

Name: A rule
Definition: short names for longer commands
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja
Example: how to run the compiler

Name: Build statement
Definition: how to build files
using the rules
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja

Name: The graph of a ninja file
Definition: rules as node
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja
Definition2: build statement as label of edges between node
DefType: Graph with

Instruction: var = value
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja
Identifier: var
Initialization: value

Instruction: $var
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja
Returns: the value assigned to var

Instruction: build outputs: rulename inputs
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Effect: when ninja must compile outputs, it applies rulename to inputs
Context: ninja

Instruction: build outputs: rulename
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Effect: generate outputs exactly once. Never rebuild
Context: ninja

Instruction: build outputs: phony
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Effect: todo? (rewrite in doc)
Context: ninja

Instruction: default target1 ... target_n
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Effect: add target1 ... and target_n to the list of default target
Context: ninja

Instruction: ninja
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Effect: build all default targets (or all targets that are not input if there is no explicit default target)
Language: sh

Variable: .ninja_log
Meaning: log indicating how each build files were compiled
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja

Question: How does ninja knows when to recompute
Answer: Either when an input changed
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja
Answer2: when the line to compile differs than the one that was used last time (according to .ninja_log), except if this rule uses the keyword generator

Variable: ninja_required_version
Meaning: The minimal ninja version that must be used to compile this file
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja

Question: What occurs if the current major is higher than ninja_required_version's major version
Answer: A warning
Page: https://projects.eclipse.org/projects/asciidoc.asciidoc-lang
Context: ninja

Question: How does Ninja ensures that you can actually build your code in parallel
Answer: By using Ninja from the start, you build in parallel from the start. This ensures that you quickly detect any parallelism issue
Page: http://neugierig.org/software/blog/2020/05/ninja.html
Context: ninja

Question: What is the main metric Ninja optimizes
Answer: Incremental build time
Page: http://neugierig.org/software/blog/2020/05/ninja.html
Context: ninja

Variable: depfile
Meaning: A file written by gcc/clang during compilation that list the header dependencies found by the compiler
Page: https://ninja-build.org/manual.html
Context: ninja rule

Instruction: deps = gcc
Page: https://ninja-build.org/manual.html
Effect: specifies that the tool outputs gcc-style dependencies in the form of Makefiles
Context: ninja rule

Instruction: deps = msvc
Page: https://ninja-build.org/manual.html
Effect: specifies that the tool outputs header dependencies in the form produced by Visual Studio’s compiler’s /showIncludes flag
Context: ninja rule

Instruction: pool = foo
Page: https://ninja-build.org/manual.html
Effect: Indicate to uses pool foo
Context: ninja rule

Instruction: pool name
  depth  = n
Page: https://ninja-build.org/manual.html
Meaning: at most n rules using this pool will be executed at a time
Context: ninja rule
Identifier: name

Variable: console
Meaning: a pool of one, that has access to console input and output
Page: https://ninja-build.org/manual.html
Context: ninja

Instruction: $<space>
Page: https://ninja-build.org/manual.html
Context: ninja
Returns: a space that does not break lexing. E.g. in file name

Instruction: $:
Page: https://ninja-build.org/manual.html
Context: ninja
Returns: A colon that do not break lexing (e.g. to ensure it is not interpreted as terminating a list of output)

Instruction: $$
Page: https://ninja-build.org/manual.html
Context: ninja
Returns: A $

Instruction: $<newline>
Page: https://ninja-build.org/manual.html
Effect: ignored. Allow to use newline in actual text while not being considered as a newline by parser
Context: ninja

Variable: description
Meaning: a short description of the command, used to pretty-print
the command as it’s running
Page: https://ninja-build.org/manual.html
Context: ninja

Variable: dyndep
Meaning: If present, must name one of the build statement inputs.
Page: https://ninja-build.org/manual.html
Context: ninja build statement

Variable: generator
Meaning: specifies that this rule is used to
re-invoke the generator program.
Page: https://ninja-build.org/manual.html
Context: ninja build

Variable: in
Meaning: the space-separated list of files provided as inputs to the build line referencing this rule, shell-quoted if it appears in commands.
Page: https://ninja-build.org/manual.html
Context: ninja build

Variable: in_newline
Meaning: the newline-separated list of files provided as inputs to the build line referencing this rule, shell-quoted if it appears in commands.
Page: https://ninja-build.org/manual.html
Context: ninja build

Variable: out
Meaning: the space-separated list of files provided as outputs to the build line referencing this rule, shell-quoted if it appears in commands.
Page: https://ninja-build.org/manual.html
Context: ninja build

Variable: restat
Meaning: if present, causes Ninja to re-stat the command’s outputs
after execution of the command. Each output whose modification time
the command did not change will be treated as though it had never
needed to be built. This may cause the output’s reverse
dependencies to be removed from the list of pending build actions.
Page: https://ninja-build.org/manual.html
Context: ninja build

Variable: rspfile
Meaning: file in which rspfile_content should be written before applying build rule and to delete afterward
Page: https://ninja-build.org/manual.html
Context: ninja build

Variable: rspfile_content
Meaning: write this text in file before executing build rule
Page: https://ninja-build.org/manual.html
Context: ninja build

Question: What is the most usual cause of "invalid parameter" on windows?
Answer: command line is too long and can't be executed by windows
Page: https://ninja-build.org/manual.html
Context: ninja build

Instruction: | out1 ... out_n
Page: https://ninja-build.org/manual.html
Effect: same as standard build output, except they are not listed in $out
Context: ninja build
Name: implicit output