gpt4 book ai didi

生成文件 : --ignore-errors vs --keep-going

转载 作者:行者123 更新时间:2023-12-04 11:43:03 29 4
gpt4 key购买 nike

我正在经历Makefile documentation ,我不清楚--ignore-errors的区别和 --keep-going .

有人可以强调两者之间的区别吗?对我来说,两者似乎在发生错误后都会继续。

虽然文档中不清楚,但 --ignore-errors可以有配方级别的范围,如果一个配方行失败,下一个将继续执行。 --keep-going可能具有目标级范围,如果任何目标配方失败,配方执行将在那里结束,但仍将尝试创建其他先决条件/目标。这只是一种可能的看法,需要对此进行澄清。

最佳答案

https://www.gnu.org/software/make/manual/make.html#Errors

Sometimes the failure of a certain recipe line does not indicate a problem. For example, you may use the mkdir command to ensure that a directory exists. If the directory already exists, mkdir will report an error, but you probably want make to continue regardless.

To ignore errors in a recipe line, write a - at the beginning of the line’s text (after the initial tab). The - is discarded before the line is passed to the shell for execution.

For example,

clean:
-rm -f *.o

This causes make to continue even if rm is unable to remove a file.

When you run make with the -i or --ignore-errors flag, errors are ignored in all recipes of all rules. A rule in the makefile for the special target .IGNORE has the same effect, if there are no prerequisites. These ways of ignoring errors are obsolete because - is more flexible.



换句话说, make --ignore-errors行为就像有一个 -在所有命令之前。

When errors are to be ignored, because of either a - or the -i flag, make treats an error return just like success, except that it prints out a message that tells you the status code the shell exited with, and says that the error has been ignored.

When an error happens that make has not been told to ignore, it implies that the current target cannot be correctly remade, and neither can any other that depends on it either directly or indirectly. No further recipes will be executed for these targets, since their preconditions have not been achieved.

Normally make gives up immediately in this circumstance, returning a nonzero status. However, if the -k or --keep-going flag is specified, make continues to consider the other prerequisites of the pending targets, remaking them if necessary, before it gives up and returns nonzero status. For example, after an error in compiling one object file, make -k will continue compiling other object files even though it already knows that linking them will be impossible. See Summary of Options.

The usual behavior assumes that your purpose is to get the specified targets up to date; once make learns that this is impossible, it might as well report the failure immediately. The -k option says that the real purpose is to test as many of the changes made in the program as possible, perhaps to find several independent problems so that you can correct them all before the next attempt to compile. This is why Emacs’ compile command passes the -k flag by default.



让我们以这个例子为例:
target: intermediate-1 intermediate-2 intermediate-3
cat intermediate-1 intermediate-2 intermediate-3 > target

intermediate-1:
echo "oh no, I'm failing!"
false

intermediate-2:
echo 'hello' > intermediate-2

intermediate-3:
echo 'world' > intermediate-3

通常当你运行时 make target (并且还没有任何文件存在),它将首先尝试制作 intermediate-1 .该目标失败,因为相关命令之一 ( false ) 返回非零退出状态。 make然后立即放弃甚至不看 intermediate-2intermediate-3 .

但是,与 make --keep-going target ,它会注意到 intermediate-1 的失败,但继续制作 intermediate-2intermediate-3 , 成功(分别创建包含“hello”和“world”的文件)。

最后还是放弃,报错 target ,但它已尝试创建所有中间目标,即使它知道不会在 make 的运行中使用的那些。因为另一个先决条件已经失败。

如果您同时使用两个标志( make --ignore-errors --keep-going ),则 --keep-going被有效地忽略。 --keep-going只影响如何 make在中间目标中遇到错误时的行为,但 --ignore-errors意味着 make永远不会遇到错误。

关于生成文件 : --ignore-errors vs --keep-going,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53039550/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com