Error while running parallel make

余生长醉 提交于 2019-12-10 09:29:39

问题


Consider following make:

all: a b

a:
        echo a
        exit 1


b:
        echo b start
        sleep 1
        echo b end

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

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.


回答1:


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 $?

The echo will print 0 if anything was ok and will print something else if it wasn't.

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

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.

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.




回答2:


What you're seeing is that the output of both these tasks are independent. So, if you're running 5 tasks in parallel, and 3 of them gave errors, they may very well be interspersed by output of the other tasks.

The best thing to do is run a set of serial tasks together, send their error output into a file... and print it to screen when exiting.

P.S. - Also, never use exit 1 in a task unless there absolutely is an error!



来源:https://stackoverflow.com/questions/10971615/error-while-running-parallel-make

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!