Question

How do I mark a rule in Waf such that the build doesn't stop on that rule's failure?

ex.

bld(rule="magicalcommand {SRC} {TGT}", source="somefile", target="othersuchfile")

where magicalcommand may somehow fail (but it's okay for that command to fail).

Was it helpful?

Solution

Solved it by turning the rule from a string into a function with the actual execution call wrapped into a try/except block:

def somefunc(task):
    # set up the command string using task.inputs, task.outputs [, and task.env]
    cmd = 'magicalcommand ' + task.inputs[0].abspath() + ' ' + task.outputs[0].abspath()
    try:
        return bld.cmd_and_log(cmd)
    except Exception as e:
        from waflib import Logs
        Logs.info('cmd failed!')
        return 0

bld(rule=somefunc, source='somefile', target='othersuchfile')

Note that I'm using bld.cmd_and_log, not bld.exec_command. The former actually throws on error (and supposedly supplies access to the stdout and stderr of the command through e on failure), the latter just kills the entire build process for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top