coccicheck 2.1 KB

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