User functions may be bound to be executed at two key moments during the build command (callbacks):
Here is how to execute a test after the build is finished:
srcdir = '.'
blddir = 'build'
def set_options(ctx):
ctx.add_option('--exe', action='store_true', default=False,
help='execute the program after it is built')
def configure(ctx):
pass
def pre(ctx):
print("before the build is started")
def post(ctx):
import Options, Utils
if Options.options.exe:
Utils.exec_command('/sbin/ldconfig')
def build(ctx):
ctx.add_pre_fun(pre)
ctx.add_post_fun(post)
The callbacks take the build context as unique parameter ctx | |
Access to the command-line options | |
A common scenario is to call ldconfig after the files are installed. | |
Scheduling the functions for later execution. Remember that in Python, functions are objects too. |
Upon execution, the following output will be produced:
$ waf distclean configure build --exe
'distclean' finished successfully (0.002s)
'configure' finished successfully (0.001s)
Waf: Entering directory `/tmp/smallproject/build'
before the build is started
Waf: Leaving directory `/tmp/smallproject/build'
hello
'build' finished successfully (0.008s)