【问题标题】:Allowing a build target to fail in Waf允许构建目标在 Waf 中失败
【发布时间】:2013-10-04 02:47:27
【问题描述】:

如何在 Waf 中标记规则,以使构建不会因该规则失败而停止?

例如

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

magicalcommand 可能会以某种方式失败(但没关系该命令失败)。

【问题讨论】:

  • 与 waf 无关,但与一般的所有构建系统相关 - 您可以创建一个包装脚本,无论它的内容命令结果如何(甚至 magicalcommand || true 对于 nix 系统)都将返回 0。遗憾的是,这种方式不太便携。

标签: waf


【解决方案1】:

通过将规则从字符串转换为函数并将实际执行调用包装到 try/except 块中来解决它:

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')

请注意,我使用的是bld.cmd_and_log,而不是bld.exec_command。前者实际上会引发错误(并且据说在失败时通过e 提供对命令的stdoutstderr 的访问),后者只是为我杀死了整个构建过程。

【讨论】:

    猜你喜欢
    • 2012-04-21
    • 2012-05-03
    • 1970-01-01
    • 2021-12-03
    • 2017-10-16
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    相关资源
    最近更新 更多