coccicheck: add support for DEBUG_FILE
[deliverable/linux.git] / scripts / coccicheck
index b2d758188f2f404b22c8c691b87d0e43a0404f5d..3f0bb3f0fddc56edabff70147bf5153d7d2b5f7b 100755 (executable)
@@ -7,8 +7,13 @@
 
 SPATCH="`which ${SPATCH:=spatch}`"
 
-trap kill_running SIGTERM SIGINT
-declare -a SPATCH_PID
+if [ ! -x "$SPATCH" ]; then
+    echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
+    exit 1
+fi
+
+USE_JOBS="no"
+$SPATCH --help | grep "\-\-jobs" > /dev/null && USE_JOBS="yes"
 
 # The verbosity may be set by the environmental parameter V=
 # as for example with 'make V=1 coccicheck'
@@ -25,7 +30,7 @@ else
        NPROC="$J"
 fi
 
-FLAGS="$SPFLAGS --very-quiet"
+FLAGS="--very-quiet"
 
 # spatch only allows include directories with the syntax "-I include"
 # while gcc also allows "-Iinclude" and "-include include"
@@ -51,9 +56,14 @@ if [ "$KBUILD_EXTMOD" != "" ] ; then
     OPTIONS="--patch $srctree $OPTIONS"
 fi
 
-if [ ! -x "$SPATCH" ]; then
-    echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
-    exit 1
+# You can override by using SPFLAGS
+if [ "$USE_JOBS" = "no" ]; then
+       trap kill_running SIGTERM SIGINT
+       declare -a SPATCH_PID
+elif [ "$NPROC" != "1" ]; then
+       # Using 0 should work as well, refer to _SC_NPROCESSORS_ONLN use on
+       # https://github.com/rdicosmo/parmap/blob/master/setcore_stubs.c
+       OPTIONS="$OPTIONS --jobs $NPROC --chunksize 1"
 fi
 
 if [ "$MODE" = "" ] ; then
@@ -72,7 +82,7 @@ if [ "$MODE" = "chain" ] ; then
        echo 'All available modes will be tried (in that order): patch, report, context, org'
     fi
 elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
-    FLAGS="$FLAGS --no-show-diff"
+    FLAGS="--no-show-diff $FLAGS"
 fi
 
 if [ "$ONLINE" = "0" ] ; then
@@ -82,7 +92,26 @@ if [ "$ONLINE" = "0" ] ; then
     echo ''
 fi
 
-run_cmd() {
+run_cmd_parmap() {
+       if [ $VERBOSE -ne 0 ] ; then
+               echo "Running ($NPROC in parallel): $@"
+       fi
+       if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then
+               if [ -f $DEBUG_FILE ]; then
+                       echo "Debug file $DEBUG_FILE exists, bailing"
+                       exit
+               fi
+       else
+               DEBUG_FILE="/dev/null"
+       fi
+       $@ 2>$DEBUG_FILE
+       if [[ $? -ne 0 ]]; then
+               echo "coccicheck failed"
+               exit $?
+       fi
+}
+
+run_cmd_old() {
        local i
        if [ $VERBOSE -ne 0 ] ; then
                echo "Running ($NPROC in parallel): $@"
@@ -97,8 +126,16 @@ run_cmd() {
        wait
 }
 
+run_cmd() {
+       if [ "$USE_JOBS" = "yes" ]; then
+               run_cmd_parmap $@
+       else
+               run_cmd_old $@
+       fi
+}
+
 kill_running() {
-       for i in $(seq $(( NPROC - 1 )) ); do
+       for i in $(seq $(( NPROC - 1 )) ); do
                if [ $VERBOSE -eq 2 ] ; then
                        echo "Killing ${SPATCH_PID[$i]}"
                fi
@@ -106,6 +143,9 @@ kill_running() {
        done
 }
 
+# You can override heuristics with SPFLAGS, these must always go last
+OPTIONS="$OPTIONS $SPFLAGS"
+
 coccinelle () {
     COCCI="$1"
 
This page took 0.026395 seconds and 5 git commands to generate.