Add clang-tidy configuration and watch script for improved code quality checks
This commit is contained in:
1 parent
fb273e0f8f
commit
fca0c19207
5 files changed
+197
No files matched your search
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
set -u
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT_DIR" || exit 1
|
||||
|
||||
EXTRA_ARGS=(
|
||||
-extra-arg=-isystem
|
||||
-extra-arg=/opt/devkitpro/devkitARM/arm-none-eabi/include/c++/15.2.0
|
||||
-extra-arg=-isystem
|
||||
-extra-arg=/opt/devkitpro/devkitARM/arm-none-eabi/include/c++/15.2.0/arm-none-eabi
|
||||
-extra-arg=-isystem
|
||||
-extra-arg=/opt/devkitpro/devkitARM/arm-none-eabi/include/c++/15.2.0/backward
|
||||
-extra-arg=-isystem
|
||||
-extra-arg=/opt/devkitpro/devkitARM/lib/gcc/arm-none-eabi/15.2.0/include
|
||||
-extra-arg=-isystem
|
||||
-extra-arg=/opt/devkitpro/devkitARM/lib/gcc/arm-none-eabi/15.2.0/include-fixed
|
||||
-extra-arg=-isystem
|
||||
-extra-arg=/opt/devkitpro/devkitARM/arm-none-eabi/include
|
||||
)
|
||||
|
||||
rebuild_tidy_db() {
|
||||
mkdir -p .clang-tidy-db
|
||||
sed 's/-mthumb-interwork//g' compile_commands.json > .clang-tidy-db/compile_commands.json
|
||||
}
|
||||
|
||||
collect_sources() {
|
||||
find source include -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.cxx' \) 2>/dev/null | sort
|
||||
}
|
||||
|
||||
declare -A mtimes
|
||||
last_cc_mtime=""
|
||||
|
||||
while true; do
|
||||
if [[ ! -f compile_commands.json ]]; then
|
||||
echo "Waiting for compile_commands.json (run CMake configure/build once)..."
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
cc_mtime="$(stat -c %Y compile_commands.json 2>/dev/null || echo 0)"
|
||||
db_regenerated=0
|
||||
if [[ "$cc_mtime" != "$last_cc_mtime" ]]; then
|
||||
rebuild_tidy_db
|
||||
last_cc_mtime="$cc_mtime"
|
||||
db_regenerated=1
|
||||
fi
|
||||
|
||||
mapfile -t files < <(collect_sources)
|
||||
changed=()
|
||||
|
||||
for f in "${files[@]}"; do
|
||||
m="$(stat -c %Y "$f" 2>/dev/null || echo 0)"
|
||||
if [[ "${mtimes[$f]:-}" != "$m" ]]; then
|
||||
changed+=("$f")
|
||||
mtimes["$f"]="$m"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $db_regenerated -eq 1 && ${#files[@]} -gt 0 ]]; then
|
||||
changed=("${files[@]}")
|
||||
fi
|
||||
|
||||
if [[ ${#changed[@]} -gt 0 ]]; then
|
||||
echo "TIDY-WATCH-BEGIN"
|
||||
for f in "${changed[@]}"; do
|
||||
clang-tidy -quiet -p .clang-tidy-db "$f" "${EXTRA_ARGS[@]}" || true
|
||||
done
|
||||
echo "TIDY-WATCH-END"
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
Reference in new issue
Block a user