2 The Waf features are names linked to specific functions by the decorator
3 :py:func:`waflib.TaskGen.feature`. The functions
4 are mapped to the class :py:class:`waflib.TaskGen.task_gen` as methods.
6 The association between feature names and methods is *many-to-many*, which means
7 that a method may be involved in several features, and that a feature may be bound
10 Here is how to create and use a new feature named **foo**::
12 from waflib.TaskGen import feature
14 def print_hello(self):
15 print("Hello, World!")
17 The function *print_hello* is now associated with the :py:class:`waflib.TaskGen.task_gen` class, which means
18 that it may be used directly::
24 The method may be called directly, and several times. If a method creates task, the same tasks will be created
25 more than once, which may cause build errors. The *feature* attribute is used to have the associated
26 methods called *exactly once* before the build starts::
31 Here is a more complete example with two methods::
33 from waflib.TaskGen import feature, after_method
36 @after_method('print_bar')
37 def print_hello(self):
45 bld(features='foo bar')
47 The order of method execution is unrelated to the order of the features given. For instance,
48 this example will print "Hello, Bar!" then "Hello, Foo!". The decorators
49 :py:func:`waflib.TaskGen.after` and :py:func:`waflib.TaskGen.before` are
50 enforcing partial order constraints on the methods to execute.
52 The following maps represent the associations betwen feature methods (represented in yellow) and
53 methods associated to other feature names.