Skip to main content

Ninja Build Generation

Project description

Documentation Status

This package allows a Python script to use file system operations (such as glob) and/or apply any other logic (such as reading structured configuration files) to generate a build.ninja file.

This isn’t intended to replace “high level” build systems such as cmake. Rather, think of it as replacing the clunky GNU make language with Python.

Yes, ninja does provide the ninja_syntax module which already does this. The added value of ningen is:

  • Convenience functions for pattern-based build file generation.

  • Allow overriding build statements (which complements the pattern-based approach).

Installation

Just pip install ningen (or the equivalent in whatever Python environment you are using).

Usage

The Writer class is similar to the one in ninja_syntax. Two additional utility functions are provided: foreach for iterating on all combinations of several variables, possibly extracting them from existing file names; and expand for generating formatted strings using all the variable combinations.

For example:

import ningen as ng

# Similarly to ninja_syntax writer, but internally buffers everything:
writer = ng.Writer()

modes = ['debug', 'release']
objects = []
writer.rule('compile_debug', ...)
writer.rule('compile_release', ...)

# Ningen provides the "foreach" function,
# which iterates on existing files and/or variable values:
for c in ng.foreach('src/{*name}.cc', mode=modes):
    objects.append(name)
    writer.build(f'obj/{c.mode}/{c.name}.o', f'compile_{c.mode}',
                 inputs=[c.path, ...], ...)

# Since it buffers the data, ningen allows overriding previous build statements:
writer.rule('special_compile_debug', ...)
writer.build('obj/debug/special.o', 'special_compile_gcc',
             inputs=['src/special.cc', ...], ..., override=True)

# Ningen also provides the "expand" function which formats multiple strings:
for mode in modes:
    writer.build('bin/{mode}/program', f'link_{mode}',
                 inputs=ng.expand('obj/{mode}/{object}.o',
                                  mode=mode, object=objects))

# Actually write the buffered ninja build file (by default, to "build.ninja"):
writer.write()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ningen-0.4.0.tar.gz (13.4 kB view details)

Uploaded Source

File details

Details for the file ningen-0.4.0.tar.gz.

File metadata

  • Download URL: ningen-0.4.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.12.0 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for ningen-0.4.0.tar.gz
Algorithm Hash digest
SHA256 553401926f634679b2ab3cab857b0c670e69564c2dd6bdb48667c2a54d2586f7
MD5 e407653c05e3eb0e1d7b31c9346e3fd3
BLAKE2b-256 4869e04def032c2f5f304eb51e764003a9efa4693c587a5daf38db7670f0e1ee

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page