A cloning scheme is provided for duplicating task generators for several variants easily. A general design pattern is to duplicate the task generators for the desired variants immediately before the build starts. Here is an example, also available in the folder demos/cxx of the Waf distribution.
srcdir = '.'
blddir = 'build'
import Options
def set_options(opt):
opt.add_option('--build_kind', action='store', default='debug,release', help='build the selected variants')
def configure(conf):
for x in ['debug', 'release']:
env = conf.env.copy()
env.set_variant(x)
conf.set_env_name(x, env)
def build(bld):
bld(rule='touch ${TGT}', target='foo.txt')
for obj in bld.all_task_gen[:]:
for x in ['debug', 'release']:
cloned_obj = obj.clone(x)
kind = Options.options.build_kind
if kind.find(x) < 0:
cloned_obj.posted = True
obj.posted = True
Add a command-line option for enabling or disabling the release and debug builds | |
The configuration will create the release and debug configuration sets, bound to a variant of the same names | |
Targets are declared normally for the default variant | |
A copy of the existing task generators is created to avoid the creation of an infinite loop (new task generator instances get added to that list) | |
Clone a task generator for the configuration set debug or release. Making task generator clones is a cheap operation compared to duplicating tasks. | |
Look at the command-line arguments, and disable the unwanted variant(s) | |
Disable the original task generator for the default configuration set (do not use it). |
Some task generators are use indexed attributes to generate unique values which may cause unnecessary rebuilds if the scripts change. To avoid problems, it is a best practice to create the task generators for the default configuration set first. Also, the method clone is not a substitute for creating instances for lots of nearly identical task generators. In such a situation, it will be better to use one task generator to create lots of tasks. As a reminder, creating task generator clones for the same variant will lead to build errors.
![]() | Warning |
|---|---|
| Do not create task generator clones for the same variant or for the same configuration set. |