ningen.writer module

Write ninja files.

This is similar to a ninja_syntax.Writer, but allows for overriding the build statement for targets, which makes it easier to use in a pattern-based generation policy.

class ningen.writer.Writer[source]

Bases: object

Write a ninja rules file using arbitrary logic (including querying the file system).

write(*, output: Union[str, TextIO] = 'build.ninja', width: int = 120) None[source]

Actually write the collected rules into the ninja rules file, using the specified line width.

If the output (default: "build.ninja") is a string, it is the name of a disk file to create and write into. Otherwise, it can be any Python TextIO object.

Note

Deferring writing the rules to the last moment allows us to provide additional functionality. Specifically it allows overriding “default” build statements with more specific ones.

comment(text: str) None[source]

Create a global ninja comment with some string text.

variable(name: str, value: Union[str, Sequence[Optional[str]]]) None[source]

Create a global ninja variable with some string name and some ningen.value.Value value.

pool(name: str, depth: int) None[source]

Create a ninja execution pool with some string name and some integer depth.

rule(name: str, command: Union[str, Sequence[Optional[str]]], *, description: Optional[Union[str, Sequence[Optional[str]]]] = None, depfile: Optional[str] = None, deps: Optional[str] = None, generator: bool = False, pool: Optional[str] = None, restat: bool = False, rspfile: Optional[str] = None, rspfile_content: Optional[Union[str, Sequence[Optional[str]]]] = None) None[source]

Create a ninja rule with some string name and some ningen.value.Value command.

See the ninja documentation for the semantics of the arguments.

build(outputs: Union[str, Sequence[Optional[str]]], rule: str, *, override: bool = False, inputs: Optional[Union[str, Sequence[Optional[str]]]] = None, implicit: Optional[Union[str, Sequence[Optional[str]]]] = None, order_only: Optional[Union[str, Sequence[Optional[str]]]] = None, implicit_outputs: Optional[Union[str, Sequence[Optional[str]]]] = None, **variables: Union[str, Sequence[Optional[str]]]) None[source]

Create a ninja build statement for some ningen.value.Value outputs using some named rule.

If override is True, then this build statement will override any previous build statement(s) that were specified for any of the output(s), by simply removing them from the previous build statement(s) (if a build statement has no outputs left, it is simply ignored).

This allows specifying generic default build statements for a set of targets, followed by specialized build statements for some special subset of the targets, without having to worry about “multiple rules may be used to generate” errors.

Note

Overriding only works if using the exact same output file name. That is, if you have one build statement for "./foo" and another for "foo", then the code will not understand that these refer to the same file and will pass both to the ninja build file, regardless of the value of override.

See the ninja documentation for the semantics of the arguments.

include(path: str) None[source]

Create a ninja include statement for some string path.

subninja(path: str) None[source]

Create a ninja subninja statement for some string path.