Search code examples
pythonbuildwaf

Using waf, how can I refer to a file in build directory as input to another build command?


I'm using waf as the build system for my project and I need to execute two consecutive shell commands during build process, in which output file from first command should be given as an input file at command-line to second command. According to waf book, general template for executing OS commands looks like this:

bld(rule='cp ${SRC} ${TGT}', source='input.txt', target='output.txt')

Using this template, the target directory will be automatically prepended to target file. But it's not clear how to refer to that file as an input file in later commands.

Linux OS, Python version 2.7, waf version 1.8.9

How can this be done?


Solution

  • Usually you just have to use the target file. Most WAF tools try to first find a file in the build directory and in the source directory. If not found it's something to build. So you can do:

    rule = 'cp ${SRC} ${TGT}'
    
    bld(rule=rule, source='input.txt', target='output.txt')
    bld(rule=rule, source='output.txt', target='output2.txt')
    

    And you will get something like:

    [1/2] output.txt: input.txt -> build/output.txt
    [2/2] output2.txt: build/output.txt -> build/output2.txt
    

    WAF looks for relative paths from build and source directory.