-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathclang-tidy.sh
More file actions
executable file
·60 lines (51 loc) · 1.96 KB
/
clang-tidy.sh
File metadata and controls
executable file
·60 lines (51 loc) · 1.96 KB
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
#!/usr/bin/env bash
set -eu
set -o pipefail
# https://clang.llvm.org/extra/clang-tidy/
: '
Runs clang-tidy on the code in src/
Return `1` if there are files automatically fixed by clang-tidy.
Returns `0` if no fixes by clang-tidy.
TODO: should also return non-zero if clang-tidy emits warnings
or errors about things it cannot automatically fix. However I cannot
figure out how to get this working yet as it seems that clang-tidy
always returns 0 even on errors.
'
PATH_TO_CLANG_TIDY_SCRIPT="$(pwd)/mason_packages/.link/share/run-clang-tidy.py"
# make sure that run-clang-tidy.py can find the right clang-tidy
export PATH=$(pwd)/mason_packages/.link/bin:${PATH}
# build the compile_commands.json file if it does not exist
if [[ ! -f build/compile_commands.json ]]; then
# We need to clean otherwise when we make the project
# will will not see all the compile commands
make clean
# Create the build directory to put the compile_commands in
# We do this first to ensure it is there to start writing to
# immediately (make make not create it right away)
mkdir -p build
# Run make, pipe the output to the generate_compile_commands.py
# and drop them in a place that clang-tidy will automatically find them
RESULT=0
make | tee /tmp/make-node-cpp-skel-build-output.txt || RESULT=$?
if [[ ${RESULT} != 0 ]]; then
echo "Build failed, could not generate compile commands for clang-tidy, aborting!"
exit ${RESULT}
else
cat /tmp/make-node-cpp-skel-build-output.txt | scripts/generate_compile_commands.py > build/compile_commands.json
fi
fi
# change into the build directory so that clang-tidy can find the files
# at the right paths (since this is where the actual build happens)
cd build
${PATH_TO_CLANG_TIDY_SCRIPT} -fix
cd ../
# Print list of modified files
dirty=$(git ls-files --modified src/)
if [[ $dirty ]]; then
echo "The following files have been modified:"
echo $dirty
git diff
exit 1
else
exit 0
fi