Commit | Line | Data |
---|---|---|
9e395550 | 1 | #!/bin/bash |
74425eee NP |
2 | |
3 | SPATCH="`which ${SPATCH:=spatch}`" | |
4 | ||
26e56720 BS |
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 | ||
ed621cc4 | 14 | FLAGS="$SPFLAGS -very_quiet" |
9e395550 NP |
15 | |
16 | # spatch only allows include directories with the syntax "-I include" | |
17 | # while gcc also allows "-Iinclude" and "-include include" | |
18 | COCCIINCLUDE=${LINUXINCLUDE//-I/-I } | |
19 | COCCIINCLUDE=${COCCIINCLUDE//-include/-I} | |
20 | ||
1e9dea2a NP |
21 | if [ "$C" = "1" -o "$C" = "2" ]; then |
22 | ONLINE=1 | |
23 | ||
9e395550 NP |
24 | # Take only the last argument, which is the C file to test |
25 | shift $(( $# - 1 )) | |
26 | OPTIONS="$COCCIINCLUDE $1" | |
1e9dea2a NP |
27 | else |
28 | ONLINE=0 | |
d0bc1fb4 | 29 | if [ "$KBUILD_EXTMOD" = "" ] ; then |
9e395550 | 30 | OPTIONS="-dir $srctree $COCCIINCLUDE" |
d0bc1fb4 | 31 | else |
bad6a409 | 32 | OPTIONS="-dir $KBUILD_EXTMOD $COCCIINCLUDE" |
d0bc1fb4 | 33 | fi |
1e9dea2a NP |
34 | fi |
35 | ||
bad6a409 NP |
36 | if [ "$KBUILD_EXTMOD" != "" ] ; then |
37 | OPTIONS="-patch $srctree $OPTIONS" | |
38 | fi | |
39 | ||
74425eee NP |
40 | if [ ! -x "$SPATCH" ]; then |
41 | echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' | |
42 | exit 1 | |
43 | fi | |
44 | ||
45 | if [ "$MODE" = "" ] ; then | |
1e9dea2a | 46 | if [ "$ONLINE" = "0" ] ; then |
2c1160c8 NP |
47 | echo 'You have not explicitly specified the mode to use. Using default "chain" mode.' |
48 | echo 'All available modes will be tried (in that order): patch, report, context, org' | |
1e9dea2a | 49 | echo 'You can specify the mode with "make coccicheck MODE=<mode>"' |
1e9dea2a | 50 | fi |
2c1160c8 | 51 | MODE="chain" |
03ee0c42 | 52 | elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then |
062c1825 | 53 | FLAGS="$FLAGS -no_show_diff" |
74425eee NP |
54 | fi |
55 | ||
1e9dea2a NP |
56 | if [ "$ONLINE" = "0" ] ; then |
57 | echo '' | |
58 | echo 'Please check for false positives in the output before submitting a patch.' | |
59 | echo 'When using "patch" mode, carefully review the patch before submitting it.' | |
60 | echo '' | |
61 | fi | |
74425eee | 62 | |
5303265a BS |
63 | run_cmd() { |
64 | if [ $VERBOSE -ne 0 ] ; then | |
65 | echo "Running: $@" | |
66 | fi | |
67 | eval $@ | |
68 | } | |
69 | ||
70 | ||
1e9dea2a | 71 | coccinelle () { |
74425eee | 72 | COCCI="$1" |
74425eee NP |
73 | |
74 | OPT=`grep "Option" $COCCI | cut -d':' -f2` | |
74425eee | 75 | |
062c1825 | 76 | # The option '-parse_cocci' can be used to syntactically check the SmPL files. |
1e9dea2a NP |
77 | # |
78 | # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null | |
74425eee | 79 | |
35d88a38 | 80 | if [ $VERBOSE -ne 0 -a $ONLINE -eq 0 ] ; then |
74425eee | 81 | |
1e9dea2a | 82 | FILE=`echo $COCCI | sed "s|$srctree/||"` |
74425eee | 83 | |
3c908417 NP |
84 | echo "Processing `basename $COCCI`" |
85 | echo "with option(s) \"$OPT\"" | |
86 | echo '' | |
1e9dea2a NP |
87 | echo 'Message example to submit a patch:' |
88 | ||
3c908417 | 89 | sed -ne 's|^///||p' $COCCI |
1e9dea2a | 90 | |
062c1825 NP |
91 | if [ "$MODE" = "patch" ] ; then |
92 | echo ' The semantic patch that makes this change is available' | |
93 | elif [ "$MODE" = "report" ] ; then | |
94 | echo ' The semantic patch that makes this report is available' | |
95 | elif [ "$MODE" = "context" ] ; then | |
96 | echo ' The semantic patch that spots this code is available' | |
97 | elif [ "$MODE" = "org" ] ; then | |
98 | echo ' The semantic patch that makes this Org report is available' | |
99 | else | |
100 | echo ' The semantic patch that makes this output is available' | |
101 | fi | |
1e9dea2a NP |
102 | echo " in $FILE." |
103 | echo '' | |
104 | echo ' More information about semantic patching is available at' | |
105 | echo ' http://coccinelle.lip6.fr/' | |
106 | echo '' | |
107 | ||
3c908417 NP |
108 | if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then |
109 | echo 'Semantic patch information:' | |
110 | sed -ne 's|^//#||p' $COCCI | |
111 | echo '' | |
112 | fi | |
2c1160c8 | 113 | fi |
3c908417 | 114 | |
2c1160c8 | 115 | if [ "$MODE" = "chain" ] ; then |
5303265a BS |
116 | run_cmd $SPATCH -D patch \ |
117 | $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | |
118 | run_cmd $SPATCH -D report \ | |
119 | $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ | |
120 | run_cmd $SPATCH -D context \ | |
121 | $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ | |
122 | run_cmd $SPATCH -D org \ | |
123 | $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 | |
c05cd6dd | 124 | elif [ "$MODE" = "rep+ctxt" ] ; then |
5303265a BS |
125 | run_cmd $SPATCH -D report \ |
126 | $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \ | |
127 | run_cmd $SPATCH -D context \ | |
128 | $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 | |
1e9dea2a | 129 | else |
5303265a | 130 | run_cmd $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 |
1e9dea2a | 131 | fi |
74425eee | 132 | |
74425eee NP |
133 | } |
134 | ||
135 | if [ "$COCCI" = "" ] ; then | |
136 | for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do | |
1e9dea2a | 137 | coccinelle $f |
74425eee NP |
138 | done |
139 | else | |
1e9dea2a | 140 | coccinelle $COCCI |
74425eee | 141 | fi |