Linux Audio

Check our new training course

Loading...
v4.6
  1#!/bin/bash
  2
  3#
  4# This script requires at least spatch
  5# version 1.0.0-rc11.
  6#
  7
  8SPATCH="`which ${SPATCH:=spatch}`"
  9
 10trap kill_running SIGTERM SIGINT
 11declare -a SPATCH_PID
 12
 13# The verbosity may be set by the environmental parameter V=
 14# as for example with 'make V=1 coccicheck'
 15
 16if [ -n "$V" -a "$V" != "0" ]; then
 17	VERBOSE="$V"
 18else
 19	VERBOSE=0
 20fi
 21
 22if [ -z "$J" ]; then
 23	NPROC=$(getconf _NPROCESSORS_ONLN)
 24else
 25	NPROC="$J"
 26fi
 27
 28FLAGS="$SPFLAGS --very-quiet"
 29
 30# spatch only allows include directories with the syntax "-I include"
 31# while gcc also allows "-Iinclude" and "-include include"
 32COCCIINCLUDE=${LINUXINCLUDE//-I/-I }
 33COCCIINCLUDE=${COCCIINCLUDE// -include/ --include}
 34
 35if [ "$C" = "1" -o "$C" = "2" ]; then
 36    ONLINE=1
 37
 38    # Take only the last argument, which is the C file to test
 39    shift $(( $# - 1 ))
 40    OPTIONS="$COCCIINCLUDE $1"
 
 
 
 
 
 41else
 42    ONLINE=0
 
 43    if [ "$KBUILD_EXTMOD" = "" ] ; then
 44        OPTIONS="--dir $srctree $COCCIINCLUDE"
 45    else
 46        OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
 47    fi
 48fi
 49
 50if [ "$KBUILD_EXTMOD" != "" ] ; then
 51    OPTIONS="--patch $srctree $OPTIONS"
 52fi
 53
 54if [ ! -x "$SPATCH" ]; then
 55    echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
 56    exit 1
 57fi
 58
 59if [ "$MODE" = "" ] ; then
 60    if [ "$ONLINE" = "0" ] ; then
 61	echo 'You have not explicitly specified the mode to use. Using default "report" mode.'
 62	echo 'Available modes are the following: patch, report, context, org'
 63	echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
 64	echo 'Note however that some modes are not implemented by some semantic patches.'
 65    fi
 66    MODE="report"
 67fi
 68
 69if [ "$MODE" = "chain" ] ; then
 70    if [ "$ONLINE" = "0" ] ; then
 71	echo 'You have selected the "chain" mode.'
 72	echo 'All available modes will be tried (in that order): patch, report, context, org'
 
 73    fi
 
 74elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
 75    FLAGS="$FLAGS --no-show-diff"
 76fi
 77
 78if [ "$ONLINE" = "0" ] ; then
 79    echo ''
 80    echo 'Please check for false positives in the output before submitting a patch.'
 81    echo 'When using "patch" mode, carefully review the patch before submitting it.'
 82    echo ''
 83fi
 84
 85run_cmd() {
 86	local i
 87	if [ $VERBOSE -ne 0 ] ; then
 88		echo "Running ($NPROC in parallel): $@"
 89	fi
 90	for i in $(seq 0 $(( NPROC - 1)) ); do
 91		eval "$@ --max $NPROC --index $i &"
 92		SPATCH_PID[$i]=$!
 93		if [ $VERBOSE -eq 2 ] ; then
 94			echo "${SPATCH_PID[$i]} running"
 95		fi
 96	done
 97	wait
 98}
 99
100kill_running() {
101	for i in $(seq $(( NPROC - 1 )) ); do
102		if [ $VERBOSE -eq 2 ] ; then
103			echo "Killing ${SPATCH_PID[$i]}"
104		fi
105		kill ${SPATCH_PID[$i]} 2>/dev/null
106	done
107}
108
109coccinelle () {
110    COCCI="$1"
111
112    OPT=`grep "Option" $COCCI | cut -d':' -f2`
113
114#   The option '--parse-cocci' can be used to syntactically check the SmPL files.
115#
116#    $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
117
118    if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then
119
120	FILE=`echo $COCCI | sed "s|$srctree/||"`
121
122	echo "Processing `basename $COCCI`"
123	echo "with option(s) \"$OPT\""
124	echo ''
125	echo 'Message example to submit a patch:'
126
127	sed -ne 's|^///||p' $COCCI
128
129	if [ "$MODE" = "patch" ] ; then
130	    echo ' The semantic patch that makes this change is available'
131	elif [ "$MODE" = "report" ] ; then
132	    echo ' The semantic patch that makes this report is available'
133	elif [ "$MODE" = "context" ] ; then
134	    echo ' The semantic patch that spots this code is available'
135	elif [ "$MODE" = "org" ] ; then
136	    echo ' The semantic patch that makes this Org report is available'
137	else
138	    echo ' The semantic patch that makes this output is available'
139	fi
140	echo " in $FILE."
141	echo ''
142	echo ' More information about semantic patching is available at'
143	echo ' http://coccinelle.lip6.fr/'
144	echo ''
145
146	if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
147	    echo 'Semantic patch information:'
148	    sed -ne 's|^//#||p' $COCCI
149	    echo ''
150	fi
151    fi
152
153    if [ "$MODE" = "chain" ] ; then
154	run_cmd $SPATCH -D patch   \
155		$FLAGS --cocci-file $COCCI $OPT $OPTIONS               || \
156	run_cmd $SPATCH -D report  \
157		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || \
158	run_cmd $SPATCH -D context \
159		$FLAGS --cocci-file $COCCI $OPT $OPTIONS               || \
160	run_cmd $SPATCH -D org     \
161		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff || exit 1
162    elif [ "$MODE" = "rep+ctxt" ] ; then
163	run_cmd $SPATCH -D report  \
164		$FLAGS --cocci-file $COCCI $OPT $OPTIONS --no-show-diff && \
165	run_cmd $SPATCH -D context \
166		$FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
167    else
168	run_cmd $SPATCH -D $MODE   $FLAGS --cocci-file $COCCI $OPT $OPTIONS || exit 1
169    fi
170
171}
172
173if [ "$COCCI" = "" ] ; then
174    for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
175	coccinelle $f
176    done
177else
178    coccinelle $COCCI
179fi
v3.5.6
  1#!/bin/sh
 
 
 
 
 
  2
  3SPATCH="`which ${SPATCH:=spatch}`"
  4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  5if [ "$C" = "1" -o "$C" = "2" ]; then
  6    ONLINE=1
  7
  8# This requires Coccinelle >= 0.2.3
  9#    FLAGS="-ignore_unknown_options -very_quiet"
 10#    OPTIONS=$*
 11
 12# Workaround for Coccinelle < 0.2.3
 13	FLAGS="-I $srctree/include -very_quiet"
 14	shift $(( $# - 1 ))
 15	OPTIONS=$1
 16else
 17    ONLINE=0
 18    FLAGS="-very_quiet"
 19    if [ "$KBUILD_EXTMOD" = "" ] ; then
 20        OPTIONS="-dir $srctree"
 21    else
 22        OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include -I $KBUILD_EXTMOD/include"
 23    fi
 24fi
 25
 
 
 
 
 26if [ ! -x "$SPATCH" ]; then
 27    echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
 28    exit 1
 29fi
 30
 31if [ "$MODE" = "" ] ; then
 32    if [ "$ONLINE" = "0" ] ; then
 33	echo 'You have not explicitly specified the mode to use. Using default "chain" mode.'
 
 
 
 
 
 
 
 
 
 
 34	echo 'All available modes will be tried (in that order): patch, report, context, org'
 35	echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
 36    fi
 37    MODE="chain"
 38elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
 39    FLAGS="$FLAGS -no_show_diff"
 40fi
 41
 42if [ "$ONLINE" = "0" ] ; then
 43    echo ''
 44    echo 'Please check for false positives in the output before submitting a patch.'
 45    echo 'When using "patch" mode, carefully review the patch before submitting it.'
 46    echo ''
 47fi
 48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 49coccinelle () {
 50    COCCI="$1"
 51
 52    OPT=`grep "Option" $COCCI | cut -d':' -f2`
 53
 54#   The option '-parse_cocci' can be used to syntactically check the SmPL files.
 55#
 56#    $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
 57
 58    if [ "$ONLINE" = "0" ] ; then
 59
 60	FILE=`echo $COCCI | sed "s|$srctree/||"`
 61
 62	echo "Processing `basename $COCCI`"
 63	echo "with option(s) \"$OPT\""
 64	echo ''
 65	echo 'Message example to submit a patch:'
 66
 67	sed -ne 's|^///||p' $COCCI
 68
 69	if [ "$MODE" = "patch" ] ; then
 70	    echo ' The semantic patch that makes this change is available'
 71	elif [ "$MODE" = "report" ] ; then
 72	    echo ' The semantic patch that makes this report is available'
 73	elif [ "$MODE" = "context" ] ; then
 74	    echo ' The semantic patch that spots this code is available'
 75	elif [ "$MODE" = "org" ] ; then
 76	    echo ' The semantic patch that makes this Org report is available'
 77	else
 78	    echo ' The semantic patch that makes this output is available'
 79	fi
 80	echo " in $FILE."
 81	echo ''
 82	echo ' More information about semantic patching is available at'
 83	echo ' http://coccinelle.lip6.fr/'
 84	echo ''
 85
 86	if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
 87	    echo 'Semantic patch information:'
 88	    sed -ne 's|^//#||p' $COCCI
 89	    echo ''
 90	fi
 91    fi
 92
 93    if [ "$MODE" = "chain" ] ; then
 94	$SPATCH -D patch   $FLAGS -sp_file $COCCI $OPT $OPTIONS               || \
 95	$SPATCH -D report  $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \
 96	$SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS               || \
 97	$SPATCH -D org     $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1
 
 
 
 
 
 
 
 
 
 98    else
 99	$SPATCH -D $MODE   $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
100    fi
101
102}
103
104if [ "$COCCI" = "" ] ; then
105    for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
106	coccinelle $f
107    done
108else
109    coccinelle $COCCI
110fi