Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 107 lines (87 sloc) 3.013 kb
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
1 #!/bin/sh
2
3 SPATCH="`which ${SPATCH:=spatch}`"
4
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
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"
2c1160c @npalix Coccinelle: Add a new mode named 'chain'
npalix authored
19 OPTIONS="-dir $srctree"
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
20 fi
21
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
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
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
28 if [ "$ONLINE" = "0" ] ; then
2c1160c @npalix Coccinelle: Add a new mode named 'chain'
npalix authored
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'
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
31 echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
32 fi
2c1160c @npalix Coccinelle: Add a new mode named 'chain'
npalix authored
33 MODE="chain"
03ee0c4 @npalix Coccinelle: Use the -no_show_diff option for org and report mode
npalix authored
34 elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
062c182 @npalix Coccinelle: Add contextual message
npalix authored
35 FLAGS="$FLAGS -no_show_diff"
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
36 fi
37
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
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
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
44
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
45 coccinelle () {
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
46 COCCI="$1"
47
48 OPT=`grep "Option" $COCCI | cut -d':' -f2`
49
062c182 @npalix Coccinelle: Add contextual message
npalix authored
50 # The option '-parse_cocci' can be used to syntactically check the SmPL files.
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
51 #
52 # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
53
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
54 if [ "$ONLINE" = "0" ] ; then
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
55
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
56 FILE=`echo $COCCI | sed "s|$srctree/||"`
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
57
3c90841 @npalix Coccinelle: Improve user information with a new kind of comment
npalix authored
58 echo "Processing `basename $COCCI`"
59 echo "with option(s) \"$OPT\""
60 echo ''
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
61 echo 'Message example to submit a patch:'
62
3c90841 @npalix Coccinelle: Improve user information with a new kind of comment
npalix authored
63 sed -ne 's|^///||p' $COCCI
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
64
062c182 @npalix Coccinelle: Add contextual message
npalix authored
65 if [ "$MODE" = "patch" ] ; then
66 echo ' The semantic patch that makes this change is available'
67 elif [ "$MODE" = "report" ] ; then
68 echo ' The semantic patch that makes this report is available'
69 elif [ "$MODE" = "context" ] ; then
70 echo ' The semantic patch that spots this code is available'
71 elif [ "$MODE" = "org" ] ; then
72 echo ' The semantic patch that makes this Org report is available'
73 else
74 echo ' The semantic patch that makes this output is available'
75 fi
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
76 echo " in $FILE."
77 echo ''
78 echo ' More information about semantic patching is available at'
79 echo ' http://coccinelle.lip6.fr/'
80 echo ''
81
3c90841 @npalix Coccinelle: Improve user information with a new kind of comment
npalix authored
82 if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
83 echo 'Semantic patch information:'
84 sed -ne 's|^//#||p' $COCCI
85 echo ''
86 fi
2c1160c @npalix Coccinelle: Add a new mode named 'chain'
npalix authored
87 fi
3c90841 @npalix Coccinelle: Improve user information with a new kind of comment
npalix authored
88
2c1160c @npalix Coccinelle: Add a new mode named 'chain'
npalix authored
89 if [ "$MODE" = "chain" ] ; then
03ee0c4 @npalix Coccinelle: Use the -no_show_diff option for org and report mode
npalix authored
90 $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
91 $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \
92 $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
93 $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
94 else
2c1160c @npalix Coccinelle: Add a new mode named 'chain'
npalix authored
95 $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
96 fi
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
97
98 }
99
100 if [ "$COCCI" = "" ] ; then
101 for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
102 coccinelle $f
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
103 done
104 else
1e9dea2 @npalix Add support for the C variable in the coccicheck script
npalix authored
105 coccinelle $COCCI
74425ee @npalix Add a target to use the Coccinelle checker
npalix authored
106 fi
Something went wrong with that request. Please try again.