aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Palix <npalix@diku.dk>2010-06-13 03:26:34 -0400
committerMichal Marek <mmarek@suse.cz>2010-06-28 10:44:53 -0400
commit1e9dea2a60b71ea7a9ac2936bed920d39f662e52 (patch)
treedf3696ae510c2e4edbc80123dbd73abbc7169c28
parent6ff21517c001f38b02393ad9dc92decbaee209fa (diff)
Add support for the C variable in the coccicheck script
This patch makes it possible to use the Coccinelle checker with the C variable of the build system. To check only newly edited code, the following command may be used: 'make C={1,2} CHECK="scripts/coccicheck"' This runs every semantic patch in scripts/coccinelle by default. The COCCI variable may additionally be used to only apply a single semantic patch. Signed-off-by: Nicolas Palix <npalix@diku.dk> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Michal Marek <mmarek@suse.cz>
-rwxr-xr-xscripts/coccicheck76
1 files changed, 51 insertions, 25 deletions
diff --git a/scripts/coccicheck b/scripts/coccicheck
index 037424b9ede5..b8bcf1f7bed7 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -2,53 +2,79 @@
2 2
3SPATCH="`which ${SPATCH:=spatch}`" 3SPATCH="`which ${SPATCH:=spatch}`"
4 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"
19fi
20
5if [ ! -x "$SPATCH" ]; then 21if [ ! -x "$SPATCH" ]; then
6 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' 22 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
7 exit 1 23 exit 1
8fi 24fi
9 25
10if [ "$MODE" = "" ] ; then 26if [ "$MODE" = "" ] ; then
11 echo 'You have not explicitly specify the mode to use. Fallback to "report".' 27 if [ "$ONLINE" = "0" ] ; then
12 echo 'You can specify the mode with "make coccicheck MODE=<mode>"' 28 echo 'You have not explicitly specify the mode to use. Fallback to "report".'
13 echo 'Available modes are: report, patch, context, org' 29 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
30 echo 'Available modes are: report, patch, context, org'
31 fi
14 MODE="report" 32 MODE="report"
15fi 33fi
16 34
17echo '' 35if [ "$ONLINE" = "0" ] ; then
18echo 'Please check for false positives in the output before submitting a patch.' 36 echo ''
19echo 'When using "patch" mode, carefully review the patch before submitting it.' 37 echo 'Please check for false positives in the output before submitting a patch.'
20echo '' 38 echo 'When using "patch" mode, carefully review the patch before submitting it.'
39 echo ''
40fi
21 41
22function coccinelle { 42coccinelle () {
23 COCCI="$1" 43 COCCI="$1"
24 DIR="$2"
25 44
26 OPT=`grep "Option" $COCCI | cut -d':' -f2` 45 OPT=`grep "Option" $COCCI | cut -d':' -f2`
27 FILE=`echo $COCCI | sed "s|$DIR/||"`
28 46
29 echo "Processing `basename $COCCI` with option(s) \"$OPT\"" 47# The option '-parse_cocci' can be used to syntaxically check the SmPL files.
30 echo 'Message example to submit a patch:' 48#
49# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
31 50
32 sed -e '/\/\/\//!d' -e 's|^///||' $COCCI 51 if [ "$ONLINE" = "0" ] ; then
33 52
34 echo ' The semantic patch that makes this change is available' 53 FILE=`echo $COCCI | sed "s|$srctree/||"`
35 echo " in $FILE."
36 echo ''
37 echo ' More information about semantic patching is available at'
38 echo ' http://coccinelle.lip6.fr/'
39 echo ''
40 54
41# The option '-parse_cocci' can be used to syntaxically check the SmPL files. 55 echo "Processing `basename $COCCI` with option(s) \"$OPT\""
42# 56 echo 'Message example to submit a patch:'
43# $SPATCH -D $MODE -very_quiet -parse_cocci $COCCI $OPT > /dev/null 57
58 sed -e '/\/\/\//!d' -e 's|^///||' $COCCI
59
60 echo ' The semantic patch that makes this change is available'
61 echo " in $FILE."
62 echo ''
63 echo ' More information about semantic patching is available at'
64 echo ' http://coccinelle.lip6.fr/'
65 echo ''
66
67 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT -dir $srctree || exit 1
68 else
69 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
70 fi
44 71
45 $SPATCH -D $MODE -very_quiet -sp_file $COCCI $OPT -dir $DIR
46} 72}
47 73
48if [ "$COCCI" = "" ] ; then 74if [ "$COCCI" = "" ] ; then
49 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do 75 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
50 coccinelle $f $srctree; 76 coccinelle $f
51 done 77 done
52else 78else
53 coccinelle $COCCI $srctree 79 coccinelle $COCCI
54fi 80fi