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:
objectWrite a
ninjarules 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
ninjarules file, using the specified linewidth.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 PythonTextIOobject.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.
- variable(name: str, value: Union[str, Sequence[Optional[str]]]) None[source]¶
Create a global
ninjavariable with some stringnameand someningen.value.Valuevalue.
- pool(name: str, depth: int) None[source]¶
Create a
ninjaexecution pool with some stringnameand some integerdepth.
- 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
ninjarule with some stringnameand someningen.value.Valuecommand.See the
ninjadocumentation 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
ninjabuild statement for someningen.value.Valueoutputsusing some namedrule.If
overrideisTrue, 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 theninjabuild file, regardless of the value ofoverride.See the
ninjadocumentation for the semantics of the arguments.