craftr.ext.rules
¶
-
craftr.ext.rules.
alias
(*targets, target_name=None)[source]¶ Create an alias target that causes all specified “targets” to be built.
Parameters: - targets – The targets to create an alias for. You may pass None for an element, in which case it is ignored.
- target_name – Alternative target name.
-
craftr.ext.rules.
run
(commands, args=(), inputs=(), outputs=None, cwd=None, pool=None, description=None, target_name=None, multiple=False)[source]¶ This function creates a
Target
that runs a custom command. The function is three different modes based on the first parameter.- If commands is a
Target
, that target must list exactly one file in its outputs and that file is assumed to be a binary and will be executed by the target created by this function. The args parameter may be a list of additional arguments for the program. - If commands is a list, it is handled as a list of commands, never as a single command. Thus a string in the list represents a complete command, as does a list of strings (representing the command as its individual arguments).
- If commands is a string, it will be treated as a single command.
If multiple commands need to be invoked,
TargetBuilder.write_multicommand_file
is used to create a script to invoke multiple commands.__Examples__
main = ld.link( output = 'main', inputs = objects, ) run = rules.run(main, args = [path.local('testfile.dat')])
run = rules.run([ 'command1 args11 args12 args13', ['command2', 'args21', 'args22', 'args23'], ], cwd = path.local('test'), multiple=True)
Parameters: - commands – A
Target
, string or list of strings/command lists. - args – Additional program arguments when a
Target
is specified for commands. - inputs – A list of input files for the command. These can be
referenced using the Ninja variable
%in
in the command(s). - outputs – A list of outputs generated by the command. These
can be referenced using the Ninja variable
%out
in the command(s). - cwd – An optional working directory to switch to when executing the command(s). If None is passed, the build directory is used.
- pool – Override the default pool that the command is executed in.
If a
Target
is passed for commands, this will default toconsole
. - description – Optional target description displayed when building with Ninja.
- multiple – True if commands is a list of commands. This will cause a shell/batch script to be created and invoked by Ninja.
- target_name – An optional override for the return target’s name.
Returns: A
Target
.- If commands is a
-
craftr.ext.rules.
render_template
(template, output, context, env=None, target_name=None)[source]¶ Creates a
task()
that renders the file template using Jinja2 with the specified context to the output file.# craftr_module(my_project) import jinja2 from craftr import path from craftr.ext import rules # We can use the render_template() task factory to render # a Jinja2 template that outputs a linker script. ld_script = rules.render_template( template = path.local('my_project.ld.jinja2'), output = 'test.html', env = jinja2.Environment( variable_start_string = '{$', variable_end_string = '$}', ), context = dict( # Context variables here ) )
Parameters: - template – Filename of a Jinja template.
- output – Output filename.
- context – Context dictionary.
- env – A
jinja2.Environment
object. - target_name – Optional target name. Automatically deduced from the assigned variable if omitted.