coccicheck 3.2 KB

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