ci(compiler): Add option --fix to lint_cpp.sh

Add an option `--fix` to `lint_cpp.sh` advising `clang-tidy` to apply
suggested fixes.
This commit is contained in:
Andi Drebes
2021-06-08 15:20:22 +02:00
committed by Quentin Bourgerie
parent bf101e5147
commit 5167781e44

View File

@@ -1,5 +1,16 @@
#!/bin/bash
print_usage() {
local FD=$1
echo "Usage: $0 [OPTION]" >&$FD
echo "Check if the sources comply with the checks from .clang-tidy" >&$FD
echo "" >&$FD
echo "Options:" >&$FD
echo " -f, --fix Advise clang-tidy to fix any issue" >&$FD
echo " found." >&$FD
echo " -h, --help Print this help." >&$FD
}
die() {
echo "$@" >&2
exit 1
@@ -13,6 +24,28 @@ check_buildfile() {
"directory."
}
CLANG_TIDY_EXTRA_ARGS=()
# Parse arguments
while [ $# -gt 0 ]
do
case $1 in
-f|--fix)
CLANG_TIDY_EXTRA_ARGS+=("--fix")
;;
-h|--help)
print_usage 1
exit 0
;;
*)
print_usage 2
exit 1
;;
esac
shift
done
check_buildfile "CMakeFiles/CMakeDirectoryInformation.cmake"
check_buildfile "compile_commands.json"
@@ -29,4 +62,5 @@ TOP_SRCDIR=$(grep -o 'set\s*(\s*CMAKE_RELATIVE_PATH_TOP_SOURCE\s\+"[^"]\+")' \
find "$TOP_SRCDIR/"{include,lib,src} \
\( -iname "*.h" -o -iname "*.cpp" -o -iname "*.cc" \) | \
xargs clang-tidy -p . -header-filter="$TOP_SRCDIR/include/.*\.h"
xargs clang-tidy -p . -header-filter="$TOP_SRCDIR/include/.*\.h" \
"${CLANG_TIDY_EXTRA_ARGS[@]}"