check_cocci_parse.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. # If we have coccinelle installed, run try_parse.sh on every filename passed
  3. # as an argument. If no filenames are supplied, scan a standard Tor 0.3.5 or
  4. # later directory layout.
  5. #
  6. # Uses the default coccinelle exceptions file, or $TOR_COCCI_EXCEPTIONS_FILE,
  7. # if it is set.
  8. #
  9. # Use TOR_COCCI_EXCEPTIONS_FILE=/dev/null check_cocci_parse.sh to disable
  10. # the default exception file.
  11. #
  12. # If spatch is not installed, remind the user to install it, but exit with
  13. # a success error status.
  14. scripts_cocci="$(dirname "$0")"
  15. top="$scripts_cocci/../.."
  16. try_parse="$scripts_cocci/try_parse.sh"
  17. exitcode=0
  18. export TOR_COCCI_EXCEPTIONS_FILE="${TOR_COCCI_EXCEPTIONS_FILE:-$scripts_cocci/exceptions.txt}"
  19. if ! command -v spatch; then
  20. echo "Install coccinelle's spatch to check cocci C parsing!"
  21. exit "$exitcode"
  22. fi
  23. if test $# -ge 1 ; then
  24. "$try_parse" "$@"
  25. exitcode=$?
  26. else
  27. # This is the layout in 0.3.5
  28. "$try_parse" \
  29. src/lib/*/*.[ch] \
  30. src/core/*/*.[ch] \
  31. src/feature/*/*.[ch] \
  32. src/app/*/*.[ch] \
  33. src/test/*.[ch] \
  34. src/test/*/*.[ch] \
  35. src/tools/*.[ch]
  36. exitcode=$?
  37. fi
  38. if test "$exitcode" != 0 ; then
  39. echo "Please fix these cocci parsing errors in the above files"
  40. echo "Set VERBOSE=1 for more details"
  41. echo "Try running test-operator-cleanup or 'make autostyle-operators'"
  42. echo "As a last resort, you can modify scripts/coccinelle/exceptions.txt"
  43. fi
  44. exit "$exitcode"