运行并行make时出错 [英] Error while running parallel 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.
有没有办法使错误消息也出现在make执行的 end 中?
Is there a way for error message to appear also just in the end of the make execution?
更新:
请参阅我可能的解决方案如何检查make出口状态.
See my possible solution how to check make exit status from within make.
推荐答案
如果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 $?
如果一切正常,回声将打印0
,否则将打印其他内容.
The echo will print 0
if anything was ok and will print something else if it wasn't.
您还可以从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屋!