forked from ArtificialAmateur/cpp-linter-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
runchecks.sh
50 lines (42 loc) · 1.78 KB
/
runchecks.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
#!/bin/bash
# save current location
REPO_PATH=$(pwd)
cp /usr/bin/run-clang-tidy.py $INPUT_BUILD_PATH
cd $INPUT_BUILD_PATH
# make the compile command database using bear
echo '::group::Run make to generate a compilation database'
bear -- make $INPUT_MAKE_OPTIONS || exit $?
echo '::endgroup::'
echo '::group::Run clang-tidy'
clang-tidy --version
echo
python3 run-clang-tidy.py -header-filter=$INPUT_HEADER_FILTER -ignore-files=$INPUT_IGNORE_FILES -j 2 -config-file=$GITHUB_WORKSPACE/.clang-tidy > $GITHUB_WORKSPACE/clang-tidy-report.txt
echo '::endgroup::'
# extract -I directories from the compilation database into a shell array
includes=()
eval "$(jq -r 'map(.arguments | map(select(startswith("-I")) | ltrimstr("-I")))
| flatten | unique
| @sh "includes=( \(.) )"' compile_commands.json)"
# split on all whitespace (including newlines)
# this avoids expanding globs
read -ra cppcheck_args -d '' <<<"$INPUT_CPPCHECK_OPTIONS"
# extract the directories to ignore from INPUT_IGNORE_FILES (split on '|')
IFS='|' read -ra ignore_files <<<"$INPUT_IGNORE_FILES"
for file in "${ignore_files[@]}"; do
# after checking the source code, -i also accepts globs
cppcheck_args+=(-i "*/$file/*")
# also suppress any errors from the ignored files
cppcheck_args+=("--suppress=*:*/$file/*")
# don't scan ignored directories for preprocessor variables
for include in "${includes[@]}"; do
if [[ $include = *"/$file/"* ]]; then
cppcheck_args+=("--config-exclude=$include")
fi
done
done
echo '::group::Run cppcheck'
cppcheck --version
echo "extra cppcheck arguments: ${cppcheck_args[*]}"
echo
cppcheck --enable=all --force --std=c++17 --language=c++ --project=compile_commands.json "${cppcheck_args[@]}" --output-file=$GITHUB_WORKSPACE/cppcheck-report.txt
echo '::endgroup::'