Stop make if find -exec returns non-zero

I am trying to integrate my code check with pyflakes into the build process. I defined the following goal in my Makefile :

 pyflakes: find $(APPLICATION_DIRECTORY) -iname "*.py" -exec pyflakes "{}" \; 

The problem is that find returns 0 every time, even if there are problems with the code ( pyflakes returns not 0 ), and make succeeds. Ideally, I want to run a check on each source file and stop make if at least one of -exec fails. Is there any way to achieve this?

+6
source share
3 answers

I assume that there is no way to make find the return code -exec .
What should work is piping up to xargs :

 find $(APPLICATION_DIRECTORY) -iname "*.py" |xargs -I file pyflakes file 
+4
source

You can simply pass the find output to your own processing loop and exit when pyflakes returns an exit status other than 0.

 find . -iname '*.jpg' | \ while read line ; do pyflakes "$line" res=$? if [ $res -ne 0 ] ; then exit $res fi done 
+3
source

Complete the search process

 pyflakes: find $(APPLICATION_DIRECTORY) -iname "*.py" -exec bash -c 'pyflakes {}; if [[ $$? != 0 ]]; then kill -INT $$PPID;fi' \; 

This is what is included in the make file, it is not a script file if you are wondering about the syntax.

+1
source

Source: https://habr.com/ru/post/922248/


All Articles