coccicheck 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/sh
  2. SPATCH="`which ${SPATCH:=spatch}`"
  3. # The verbosity may be set by the environmental parameter V=
  4. # as for example with 'make V=1 coccicheck'
  5. if [ -n "$V" -a "$V" != "0" ]; then
  6. VERBOSE=1
  7. else
  8. VERBOSE=0
  9. fi
  10. if [ "$C" = "1" -o "$C" = "2" ]; then
  11. ONLINE=1
  12. # This requires Coccinelle >= 0.2.3
  13. # FLAGS="-ignore_unknown_options -very_quiet"
  14. # OPTIONS=$*
  15. # Workaround for Coccinelle < 0.2.3
  16. FLAGS="-I $srctree/include -very_quiet"
  17. shift $(( $# - 1 ))
  18. OPTIONS=$1
  19. else
  20. ONLINE=0
  21. FLAGS="-very_quiet"
  22. if [ "$KBUILD_EXTMOD" = "" ] ; then
  23. OPTIONS="-dir $srctree"
  24. else
  25. OPTIONS="-dir $KBUILD_EXTMOD -patch $srctree -I $srctree/include -I $KBUILD_EXTMOD/include"
  26. fi
  27. fi
  28. if [ ! -x "$SPATCH" ]; then
  29. echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
  30. exit 1
  31. fi
  32. if [ "$MODE" = "" ] ; then
  33. if [ "$ONLINE" = "0" ] ; then
  34. echo 'You have not explicitly specified the mode to use. Using default "chain" mode.'
  35. echo 'All available modes will be tried (in that order): patch, report, context, org'
  36. echo 'You can specify the mode with "make coccicheck MODE=<mode>"'
  37. fi
  38. MODE="chain"
  39. elif [ "$MODE" = "report" -o "$MODE" = "org" ] ; then
  40. FLAGS="$FLAGS -no_show_diff"
  41. fi
  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
  48. coccinelle () {
  49. COCCI="$1"
  50. OPT=`grep "Option" $COCCI | cut -d':' -f2`
  51. # The option '-parse_cocci' can be used to syntactically check the SmPL files.
  52. #
  53. # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
  54. if [ $VERBOSE -ne 0 ] ; then
  55. FILE=`echo $COCCI | sed "s|$srctree/||"`
  56. echo "Processing `basename $COCCI`"
  57. echo "with option(s) \"$OPT\""
  58. echo ''
  59. echo 'Message example to submit a patch:'
  60. sed -ne 's|^///||p' $COCCI
  61. if [ "$MODE" = "patch" ] ; then
  62. echo ' The semantic patch that makes this change is available'
  63. elif [ "$MODE" = "report" ] ; then
  64. echo ' The semantic patch that makes this report is available'
  65. elif [ "$MODE" = "context" ] ; then
  66. echo ' The semantic patch that spots this code is available'
  67. elif [ "$MODE" = "org" ] ; then
  68. echo ' The semantic patch that makes this Org report is available'
  69. else
  70. echo ' The semantic patch that makes this output is available'
  71. fi
  72. echo " in $FILE."
  73. echo ''
  74. echo ' More information about semantic patching is available at'
  75. echo ' http://coccinelle.lip6.fr/'
  76. echo ''
  77. if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
  78. echo 'Semantic patch information:'
  79. sed -ne 's|^//#||p' $COCCI
  80. echo ''
  81. fi
  82. fi
  83. if [ "$MODE" = "chain" ] ; then
  84. $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
  85. $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || \
  86. $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
  87. $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff || exit 1
  88. elif [ "$MODE" = "rep+ctxt" ] ; then
  89. $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS -no_show_diff && \
  90. $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
  91. else
  92. $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
  93. fi
  94. }
  95. if [ "$COCCI" = "" ] ; then
  96. for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
  97. coccinelle $f
  98. done
  99. else
  100. coccinelle $COCCI
  101. fi