rules – Build Rule Abstraction

rules provides two classes, Rule and rules.RuleCloth, which provide an additional layer of abstraction between the BuildCloth-described build system and the underlying Ninja or Make implementation.

rules provides a common interface for both Ninja and Make, but some Ninja functionality (i.e. restat rules) are not implemented for Make. Additionally, Rule only describes build rules and does not provide a common abstraction for describing build targets or dependencies.

class rules.Rule(name=None)

Rule() represents a build system rule, and provides an interface for constructing a rule.

cmd(cmd=None)

An alias for command().

command(cmd=None)
Parameters:cmd (list,str) – Optional. Specifies a command or sequence of commands that implement the build rule.
Returns:The command list of the Rule() object. If you do not specify a command, and the Rule() does not have a command, command() will return None.

Adds or appends cmd as a command list to the Rule() object.

Raises InvlaidRule if you do not specify a command list and the Rule() object doesn’t a command list.

depfile(dep=None)
Parameters:dep (string) – Optional. The path to a Makefile that contains dependencies
Returns:The current depfile.
Raises :InvalidRule if there is no depfile set for this rule.
description(des=None)
Parameters:des (string) – Optional. The text of the description message that the build job will pass to the user.
Returns:The current description.
Raises :InvalidRule if there is no description set for this rule.
msg(des=None)

An alias for description().

name(name=None)
Parameters:name (string) – Optional. Specifies a name of the rule.
Returns:The name of the Rule() object.

Sets the name of the Rule() object to name.

Raises InvlaidRule if you do not specify a name and the Rule() object doesn’t have a name.

restat()

Sets this rule as a restat rule. This only affects ninja output.

Returns:True.
rule()
Returns:A dictionary that contains the full build rule.
Raises :err.InvalidRule if you have not specified a name for the builder.
class rules.RuleCloth(output=None)

RuleCloth() provides an interoperable layer between rule objects created as rules.Rule() objects and build systems generated using MakefileCloth() and NinjaFileCloth.

_make(name, block='_all')

An internal method used by :~rules.RuleCloth.fetch() to process content from rules and return get_block() in Makefile format.

_ninja(name, indent=4, block='_all')

An internal method used by :~rules.RuleCloth.fetch() to process content from rules and return get_block() in Ninja format.

add(rule)
Parameters:rule (Rule) – A Rule object.
Raises :InvalidRule if the rule doesn’t have a name or if the rule already exists in rules.

Adds a Rule object to the RuleCloth object. Will not overwrite an existing rule.

fetch(name, block='_all')
Parameters:
  • name (string) – The name of the build rule in rules to return.
  • block (string) – Optional; defaults to _all. Specify the name of the block in builder to create and access.
Returns:

The output of get_block() for either Ninja or Makefiles, depending on name.

Raises :

InvalidBuilder when output is neither make nor ninja.

list_rules()
Returns:A list of a the names of all rules that exist in the RuleCloth object.
output = None

The default build system output format.

rules = None

The structure that represents build rules.