blob: 1a49d1c7ecfeb793a6bd116410f3c6449714eea5 [file] [log] [blame]
Nicolas Palix74425ee2010-06-06 17:15:01 +02001#!/bin/sh
2
3SPATCH="`which ${SPATCH:=spatch}`"
4
Nicolas Palix1e9dea22010-06-13 09:26:34 +02005if [ "$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
Greg Dietsche42f1c012012-01-20 17:10:35 -060012# Workaround for Coccinelle < 0.2.3
13 FLAGS="-I $srctree/include -very_quiet"
14 shift $(( $# - 1 ))
15 OPTIONS=$1
Nicolas Palix1e9dea22010-06-13 09:26:34 +020016else
17 ONLINE=0
18 FLAGS="-very_quiet"
Greg Dietsched0bc1fb2011-11-05 20:59:43 -050019 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
Nicolas Palix1e9dea22010-06-13 09:26:34 +020024fi
25
Nicolas Palix74425ee2010-06-06 17:15:01 +020026if [ ! -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
Nicolas Palix1e9dea22010-06-13 09:26:34 +020032 if [ "$ONLINE" = "0" ] ; then
Nicolas Palix2c1160c82010-10-08 21:27:40 +020033 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'
Nicolas Palix1e9dea22010-06-13 09:26:34 +020035 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
Nicolas Palix1e9dea22010-06-13 09:26:34 +020036 fi
Nicolas Palix2c1160c82010-10-08 21:27:40 +020037 MODE="chain"
Nicolas Palix03ee0c42010-10-08 21:27:41 +020038elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
Nicolas Palix062c1822010-10-24 23:37:34 +020039 FLAGS="$FLAGS -no_show_diff"
Nicolas Palix74425ee2010-06-06 17:15:01 +020040fi
41
Nicolas Palix1e9dea22010-06-13 09:26:34 +020042if [ "$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
Nicolas Palix74425ee2010-06-06 17:15:01 +020048
Nicolas Palix1e9dea22010-06-13 09:26:34 +020049coccinelle () {
Nicolas Palix74425ee2010-06-06 17:15:01 +020050 COCCI="$1"
Nicolas Palix74425ee2010-06-06 17:15:01 +020051
52 OPT=`grep "Option" $COCCI | cut -d':' -f2`
Nicolas Palix74425ee2010-06-06 17:15:01 +020053
Nicolas Palix062c1822010-10-24 23:37:34 +020054# The option '-parse_cocci' can be used to syntactically check the SmPL files.
Nicolas Palix74425ee2010-06-06 17:15:01 +020055#
Nicolas Palix1e9dea22010-06-13 09:26:34 +020056# $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
Nicolas Palix74425ee2010-06-06 17:15:01 +020057
Nicolas Palix1e9dea22010-06-13 09:26:34 +020058 if [ "$ONLINE" = "0" ] ; then
59
60 FILE=`echo $COCCI | sed "s|$srctree/||"`
61
Nicolas Palix3c908412010-10-08 21:27:38 +020062 echo "Processing `basename $COCCI`"
63 echo "with option(s) \"$OPT\""
64 echo ''
Nicolas Palix1e9dea22010-06-13 09:26:34 +020065 echo 'Message example to submit a patch:'
66
Nicolas Palix3c908412010-10-08 21:27:38 +020067 sed -ne 's|^///||p' $COCCI
Nicolas Palix1e9dea22010-06-13 09:26:34 +020068
Nicolas Palix062c1822010-10-24 23:37:34 +020069 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
Nicolas Palix1e9dea22010-06-13 09:26:34 +020080 echo " in $FILE."
81 echo ''
82 echo ' More information about semantic patching is available at'
83 echo ' http://coccinelle.lip6.fr/'
84 echo ''
85
Nicolas Palix3c908412010-10-08 21:27:38 +020086 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
87 echo 'Semantic patch information:'
88 sed -ne 's|^//#||p' $COCCI
89 echo ''
90 fi
Nicolas Palix2c1160c82010-10-08 21:27:40 +020091 fi
Nicolas Palix3c908412010-10-08 21:27:38 +020092
Nicolas Palix2c1160c82010-10-08 21:27:40 +020093 if [ "$MODE" = "chain" ] ; then
Nicolas Palix03ee0c42010-10-08 21:27:41 +020094 $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
Nicolas Palixc05cd6d2012-09-20 22:30:46 +020098 elif [ "$MODE" = "rep+ctxt" ] ; then
99 $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \
100 $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
Nicolas Palix1e9dea22010-06-13 09:26:34 +0200101 else
Nicolas Palix2c1160c82010-10-08 21:27:40 +0200102 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
Nicolas Palix1e9dea22010-06-13 09:26:34 +0200103 fi
104
Nicolas Palix74425ee2010-06-06 17:15:01 +0200105}
106
107if [ "$COCCI" = "" ] ; then
108 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
Nicolas Palix1e9dea22010-06-13 09:26:34 +0200109 coccinelle $f
Nicolas Palix74425ee2010-06-06 17:15:01 +0200110 done
111else
Nicolas Palix1e9dea22010-06-13 09:26:34 +0200112 coccinelle $COCCI
Nicolas Palix74425ee2010-06-06 17:15:01 +0200113fi