New commands may be injected in the following manner:
import Scripting def foo(ctx): Scripting.commands += ['build', 'clean']
Injecting new commands is useful for writing testcases. By executing waf test, the following script will configure a project, create source files in the source directory, build a program, modify the sources, and rebuild the program. In this case, the program must be rebuilt because a header (implicit dependency) has changed.
VERSION = '0.0.1'
APPNAME = 'my_testcase'
srcdir = '.'
blddir = 'build'
import Scripting
def test(ctx):
Scripting.commands += ['distclean', 'configure', 'setup', 'build', 'modify', 'build']
def configure(conf):
conf.check_tool('gcc')
def setup(ctx):
f = open('main.c', 'w')
f.write('#include "foo.h"\nint main() {return 0;}\n')
f.close()
f = open('foo.h', 'w')
f.write('int k = 32;\n')
f.close()
def build(bld):
bld.new_task_gen(
features = 'cc cprogram',
source = 'main.c',
target='tprog')
def modify(ctx):
f = open('foo.h', 'w')
f.write('int k = 34;\n')
f.close()