mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-10 04:35:03 -05:00
ci(compiler): Add script for C++ linting
Add script `.github/workflows/scripts/lint_cpp.sh` that runs `clang-tidy` with the right parameters to limit checks to source files not generated automatically. The script must be run from within the build directory as it relies on `compiler_commands.json` and `CMakeFiles/CMakeDirectoryInformation.cmake`.
This commit is contained in:
32
.github/workflows/scripts/lint_cpp.sh
vendored
Executable file
32
.github/workflows/scripts/lint_cpp.sh
vendored
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
die() {
|
||||
echo "$@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_buildfile() {
|
||||
local FILE="$1"
|
||||
|
||||
[ -f "$FILE" ] ||
|
||||
die "$FILE not found. Please run this script from within your build " \
|
||||
"directory."
|
||||
}
|
||||
|
||||
check_buildfile "CMakeFiles/CMakeDirectoryInformation.cmake"
|
||||
check_buildfile "compile_commands.json"
|
||||
|
||||
# Extract toplevel source directory from CMakeDirectoryInformation.cmake
|
||||
# containing a line:
|
||||
#
|
||||
# set(CMAKE_RELATIVE_PATH_TOP_SOURCE "...")
|
||||
TOP_SRCDIR=$(grep -o 'set\s*(\s*CMAKE_RELATIVE_PATH_TOP_SOURCE\s\+"[^"]\+")' \
|
||||
CMakeFiles/CMakeDirectoryInformation.cmake | \
|
||||
sed 's/set\s*(\s*CMAKE_RELATIVE_PATH_TOP_SOURCE\s\+"\([^"]\+\)")/\1/g')
|
||||
|
||||
[ $? -eq 0 -a ! -z "$TOP_SRCDIR" ] ||
|
||||
die "Could not extract CMAKE_RELATIVE_PATH_TOP_SOURCE from CMake files."
|
||||
|
||||
find "$TOP_SRCDIR/"{include,lib,src} \
|
||||
\( -iname "*.h" -o -iname "*.cpp" -o -iname "*.cc" \) | \
|
||||
xargs clang-tidy -p . -header-filter="$TOP_SRCDIR/include/.*\.h"
|
||||
Reference in New Issue
Block a user