aboutsummaryrefslogtreecommitdiffstats
path: root/tools/validate-clang-check.sh
blob: 2d295bcc7e23096e5bf9b8a3e3bde7c52d86d7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Copyright 2018, Alexis La Goutte (See AUTHORS file)
#
# Verifies last commit with clang-check (like scan-build) for Petri Dish
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 1998 Gerald Combs
#
# SPDX-License-Identifier: GPL-2.0-or-later
#

COMMIT_FILES=$( git diff-index --cached --name-status HEAD^ | grep -v "^D" | cut -f2 | grep "\\.c$\|cpp$" )
CLANG_CHECK_CMD=clang-check

while getopts c: OPTCHAR
do
    case $OPTCHAR in
    c)
        CLANG_CHECK_CMD="clang-check-$OPTARG"
        ;;
    *)
        echo "Usage: $( basename "$0" ) [ -c <clang version> ]"
        exit 0
    esac
done

for FILE in $COMMIT_FILES; do
    # Skip some special cases
    FILE_BASENAME="$( basename "$FILE" )"
    # If we don't have a build rule for this file, it's probably because we're missing
    # necessary includes.
    for BUILD_RULE_FILE in compile_commands.json build.ninja ; do
        if [[ -f $BUILD_RULE_FILE ]] && ! grep "/$FILE_BASENAME\." $BUILD_RULE_FILE &> /dev/null ; then
            echo "Don't know how to build $FILE_BASENAME. Skipping."
            continue 2
        fi
    done
    # wsutil/file_util.c is Windows-only.
    if test "$FILE_BASENAME" = "file_util.c"
    then
        continue
    fi
    # iLBC: the file is not even compiled when ilbc is not installed
    if test "$FILE_BASENAME" = "iLBCdecode.c"
    then
        continue
    fi
    # This is a template file, not a final '.c' file.
    if echo "$FILE_BASENAME" | grep -Eq "packet-.*-template.c"
    then
        continue
    fi

    "$CLANG_CHECK_CMD" "../$FILE"
    "$CLANG_CHECK_CMD" -analyze "../$FILE"
done