【问题标题】:Make ignore errors: what is the difference between -i and -k忽略错误:-i 和 -k 有什么区别
【发布时间】:2019-05-22 06:37:09
【问题描述】:

我希望 make 即使依赖项的构建失败也能继续。我通常使用-i 来完成此操作。我的一位同事说他使用-k。事实上,这个堆栈溢出问题对每个问题都有一个答案:

Make: how to continue after a command fails?

这两个选项有区别吗?

make 手册页对这两个选项的说明如下:

   -i, --ignore-errors
        Ignore all errors in commands executed to remake files.

   -k, --keep-going
        Continue as much as possible after an error.  While the 
        target that failed, and those that depend on it, cannot be 
        remade, the  other  dependencies of these targets can be 
        processed all the same.

-k 描述的是我认为-i 所做的。我确定我遗漏了一些东西:有人可以帮我理解其中的区别吗?

【问题讨论】:

    标签: makefile


    【解决方案1】:

    考虑这个makefile:

    all: fail success
    
    all success:
            @echo $@
    
    fail:
            exit 1
            @echo $@
    

    现在使用两个标志运行:

    $ make -i
    exit 1
    make: [Makefile:7: fail] Error 1 (ignored)
    fail
    success
    all
    

    这个标志导致 make 假装一个特定的配方命令成功,即使它失败了。因此all 目标仍在运行,因为make 认为fail 目标实际上成功了。这相当于在每个配方行的开头添加-

    相对于:

    $ make -k
    exit 1
    make: *** [Makek:7: fail] Error 1
    success
    make: Target 'all' not remade because of errors.
    

    在这里,make 知道fail 目标未构建。 success 运行是因为 -k:它不依赖于 fail。但是,all 未构建,因为它确实依赖于 fail

    我从来没有真正需要过-i;这对我来说似乎很危险。

    另一方面,我几乎默认使用-k

    【讨论】:

    • 手册还在5.5 Errors in Recipes 中说-i--ignore-errors 标志或特殊目标.IGNORE 已过时(尽管make 并没有以任何方式抱怨它)。
    • 很好的例子。这很好地展示了这两个选项。谢谢。
    • make -i check 在不间断地运行多个测试时很有用
    猜你喜欢
    • 2011-03-21
    • 2021-08-25
    • 2021-12-30
    相关资源
    最近更新 更多