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