Task generators
The class waflib.TaskGen.task_gen encapsulates the creation of task objects (low-level code) The instances can have various parameters, but the creation of task nodes (Task.py) is always postponed. To achieve this, various methods are called from the method “apply”
remember the methods declaring features
Bases: object
Instances of this class create waflib.Task.TaskBase when calling the method waflib.TaskGen.task_gen.post() from the main thread. A few notes:
The task generator objects predefine various attributes (source, target) for possible processing by process_rule (make-like rules) or process_source (extensions, misc methods)
The tasks are stored on the attribute ‘tasks’. They are created by calling methods listed in self.meths or referenced in the attribute features A topological sort is performed to ease the method re-use.
The extra key/value elements passed in kw are set as attributes
List of method names to execute (it is usually a good idea to avoid touching this)
Precedence table for sorting the methods in self.meths
List of mappings {extension -> function} for processing files by extension
List of feature names for bringing new methods in
List of tasks created.
If not set, the name is computed from the target name:
def build(bld):
x = bld(name='foo')
x.get_name() # foo
y = bld(target='bar')
y.get_name() # bar
Return type: | string |
---|---|
Returns: | name of this task generator |
If not set, the name is computed from the target name:
def build(bld):
x = bld(name='foo')
x.get_name() # foo
y = bld(target='bar')
y.get_name() # bar
Return type: | string |
---|---|
Returns: | name of this task generator |
Ensure that a parameter is a list
Parameters: | val (string or list of string) – input to return as a list |
---|---|
Return type: | list |
Create task objects. The following operations are performed:
Parameters: | node (waflib.Tools.Node.Node) – Input file to process |
---|---|
Returns: | A method able to process the input node by looking at the extension |
Return type: | function |
Wrapper for creating task objects easily
Parameters: |
|
---|---|
Returns: | A task object |
Return type: |
Make a copy of a task generator. Once the copy is made, it is necessary to ensure that the task generator does not create the same output files as the original, or the same files may be compiled twice.
Parameters: | env (waflib.ConfigSet.ConfigSet) – A configuration set |
---|---|
Returns: | A copy |
Return type: | waflib.TaskGen.task_gen |
Process the dbus files stored in the attribute dbus_lst to create waflib.Tools.dbus.dbus_binding_tool instances.
Process the enum files stored in the attribute enum_list to create waflib.Tools.glib2.glib_mkenums instances.
Process the marshal files stored in the attribute marshal_list to create waflib.Tools.glib2.glib_genmarshal instances. Add the c file created to the list of source to process.
Create a new mapping and a task class for processing files by extension. See Tools/flex.py for an example.
Parameters: |
|
---|
Decorator: register a method as a task generator method. The function must accept a task generator as first parameter:
from waflib.TaskGen import taskgen_method
@taskgen_method
def mymethod(self):
pass
Parameters: | func (function) – task generator method to add |
---|---|
Return type: | function |
Decorator: register a task generator method that will be executed when the object attribute ‘feature’ contains the corresponding key(s):
from waflib.Task import feature
@feature('myfeature')
def myfunction(self):
print('that is my feature!')
def build(bld):
bld(features='myfeature')
Parameters: | k (list of string) – feature names |
---|
Decorator: register a task generator method which will be executed before the functions of given name(s):
from waflib.TaskGen import feature, before
@feature('myfeature')
@before_method('fun2')
def fun1(self):
print('feature 1!')
@feature('myfeature')
def fun2(self):
print('feature 2!')
def build(bld):
bld(features='myfeature')
Parameters: | k (list of string) – method names |
---|
Decorator: register a task generator method which will be executed before the functions of given name(s):
from waflib.TaskGen import feature, before
@feature('myfeature')
@before_method('fun2')
def fun1(self):
print('feature 1!')
@feature('myfeature')
def fun2(self):
print('feature 2!')
def build(bld):
bld(features='myfeature')
Parameters: | k (list of string) – method names |
---|
Decorator: register a task generator method which will be executed after the functions of given name(s):
from waflib.TaskGen import feature, after
@feature('myfeature')
@after_method('fun2')
def fun1(self):
print('feature 1!')
@feature('myfeature')
def fun2(self):
print('feature 2!')
def build(bld):
bld(features='myfeature')
Parameters: | k (list of string) – method names |
---|
Decorator: register a task generator method which will be executed after the functions of given name(s):
from waflib.TaskGen import feature, after
@feature('myfeature')
@after_method('fun2')
def fun1(self):
print('feature 1!')
@feature('myfeature')
def fun2(self):
print('feature 2!')
def build(bld):
bld(features='myfeature')
Parameters: | k (list of string) – method names |
---|
Decorator: register a task generator method which will be invoked during the processing of source files for the extension given:
from waflib import Task
class mytask(Task):
run_str = 'cp ${SRC} ${TGT}'
@extension('.moo')
def create_maa_file(self, node):
self.create_task('mytask', node, node.change_ext('.maa'))
def build(bld):
bld(source='foo.moo')
Task generator method
Convert the input list into a list of nodes. It is used by waflib.TaskGen.process_source() and waflib.TaskGen.process_rule(). It is designed for source files, for folders, see waflib.Tools.ccroot.to_incnodes():
Parameters: |
|
---|---|
Return type: | list of waflib.Tools.Node.Node |
Task generator method
Process each element in the attribute source by extension.
Feature : | all |
---|
Task generator method
Process the attribute rule. When present, waflib.TaskGen.process_source() is disabled:
def build(bld):
bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt')
Feature : | all |
---|---|
Before : | waflib.TaskGen.process_source() |
Task generator method
Add a strict sequential constraint between the tasks generated by task generators. It works because task generators are posted in order. It will not post objects which belong to other folders.
Example:
bld(features='javac seq')
bld(features='jar seq')
To start a new sequence, set the attribute seq_start, for example:
obj = bld(features='seq')
obj.seq_start = True
Note that the method is executed in last position. This is more an example than a widely-used solution.
Feature : | seq |
---|
Bases: waflib.Task.Task
Create .pc files from .pc.in. The task is executed whenever an input variable used in the substitution changes.
Process .pc.in files to .pc. Install the results to ${PREFIX}/lib/pkgconfig/
- def build(bld):
- bld(source=’foo.pc.in’, install_path=’${LIBDIR}/pkgconfig/’)
Task generator method
Define a transformation that substitutes the contents of source files to target files:
def build(bld):
bld(
features='subst',
source='foo.c.in',
target='foo.c',
install_path='${LIBDIR}/pkgconfig',
VAR = 'val'
)
The input files are supposed to contain macros of the form @VAR@, where VAR is an argument of the task generator object.
This method overrides the processing by waflib.TaskGen.process_source().
Feature : | subst |
---|---|
Before : | waflib.TaskGen.process_source(), waflib.TaskGen.process_rule() |