coccicheck 3.1 KB

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