Blame view
scripts/coccicheck
3.23 KB
74425eee7 Add a target to u... |
1 2 3 |
#!/bin/sh SPATCH="`which ${SPATCH:=spatch}`" |
1e9dea2a6 Add support for t... |
4 5 6 7 8 9 |
if [ "$C" = "1" -o "$C" = "2" ]; then ONLINE=1 # This requires Coccinelle >= 0.2.3 # FLAGS="-ignore_unknown_options -very_quiet" # OPTIONS=$* |
d0bc1fb46 coccicheck: add M... |
10 11 12 13 14 15 16 17 18 |
if [ "$KBUILD_EXTMOD" = "" ] ; then # Workaround for Coccinelle < 0.2.3 FLAGS="-I $srctree/include -very_quiet" shift $(( $# - 1 )) OPTIONS=$1 else echo M= is not currently supported when C=1 or C=2 exit 1 fi |
1e9dea2a6 Add support for t... |
19 20 21 |
else ONLINE=0 FLAGS="-very_quiet" |
d0bc1fb46 coccicheck: add M... |
22 23 24 25 26 |
if [ "$KBUILD_EXTMOD" = "" ] ; then OPTIONS="-dir $srctree" else OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include -I $KBUILD_EXTMOD/include" fi |
1e9dea2a6 Add support for t... |
27 |
fi |
74425eee7 Add a target to u... |
28 29 30 31 32 33 |
if [ ! -x "$SPATCH" ]; then echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' exit 1 fi if [ "$MODE" = "" ] ; then |
1e9dea2a6 Add support for t... |
34 |
if [ "$ONLINE" = "0" ] ; then |
2c1160c87 Coccinelle: Add a... |
35 36 |
echo 'You have not explicitly specified the mode to use. Using default "chain" mode.' echo 'All available modes will be tried (in that order): patch, report, context, org' |
1e9dea2a6 Add support for t... |
37 |
echo 'You can specify the mode with "make coccicheck MODE=<mode>"' |
1e9dea2a6 Add support for t... |
38 |
fi |
2c1160c87 Coccinelle: Add a... |
39 |
MODE="chain" |
03ee0c42a Coccinelle: Use t... |
40 |
elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then |
062c1825a Coccinelle: Add c... |
41 |
FLAGS="$FLAGS -no_show_diff" |
74425eee7 Add a target to u... |
42 |
fi |
1e9dea2a6 Add support for t... |
43 44 45 46 47 48 |
if [ "$ONLINE" = "0" ] ; then echo '' echo 'Please check for false positives in the output before submitting a patch.' echo 'When using "patch" mode, carefully review the patch before submitting it.' echo '' fi |
74425eee7 Add a target to u... |
49 |
|
1e9dea2a6 Add support for t... |
50 |
coccinelle () { |
74425eee7 Add a target to u... |
51 |
COCCI="$1" |
74425eee7 Add a target to u... |
52 53 |
OPT=`grep "Option" $COCCI | cut -d':' -f2` |
74425eee7 Add a target to u... |
54 |
|
062c1825a Coccinelle: Add c... |
55 |
# The option '-parse_cocci' can be used to syntactically check the SmPL files. |
1e9dea2a6 Add support for t... |
56 57 |
# # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null |
74425eee7 Add a target to u... |
58 |
|
1e9dea2a6 Add support for t... |
59 |
if [ "$ONLINE" = "0" ] ; then |
74425eee7 Add a target to u... |
60 |
|
1e9dea2a6 Add support for t... |
61 |
FILE=`echo $COCCI | sed "s|$srctree/||"` |
74425eee7 Add a target to u... |
62 |
|
3c9084176 Coccinelle: Impro... |
63 64 65 |
echo "Processing `basename $COCCI`" echo "with option(s) \"$OPT\"" echo '' |
1e9dea2a6 Add support for t... |
66 |
echo 'Message example to submit a patch:' |
3c9084176 Coccinelle: Impro... |
67 |
sed -ne 's|^///||p' $COCCI |
1e9dea2a6 Add support for t... |
68 |
|
062c1825a Coccinelle: Add c... |
69 70 71 72 73 74 75 76 77 78 79 |
if [ "$MODE" = "patch" ] ; then echo ' The semantic patch that makes this change is available' elif [ "$MODE" = "report" ] ; then echo ' The semantic patch that makes this report is available' elif [ "$MODE" = "context" ] ; then echo ' The semantic patch that spots this code is available' elif [ "$MODE" = "org" ] ; then echo ' The semantic patch that makes this Org report is available' else echo ' The semantic patch that makes this output is available' fi |
1e9dea2a6 Add support for t... |
80 81 82 83 84 |
echo " in $FILE." echo '' echo ' More information about semantic patching is available at' echo ' http://coccinelle.lip6.fr/' echo '' |
3c9084176 Coccinelle: Impro... |
85 86 87 88 89 |
if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then echo 'Semantic patch information:' sed -ne 's|^//#||p' $COCCI echo '' fi |
2c1160c87 Coccinelle: Add a... |
90 |
fi |
3c9084176 Coccinelle: Impro... |
91 |
|
2c1160c87 Coccinelle: Add a... |
92 |
if [ "$MODE" = "chain" ] ; then |
03ee0c42a Coccinelle: Use t... |
93 94 95 96 |
$SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \ $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \ $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1 |
1e9dea2a6 Add support for t... |
97 |
else |
2c1160c87 Coccinelle: Add a... |
98 |
$SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1 |
1e9dea2a6 Add support for t... |
99 |
fi |
74425eee7 Add a target to u... |
100 |
|
74425eee7 Add a target to u... |
101 102 103 104 |
} if [ "$COCCI" = "" ] ; then for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do |
1e9dea2a6 Add support for t... |
105 |
coccinelle $f |
74425eee7 Add a target to u... |
106 107 |
done else |
1e9dea2a6 Add support for t... |
108 |
coccinelle $COCCI |
74425eee7 Add a target to u... |
109 |
fi |