Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | SPATCH="`which ${SPATCH:=spatch}`" |
| 4 | |
Bernd Schubert | 26e5672 | 2013-01-29 17:03:37 +0100 | [diff] [blame^] | 5 | # The verbosity may be set by the environmental parameter V= |
| 6 | # as for example with 'make V=1 coccicheck' |
| 7 | |
| 8 | if [ -n "$V" -a "$V" != "0" ]; then |
| 9 | VERBOSE=1 |
| 10 | else |
| 11 | VERBOSE=0 |
| 12 | fi |
| 13 | |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 14 | if [ "$C" = "1" -o "$C" = "2" ]; then |
| 15 | ONLINE=1 |
| 16 | |
| 17 | # This requires Coccinelle >= 0.2.3 |
| 18 | # FLAGS="-ignore_unknown_options -very_quiet" |
| 19 | # OPTIONS=$* |
| 20 | |
Greg Dietsche | 42f1c01 | 2012-01-20 17:10:35 -0600 | [diff] [blame] | 21 | # Workaround for Coccinelle < 0.2.3 |
| 22 | FLAGS="-I $srctree/include -very_quiet" |
| 23 | shift $(( $# - 1 )) |
| 24 | OPTIONS=$1 |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 25 | else |
| 26 | ONLINE=0 |
| 27 | FLAGS="-very_quiet" |
Greg Dietsche | d0bc1fb | 2011-11-05 20:59:43 -0500 | [diff] [blame] | 28 | if [ "$KBUILD_EXTMOD" = "" ] ; then |
| 29 | OPTIONS="-dir $srctree" |
| 30 | else |
| 31 | OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include -I $KBUILD_EXTMOD/include" |
| 32 | fi |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 33 | fi |
| 34 | |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 35 | if [ ! -x "$SPATCH" ]; then |
| 36 | echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | if [ "$MODE" = "" ] ; then |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 41 | if [ "$ONLINE" = "0" ] ; then |
Nicolas Palix | 2c1160c8 | 2010-10-08 21:27:40 +0200 | [diff] [blame] | 42 | echo 'You have not explicitly specified the mode to use. Using default "chain" mode.' |
| 43 | echo 'All available modes will be tried (in that order): patch, report, context, org' |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 44 | echo 'You can specify the mode with "make coccicheck MODE=<mode>"' |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 45 | fi |
Nicolas Palix | 2c1160c8 | 2010-10-08 21:27:40 +0200 | [diff] [blame] | 46 | MODE="chain" |
Nicolas Palix | 03ee0c4 | 2010-10-08 21:27:41 +0200 | [diff] [blame] | 47 | elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then |
Nicolas Palix | 062c182 | 2010-10-24 23:37:34 +0200 | [diff] [blame] | 48 | FLAGS="$FLAGS -no_show_diff" |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 49 | fi |
| 50 | |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 51 | if [ "$ONLINE" = "0" ] ; then |
| 52 | echo '' |
| 53 | echo 'Please check for false positives in the output before submitting a patch.' |
| 54 | echo 'When using "patch" mode, carefully review the patch before submitting it.' |
| 55 | echo '' |
| 56 | fi |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 57 | |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 58 | coccinelle () { |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 59 | COCCI="$1" |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 60 | |
| 61 | OPT=`grep "Option" $COCCI | cut -d':' -f2` |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 62 | |
Nicolas Palix | 062c182 | 2010-10-24 23:37:34 +0200 | [diff] [blame] | 63 | # The option '-parse_cocci' can be used to syntactically check the SmPL files. |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 64 | # |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 65 | # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 66 | |
Bernd Schubert | 26e5672 | 2013-01-29 17:03:37 +0100 | [diff] [blame^] | 67 | if [ $VERBOSE -ne 0 ] ; then |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 68 | |
| 69 | FILE=`echo $COCCI | sed "s|$srctree/||"` |
| 70 | |
Nicolas Palix | 3c90841 | 2010-10-08 21:27:38 +0200 | [diff] [blame] | 71 | echo "Processing `basename $COCCI`" |
| 72 | echo "with option(s) \"$OPT\"" |
| 73 | echo '' |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 74 | echo 'Message example to submit a patch:' |
| 75 | |
Nicolas Palix | 3c90841 | 2010-10-08 21:27:38 +0200 | [diff] [blame] | 76 | sed -ne 's|^///||p' $COCCI |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 77 | |
Nicolas Palix | 062c182 | 2010-10-24 23:37:34 +0200 | [diff] [blame] | 78 | if [ "$MODE" = "patch" ] ; then |
| 79 | echo ' The semantic patch that makes this change is available' |
| 80 | elif [ "$MODE" = "report" ] ; then |
| 81 | echo ' The semantic patch that makes this report is available' |
| 82 | elif [ "$MODE" = "context" ] ; then |
| 83 | echo ' The semantic patch that spots this code is available' |
| 84 | elif [ "$MODE" = "org" ] ; then |
| 85 | echo ' The semantic patch that makes this Org report is available' |
| 86 | else |
| 87 | echo ' The semantic patch that makes this output is available' |
| 88 | fi |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 89 | echo " in $FILE." |
| 90 | echo '' |
| 91 | echo ' More information about semantic patching is available at' |
| 92 | echo ' http://coccinelle.lip6.fr/' |
| 93 | echo '' |
| 94 | |
Nicolas Palix | 3c90841 | 2010-10-08 21:27:38 +0200 | [diff] [blame] | 95 | if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then |
| 96 | echo 'Semantic patch information:' |
| 97 | sed -ne 's|^//#||p' $COCCI |
| 98 | echo '' |
| 99 | fi |
Nicolas Palix | 2c1160c8 | 2010-10-08 21:27:40 +0200 | [diff] [blame] | 100 | fi |
Nicolas Palix | 3c90841 | 2010-10-08 21:27:38 +0200 | [diff] [blame] | 101 | |
Nicolas Palix | 2c1160c8 | 2010-10-08 21:27:40 +0200 | [diff] [blame] | 102 | if [ "$MODE" = "chain" ] ; then |
Nicolas Palix | 03ee0c4 | 2010-10-08 21:27:41 +0200 | [diff] [blame] | 103 | $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ |
| 104 | $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ |
| 105 | $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ |
| 106 | $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 |
Nicolas Palix | c05cd6d | 2012-09-20 22:30:46 +0200 | [diff] [blame] | 107 | elif [ "$MODE" = "rep+ctxt" ] ; then |
| 108 | $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ |
| 109 | $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 110 | else |
Nicolas Palix | 2c1160c8 | 2010-10-08 21:27:40 +0200 | [diff] [blame] | 111 | $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 112 | fi |
| 113 | |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | if [ "$COCCI" = "" ] ; then |
| 117 | for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 118 | coccinelle $f |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 119 | done |
| 120 | else |
Nicolas Palix | 1e9dea2 | 2010-06-13 09:26:34 +0200 | [diff] [blame] | 121 | coccinelle $COCCI |
Nicolas Palix | 74425ee | 2010-06-06 17:15:01 +0200 | [diff] [blame] | 122 | fi |