coccicheck 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 specify 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` with option(s) \"$OPT\""
  43. echo 'Message example to submit a patch:'
  44. sed -e '/\/\/\//!d' -e 's|^///||' $COCCI
  45. echo ' The semantic patch that makes this change is available'
  46. echo " in $FILE."
  47. echo ''
  48. echo ' More information about semantic patching is available at'
  49. echo ' http://coccinelle.lip6.fr/'
  50. echo ''
  51. $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT -dir $srctree || exit 1
  52. else
  53. $SPATCH -D $MODE $FLAGS -sp_file $COCCI $OPT $OPTIONS || exit 1
  54. fi
  55. }
  56. if [ "$COCCI" = "" ] ; then
  57. for f in `find $srctree/scripts/coccinelle/ -name '*.cocci' -type f | sort`; do
  58. coccinelle $f
  59. done
  60. else
  61. coccinelle $COCCI
  62. fi