3 # If we have coccinelle installed, run try_parse.sh on every filename passed
4 # as an argument. If no filenames are supplied, scan a standard Tor 0.3.5 or
5 # later directory layout.
7 # Uses the default coccinelle exceptions file, or $TOR_COCCI_EXCEPTIONS_FILE,
10 # Use TOR_COCCI_EXCEPTIONS_FILE=/dev/null check_cocci_parse.sh to disable
11 # the default exception file.
13 # If spatch is not installed, remind the user to install it, but exit with
14 # a success error status.
16 scripts_cocci
="$(dirname "$0")"
17 top
="$scripts_cocci/../.."
18 try_parse
="$scripts_cocci/try_parse.sh"
22 export TOR_COCCI_EXCEPTIONS_FILE
="${TOR_COCCI_EXCEPTIONS_FILE:-$scripts_cocci/exceptions.txt}"
24 PURPOSE
="cocci C parsing"
26 echo "Checking spatch:"
28 if ! command -v spatch
; then
29 echo "Install coccinelle's spatch to check $PURPOSE."
33 # Returns true if $1 is greater than or equal to $2
36 if test "$1" = "$2" ; then
40 LOWER_VERSION
="$(printf '%s\n' "$1" "$2" | $SORT_V | head -n 1)"
42 test "$LOWER_VERSION" != "$1"
45 # 'sort -V' is a gnu extension
47 # Use 'sort -n' if 'sort -V' doesn't work
48 if ! version_ge
"1" "0" ; then
49 echo "Your 'sort -V' command appears broken. Falling back to 'sort -n'."
50 echo "Some spatch version checks may give the wrong result."
54 # Print the full spatch version, for diagnostics
58 # This pattern needs to handle version strings like:
59 # spatch version 1.0.0-rc19
60 # spatch version 1.0.6 compiled with OCaml version 4.05.0
61 SPATCH_V
=$
(spatch
--version |
head -1 | \
62 sed 's/spatch version \([0-9][^ ]*\).*/\1/')
64 if ! version_ge
"$SPATCH_V" "$MIN_SPATCH_V" ; then
65 echo "Tor requires coccinelle spatch >= $MIN_SPATCH_V to check $PURPOSE."
66 echo "But you have $SPATCH_V. Please install a newer version."
70 if test $# -ge 1 ; then
75 # This is the layout in 0.3.5
76 # Keep these lists consistent:
77 # - OWNED_TOR_C_FILES in Makefile.am
78 # - CHECK_FILES in pre-commit.git-hook and pre-push.git-hook
79 # - try_parse in check_cocci_parse.sh
83 src
/feature
/*/*.
[ch
] \
91 if test "$exitcode" != 0 ; then
92 echo "Please fix these $PURPOSE errors in the above files"
93 echo "Set VERBOSE=1 for more details"
94 echo "Try running test-operator-cleanup or 'make autostyle-operators'"
95 echo "As a last resort, you can modify scripts/coccinelle/exceptions.txt"