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 | ||
42f1c01b GD |
12 | # Workaround for Coccinelle < 0.2.3 |
13 | FLAGS="-I $srctree/include -very_quiet" | |
14 | shift $(( $# - 1 )) | |
15 | OPTIONS=$1 | |
1e9dea2a NP |
16 | else |
17 | ONLINE=0 | |
18 | FLAGS="-very_quiet" | |
d0bc1fb4 GD |
19 | 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 | |
1e9dea2a NP |
24 | fi |
25 | ||
74425eee NP |
26 | if [ ! -x "$SPATCH" ]; then |
27 | echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' | |
28 | exit 1 | |
29 | fi | |
30 | ||
31 | if [ "$MODE" = "" ] ; then | |
1e9dea2a | 32 | if [ "$ONLINE" = "0" ] ; then |
2c1160c8 NP |
33 | 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' | |
1e9dea2a | 35 | echo 'You can specify the mode with "make coccicheck MODE=<mode>"' |
1e9dea2a | 36 | fi |
2c1160c8 | 37 | MODE="chain" |
03ee0c42 | 38 | elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then |
062c1825 | 39 | FLAGS="$FLAGS -no_show_diff" |
74425eee NP |
40 | fi |
41 | ||
1e9dea2a NP |
42 | if [ "$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 '' | |
47 | fi | |
74425eee | 48 | |
1e9dea2a | 49 | coccinelle () { |
74425eee | 50 | COCCI="$1" |
74425eee NP |
51 | |
52 | OPT=`grep "Option" $COCCI | cut -d':' -f2` | |
74425eee | 53 | |
062c1825 | 54 | # The option '-parse_cocci' can be used to syntactically check the SmPL files. |
1e9dea2a NP |
55 | # |
56 | # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null | |
74425eee | 57 | |
1e9dea2a | 58 | if [ "$ONLINE" = "0" ] ; then |
74425eee | 59 | |
1e9dea2a | 60 | FILE=`echo $COCCI | sed "s|$srctree/||"` |
74425eee | 61 | |
3c908417 NP |
62 | echo "Processing `basename $COCCI`" |
63 | echo "with option(s) \"$OPT\"" | |
64 | echo '' | |
1e9dea2a NP |
65 | echo 'Message example to submit a patch:' |
66 | ||
3c908417 | 67 | sed -ne 's|^///||p' $COCCI |
1e9dea2a | 68 | |
062c1825 NP |
69 | 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 | |
1e9dea2a NP |
80 | echo " in $FILE." |
81 | echo '' | |
82 | echo ' More information about semantic patching is available at' | |
83 | echo ' http://coccinelle.lip6.fr/' | |
84 | echo '' | |
85 | ||
3c908417 NP |
86 | if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then |
87 | echo 'Semantic patch information:' | |
88 | sed -ne 's|^//#||p' $COCCI | |
89 | echo '' | |
90 | fi | |
2c1160c8 | 91 | fi |
3c908417 | 92 | |
2c1160c8 | 93 | if [ "$MODE" = "chain" ] ; then |
03ee0c42 NP |
94 | $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 | |
c05cd6dd NP |
98 | 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 | |
1e9dea2a | 101 | else |
2c1160c8 | 102 | $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 |
1e9dea2a | 103 | fi |
74425eee | 104 | |
74425eee NP |
105 | } |
106 | ||
107 | if [ "$COCCI" = "" ] ; then | |
108 | for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do | |
1e9dea2a | 109 | coccinelle $f |
74425eee NP |
110 | done |
111 | else | |
1e9dea2a | 112 | coccinelle $COCCI |
74425eee | 113 | fi |