coccicheck 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. fi
  29. if [ "$ONLINE" = "0" ] ; then
  30. echo ''
  31. echo 'Please check for false positives in the output before submitting a patch.'
  32. echo 'When using "patch" mode, carefully review the patch before submitting it.'
  33. echo ''
  34. fi
  35. coccinelle () {
  36. COCCI="$1"
  37. OPT=`grep "Option" $COCCI | cut -d':' -f2`
  38. # The option '-parse_cocci' can be used to syntaxically check the SmPL files.
  39. #
  40. # $SPATCH -D $MODE $FLAGS -parse_cocci $COCCI $OPT > /dev/null
  41. if [ "$ONLINE" = "0" ] ; then
  42. FILE=`echo $COCCI | sed "s|$srctree/||"`
  43. echo "Processing `basename $COCCI`"
  44. echo "with option(s) \"$OPT\""
  45. echo ''
  46. echo 'Message example to submit a patch:'
  47. sed -ne 's|^///||p' $COCCI
  48. echo ' The semantic patch that makes this change is available'
  49. echo " in $FILE."
  50. echo ''
  51. echo ' More information about semantic patching is available at'
  52. echo ' http://coccinelle.lip6.fr/'
  53. echo ''
  54. if [ "`sed -ne 's|^//#||p' $COCCI`" ] ; then
  55. echo 'Semantic patch information:'
  56. sed -ne 's|^//#||p' $COCCI
  57. echo ''
  58. fi
  59. fi
  60. if [ "$MODE" = "chain" ] ; then
  61. $SPATCH -D patch $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
  62. $SPATCH -D report $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
  63. $SPATCH -D context $FLAGS -sp_file $COCCI $OPT $OPTIONS || \
  64. $SPATCH -D org $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
  65. else
  66. $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
  67. fi
  68. }
  69. if [ "$COCCI" = "" ] ; then
  70. for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
  71. coccinelle $f
  72. done
  73. else
  74. coccinelle $COCCI
  75. fi