]>
Commit | Line | Data |
---|---|---|
74425eee NP |
1 | #!/bin/sh |
2 | ||
3 | SPATCH="`which ${SPATCH:=spatch}`" | |
4 | ||
1e9dea2a NP |
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" | |
2c1160c8 | 19 | OPTIONS="-dir $srctree" |
1e9dea2a NP |
20 | fi |
21 | ||
74425eee NP |
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 | |
1e9dea2a | 28 | if [ "$ONLINE" = "0" ] ; then |
2c1160c8 NP |
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' | |
1e9dea2a | 31 | echo 'You can specify the mode with "make coccicheck MODE=<mode>"' |
1e9dea2a | 32 | fi |
2c1160c8 | 33 | MODE="chain" |
74425eee NP |
34 | fi |
35 | ||
1e9dea2a NP |
36 | if [ "$ONLINE" = "0" ] ; then |
37 | echo '' | |
38 | echo 'Please check for false positives in the output before submitting a patch.' | |
39 | echo 'When using "patch" mode, carefully review the patch before submitting it.' | |
40 | echo '' | |
41 | fi | |
74425eee | 42 | |
1e9dea2a | 43 | coccinelle () { |
74425eee | 44 | COCCI="$1" |
74425eee NP |
45 | |
46 | OPT=`grep "Option" $COCCI | cut -d':' -f2` | |
74425eee | 47 | |
1e9dea2a NP |
48 | # The option '-parse_cocci' can be used to syntaxically check the SmPL files. |
49 | # | |
50 | # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null | |
74425eee | 51 | |
1e9dea2a | 52 | if [ "$ONLINE" = "0" ] ; then |
74425eee | 53 | |
1e9dea2a | 54 | FILE=`echo $COCCI | sed "s|$srctree/||"` |
74425eee | 55 | |
3c908417 NP |
56 | echo "Processing `basename $COCCI`" |
57 | echo "with option(s) \"$OPT\"" | |
58 | echo '' | |
1e9dea2a NP |
59 | echo 'Message example to submit a patch:' |
60 | ||
3c908417 | 61 | sed -ne 's|^///||p' $COCCI |
1e9dea2a NP |
62 | |
63 | echo ' The semantic patch that makes this change is available' | |
64 | echo " in $FILE." | |
65 | echo '' | |
66 | echo ' More information about semantic patching is available at' | |
67 | echo ' http://coccinelle.lip6.fr/' | |
68 | echo '' | |
69 | ||
3c908417 NP |
70 | if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then |
71 | echo 'Semantic patch information:' | |
72 | sed -ne 's|^//#||p' $COCCI | |
73 | echo '' | |
74 | fi | |
2c1160c8 | 75 | fi |
3c908417 | 76 | |
2c1160c8 NP |
77 | if [ "$MODE" = "chain" ] ; then |
78 | $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | |
79 | $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | |
80 | $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | |
81 | $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 | |
1e9dea2a | 82 | else |
2c1160c8 | 83 | $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 |
1e9dea2a | 84 | fi |
74425eee | 85 | |
74425eee NP |
86 | } |
87 | ||
88 | if [ "$COCCI" = "" ] ; then | |
89 | for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do | |
1e9dea2a | 90 | coccinelle $f |
74425eee NP |
91 | done |
92 | else | |
1e9dea2a | 93 | coccinelle $COCCI |
74425eee | 94 | fi |