-
Notifications
You must be signed in to change notification settings - Fork 68
/
run_clang_tidy.sh
executable file
·67 lines (58 loc) · 1.79 KB
/
run_clang_tidy.sh
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
58
59
60
61
62
63
64
65
66
67
#!/bin/bash -e
#
# Helper script to run clang-tidy on the codebase.
#
# Parse any input args.
build_dir=build-tidy
num_jobs=$(( $( command -v nproc > /dev/null && nproc || sysctl -n hw.physicalcpu ) / 2 ))
apply_fixits=
while getopts j:B:f opt; do
case $opt in
j) # Number of jobs to use during build/analysis
num_jobs="$OPTARG"
;;
B) # Location to put the build dir
build_dir="$OPTARG"
;;
f) # Attempt to apply fixits
apply_fixits="-fix"
;;
?) echo "Usage $0 [-j jobs] [-B build_dir] [-f]"
grep " .) #" $0 | grep -v grep
exit 1
;;
esac
done
# Check that we can actually find clang-tidy.
if ! command -v clang-tidy || ! command -v run-clang-tidy || ! command -v clang || ! command -v clang++ ; then
echo "Cannot find clang, clang-tidy, or run-clang-tidy"
exit 1
fi
# Use clang as the compiler so that vbz doesn't trip up clang-tidy.
export CC=clang
export CXX=clang++
# Assuming the current script is in /scripts.
source_dir=$(dirname $(dirname $0))
# Make a new build folder to analyse.
cmake \
-S ${source_dir} \
-B ${build_dir} \
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON
# Build dorado_utils so that its dependencies (htslib, etc...) get installed, otherwise
# clang-tidy can't find their headers.
cmake \
--build ${build_dir} \
--target dorado_utils \
--target vbz_hdf_plugin \
-j ${num_jobs}
# Remove any 3rdparty .clang-tidy's otherwise we check them for errors.
find ${source_dir}/dorado/3rdparty/* -name .clang-tidy -delete
# Print the current config to make sure it parses correctly.
clang-tidy --dump-config
# Run clang-tidy with our warnings.
# Note that we use run-clang-tidy to avoid the overhead of having to a full build too.
run-clang-tidy \
-p ${build_dir} \
-j ${num_jobs} \
${apply_fixits} \
-quiet