run-clang-tidy.sh 1.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
# Copyright (c) 2020 Daniel Vrátil <dvratil@kde.org>
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
# License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this library; see the file COPYING.LIB.  If not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

19
20
21
22
23
if [ $# -lt 1 ]; then
    >&2 echo "Usage: $0 BUILD_DIR"
    exit 1
fi

24
25
set -xe

26
BUILDDIR=$1; shift 1
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

function sanitize_compile_commands
{
    local cc_file=${BUILDDIR}/compile_commands.json
    local filter_file=".clang-tidy-ignore"

    if [ ! -f "${cc_file}" ]; then
        >&2 echo "Couldn't find compile_commands.json"
        exit 1
    fi

    if [ ! -f "${filter_file}" ]; then
        return 0
    fi

42
    filter_files=$(cat ${filter_file} | grep -vE "^#\.*|^$" | tr '\n' '|' | head -c -1)
43
44
45
46

    local cc_bak_file=${cc_file}.bak
    mv ${cc_file} ${cc_bak_file}

47
48
49
50
51
    cat ${cc_bak_file} \
        | jq -r "map(select(.file|test(\"${filter_files}\")|not))" \
        > ${cc_file}

    task_count=$(cat ${cc_file} | jq "length")
52
53
54
55
56
}

sanitize_compile_commands

cd ${BUILDDIR}
57
run-clang-tidy -j$(nproc) -q $@