Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop make if find -exec returns not zero

I'm trying to integrate checking my code using pyflakes into a building process. I've defined the following target in my Makefile:

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

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

like image 613
eigenein Avatar asked Aug 06 '12 21:08

eigenein


3 Answers

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

find $(APPLICATION_DIRECTORY) -iname "*.py" |xargs -I file pyflakes file 
like image 104
tzelleke Avatar answered Oct 05 '22 21:10

tzelleke


You can just pipe the output of find 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
like image 33
Kim Stebel Avatar answered Oct 05 '22 21:10

Kim Stebel


Make it end the find process by

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

This is what goes into the makefile, it is not a script file, if you wonder about the syntax.

like image 34
pizza Avatar answered Oct 05 '22 21:10

pizza