File indexing completed on 2024-05-12 05:12:39

0001 #!/bin/sh
0002 # SPDX-FileCopyrightText: 2020 Daniel Vrátil <dvratil@kde.org>
0003 #
0004 # SPDX-License-Identifier: LGPL-2.0-or-later
0005 
0006 if [ $# -lt 2 ]; then
0007     >&2 echo "Usage: $0 SOURCE_DIR BUILD_DIR"
0008     exit 1
0009 fi
0010 
0011 set -xe
0012 
0013 source_dir=$1; shift
0014 build_dir=$1; shift 1
0015 
0016 function sanitize_compile_commands
0017 {
0018     local cc_file=${build_dir}/compile_commands.json
0019     local filter_file="${source_dir}/.clang-tidy-ignore"
0020 
0021     if [ ! -f "${cc_file}" ]; then
0022         >&2 echo "Couldn't find compile_commands.json"
0023         exit 1
0024     fi
0025 
0026     if [ ! -f "${filter_file}" ]; then
0027         return 0
0028     fi
0029 
0030     filter_files=$(cat ${filter_file} | grep -vE "^#\.*|^$" | tr '\n' '|' | head -c -1)
0031 
0032     local cc_bak_file=${cc_file}.bak
0033     mv ${cc_file} ${cc_bak_file}
0034 
0035     cat ${cc_bak_file} \
0036         | jq -r "map(select(.file|test(\"${filter_files}\")|not))" \
0037         > ${cc_file}
0038 
0039     task_count=$(cat ${cc_file} | jq "length")
0040 }
0041 
0042 sanitize_compile_commands
0043 
0044 run-clang-tidy -p ${build_dir} -j$(nproc) -q $@ | tee ${build_dir}/clang-tidy.log
0045 cat ${build_dir}/clang-tidy.log | ${source_dir}/tools/clang-tidy-to-junit.py ${source_dir} > ${build_dir}/clang-tidy-report.xml
0046