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