运行并行make时出错 [英] Error while runing parallel make
问题描述
请考虑以下make:
all: a b
a:
echo a
exit 1
b:
echo b start
sleep 1
echo b end
当运行它 make -j2
时,我收到以下输出:
While running it as make -j2
I receive the following output:
echo a
echo b start
a
exit 1
b start
sleep 1
make: *** [a] Error 1
make: *** Waiting for unfinished jobs....
echo b end
b end
我们有一个很大的make文件,很容易错过错误,因为在执行结束时没有错误信息。
We have quite a big make file and it's easy to miss error, since there's no error message at the end of execution.
是否有错误消息出现的方法只是在结束的执行?
Is there a way for error message to appear also just in the end of the make execution?
UPDATE:
See my possible solution how to check make exit status from within make.
推荐答案
如果任何程序被调用, code> make 返回一个错误, make
的返回码不会为零。因此,在调用 make
之后,您只需检查返回代码以查看是否发生错误。在 bash
(以及许多其他shell如 zsh
),您可以执行以下操作:
If any program called by make
returns with an error, the return code of make
will not be zero. So after calling make
you could just check the return code to see if an error occurred. On bash
(and many other shells like zsh
) you could do the following:
# make
....
# echo $?
echo将打印 0
您还可以从shell脚本中运行检查:
You could also run the check from inside a shell script:
make
if [ $? -eq 0 ]; then
echo "Everything OK"
else
echo "Something went wrong!"
fi
如果您需要确切的错误消息,最简单的方法是重定向输出 make
到某个文件, grep
则执行失败。
If you need the exact error message the easiest way is to redirect the output from make
to some file and grep
for the error if execution failed.
但是我通常这样做是并行运行 make
,并用 -j1
如果出错了,我会得到一个干净的错误信息。我想这可以放入一个shell脚本使用上面的技术。
But the way I usually do this is to run make
in parallel and re-execute it with -j1
if something went wrong so I will get a clean error message. I guess this could be put into a shell script using the technique above.
这篇关于运行并行make时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!