/Ninju

Ninju is a ninja build files generator

Primary LanguagePython

Ninju

FOSSA Status

Ninju is a ninja build files generator.

This is a WIP (work in progress) project.

Getting Started

Ninju provides a simple way to generate ninja build files. What makes Ninju different is that it focused on:

  • Specifying input, build command, and output.
  • Intermediate filenames can be generated automatically.

Example:

n = Ninju()
src = n.dir('src')
n.cmd('cmd1', 'bin1', '${in} ${out}')
n.cmd('cmd2', 'bin2', '${in} ${out}')
n.cmd('cmd3', 'bin3', '${in} ${out}')

# Specify the input and output
input = src('a.txt')
output = n.builddir('b.txt')

# Create the pipeline to generate output from input file
input.cmd1().cmd2().cmd3(output)

Multiple output

n = Ninju()
src = n.dir('src')
n.cmd('cmd1', 'bin1', '${in} ${out}')
n.cmd('cmd2', 'bin2', '${in} ${out}')
n.cmd('cmd3', 'bin3', '${in} ${out}')

a = src('a.txt')

# Creates two outputs
b = a.cmd1(outputs=2)

# Using two inputs
c = b.cmd2()

Using multiple output from different commands as input

n = Ninju()
src = n.dir('src')
n.cmd('cmd1', 'bin1', '${in} ${out}')
n.cmd('cmd2', 'bin2', '${in} ${out}')
n.cmd('cmd3', 'bin3', '${in} ${out}')

a = src('a.txt')
b = src('b.txt')
c = a.cmd1()
d = b.cmd2()
e = n.files(c, d).cmd3()

Documentation

Reserved

  • File names that are generated automatically by Ninju have .ninju_ prefix and created in $builddir. So avoid using that prefix.
  • The configure command is reserved for generating ninja build file.
  • The ninja build file target (defaulted to ${root}/build.ninja) is reserved

Inputs

Each input must be specified using directory function. This is needed to provide build commands as attribute.

n = Ninju()
src = n.dir('src')
n.cmd('copy', 'cp', '${in} ${out}')

# Correct
a = src('a.txt')
a.copy('${builddir}/b.txt')

# Error
a = '${root}/src/a.txt'
a.copy('${builddir}/b.txt')

Build Commands

Build commands are specified using cmd method of Ninju object. Each command will be available as a method of file object (see also Files section). Variables that are available in build commands is the same as in Ninja

n = Ninju()
n.cmd('copy', 'cp', '${in} ${out}', description='Copy file')

Files

Build command can only be executed as a method of a files object. Files object are path(s) specification that can be created using one of the following:

  • Ninju.root
  • Ninju.builddir
  • Ninju.files
  • Directory functions generated by Ninju.dir method
  • Result of build commands executed from another file object
n = Ninju()
src = n.dir('src')
n.cmd('copy', 'cp', '${in} ${out}')

# a, b, c, d, and e are all files object
a = n.root('file.txt')
b = n.builddir('file.txt')
c = n.files('${root}/file1.txt', '${root}/file2.txt')
d = src('file.txt')
e = d.copy('${root}/file3.txt')

Provided Variables

  • $root: the root directory where the taskfile located

API

Ninju

cmd()

Parameter Type Default Description
name* string
executable* string
args string
description string
depfile string
generator bool False
pool "console",1,2,...
restat bool False
rspfile string
rspfile_content string
deps "gcc","msvc"

Target

A Target is created using Ninju.target(). Target have the following methods.

Method <exec_cmd_name>

Parameter Type Default Description
inputs Files
variables dict

Method phony

Parameter Type Default Description
inputs* Files

License

FOSSA Status