2 # Copyright 2018, Alexis La Goutte (See AUTHORS file)
4 # Verifies last commit with clang-check (like scan-build) for Petri Dish
6 # Wireshark - Network traffic analyzer
7 # By Gerald Combs <gerald@wireshark.org>
8 # Copyright 1998 Gerald Combs
10 # SPDX-License-Identifier: GPL-2.0-or-later
13 COMMIT_FILES
=$
( git diff-index
--cached --name-status HEAD^ |
grep -v "^D" | cut
-f2 |
grep "\\.c$\|cpp$" )
14 CLANG_CHECK_CMD
=clang-check
16 while getopts c
: OPTCHAR
20 CLANG_CHECK_CMD
="clang-check-$OPTARG"
23 echo "Usage: $( basename "$0" ) [ -c <clang version> ]"
28 for FILE
in $COMMIT_FILES; do
29 # Skip some special cases
30 FILE_BASENAME
="$( basename "$FILE" )"
31 # If we don't have a build rule for this file, it's probably because we're missing
33 for BUILD_RULE_FILE
in compile_commands.json build.ninja
; do
34 if [[ -f $BUILD_RULE_FILE ]] && ! grep "/$FILE_BASENAME\." $BUILD_RULE_FILE &> /dev
/null
; then
35 echo "Don't know how to build $FILE_BASENAME. Skipping."
39 # wsutil/file_util.c is Windows-only.
40 if test "$FILE_BASENAME" = "file_util.c"
44 # iLBC: the file is not even compiled when ilbc is not installed
45 if test "$FILE_BASENAME" = "iLBCdecode.c"
49 # This is a template file, not a final '.c' file.
50 if echo "$FILE_BASENAME" |
grep -Eq "packet-.*-template.c"
55 "$CLANG_CHECK_CMD" "../$FILE"
56 "$CLANG_CHECK_CMD" -analyze "../$FILE"