Skip to content

Commit c6a20a3

Browse files
Update generate_compilation_database.sh
1 parent da78841 commit c6a20a3

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
# We need this export to enable color output to the terminal using GitHub
4+
# Actions. If no, we will get the error while using commands in bash such
5+
# as `tput`.
6+
export TERM=xterm-color
7+
8+
# Check if there is clang-tidy installed.
9+
clang-tidy --version >/dev/null
10+
if [[ ${?} != 0 ]]; then
11+
tput setaf 1 # Red font in terminal.
12+
printf "Error: failed to find 'clang-tidy'.\n"
13+
tput sgr0 # Make font be default in terminal.
14+
printf "Make sure you have clang-tidy installed!\n"
15+
exit 1
16+
fi
17+
18+
# Check for existence of compile_commands.json.
19+
IFS=:
20+
compilation_database=$(find . -name 'compile_commands.json')
21+
unset IFS
22+
23+
if [[ ${#compilation_database} == 0 ]]; then
24+
tput setaf 1 # Red font in terminal.
25+
printf "Error: there is no compilation database "
26+
printf "(compile_commands.json) in your workspace!\n"
27+
tput sgr0 # Make font be default in terminal.
28+
#exit 1
29+
fi
30+
31+
# Check for existence of .clang-tidy.
32+
IFS=:
33+
clang_tidy_config_file=$(find . -name '\.clang-tidy')
34+
unset IFS
35+
36+
if [[ ${#clang_tidy_config_file} == 0 ]]; then
37+
tput setaf 1 # Red font in terminal.
38+
printf "Error: there is no .clang-tidy config file in your workspace!\n"
39+
tput sgr0 # Make font be default in terminal.
40+
exit 1
41+
fi
42+
43+
# Find all source files (.cc|.cxx|.cpp) we want to check with clang-tidy.
44+
# We do not include headers since clang-tidy has `--header-filter` option or
45+
# `HeaderFilterRegex` option (in .clang-tidy). With the help of this option
46+
# we can easily grab all warnings|errors from headers included in the source
47+
# files.
48+
IFS=:
49+
source_files=$(find . -name '*.cc' -o -name '*.cpp' -o -name '*.cxx')
50+
unset IFS
51+
52+
# Exit with success if there is no work to do.
53+
if [[ ${#source_files} == 0 ]]; then
54+
tput setaf 2 # Green font in terminal.
55+
printf "There are no source files to check with clang-tidy!\n"
56+
tput sgr0 # Reset terminal.
57+
exit 0
58+
fi
59+
60+
status_exit=0
61+
62+
# Run clang-tidy checks for every file.
63+
for file in ${source_files}
64+
do
65+
printf "Run clang-tidy on ${file} ...\n"
66+
67+
#clang-tidy --config-file="${clang_tidy_config_file}" -p ${compilation_database} ${file} -- -fdebug-prefix-map=$PWD=. -Ieventuals -Itest
68+
clang-tidy --config-file="${clang_tidy_config_file}" ${file} -- -x c++ -Ieventuals -Ieventuals/scheduler.h
69+
70+
clang_tidy_status=$(echo $?)
71+
if [[ ${clang_tidy_status} != 0 ]]
72+
then
73+
tput setaf 1 # Red font in terminal.
74+
printf "Error: ${file} needs to be fixed from clang-tidy warnings.\n"
75+
tput sgr0 # Reset terminal.
76+
status_exit=1
77+
fi
78+
done
79+
80+
exit ${status_exit}

compilation-database/generate_compilation_database.sh renamed to clang-tidy-review/generate_compilation_database.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
INSTALL_DIR="/dev-tools"
3+
INSTALL_DIR="dev-tools"
44
VERSION="0.5.2"
55

66
# Check if `generate.py` is already present.

0 commit comments

Comments
 (0)