coccicheck 2.9 KB

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