forked from ON4QZ/QSSTV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-clang-tidy.sh
More file actions
executable file
·96 lines (84 loc) · 2.74 KB
/
run-clang-tidy.sh
File metadata and controls
executable file
·96 lines (84 loc) · 2.74 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# Run clang-tidy on the QSSTV codebase
# Usage: ./run-clang-tidy.sh [--fix] [--errors-only]
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Check if compile_commands.json exists
if [ ! -f "build/compile_commands.json" ]; then
echo -e "${RED}Error: build/compile_commands.json not found${NC}"
echo "Please run the following commands first:"
echo " cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .."
exit 1
fi
# Determine clang-tidy path
if command -v clang-tidy &> /dev/null; then
CLANG_TIDY="clang-tidy"
elif [ -f "/usr/local/opt/llvm/bin/clang-tidy" ]; then
CLANG_TIDY="/usr/local/opt/llvm/bin/clang-tidy"
else
echo -e "${RED}Error: clang-tidy not found${NC}"
echo "Install with: brew install llvm"
exit 1
fi
# Parse arguments
FIX_FLAG=""
ERRORS_ONLY=false
for arg in "$@"; do
case $arg in
--fix)
FIX_FLAG="-fix"
echo -e "${YELLOW}Running clang-tidy with automatic fixes...${NC}"
;;
--errors-only)
ERRORS_ONLY=true
echo -e "${YELLOW}Showing critical errors only...${NC}"
;;
*)
echo "Usage: $0 [--fix] [--errors-only]"
exit 1
;;
esac
done
if [ -z "$FIX_FLAG" ]; then
echo -e "${YELLOW}Running clang-tidy in check-only mode...${NC}"
echo "Use --fix to automatically apply fixes"
fi
# Find all C++ source and header files (excluding xmlrpc third-party code)
FILES=$(find src -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" | grep -v "/xmlrpc/")
# Run clang-tidy on each file
TOTAL=0
ERRORS=0
for FILE in $FILES; do
TOTAL=$((TOTAL + 1))
echo -e "${YELLOW}[$TOTAL] Checking $FILE...${NC}"
OUTPUT=$($CLANG_TIDY "$FILE" -p build $FIX_FLAG --system-headers=false 2>&1 || true)
# Filter out warnings from system headers and third-party libraries
FILTERED=$(echo "$OUTPUT" | grep -v "/usr/local/" | \
grep -v "/usr/include/" | \
grep -v "/Library/Frameworks/" | \
grep -v "Qt[A-Z]" | \
grep -v "warning:.*generated" || true)
if [ "$ERRORS_ONLY" = true ]; then
# Show only critical errors
if echo "$FILTERED" | grep -q "error:"; then
echo "$FILTERED" | grep "error:"
ERRORS=$((ERRORS + 1))
fi
else
# Show filtered output
if [ -n "$FILTERED" ]; then
echo "$FILTERED"
fi
fi
done
echo ""
if [ $ERRORS -gt 0 ]; then
echo -e "${RED}Found $ERRORS file(s) with critical errors${NC}"
exit 1
else
echo -e "${GREEN}Clang-tidy analysis complete! Checked $TOTAL files.${NC}"
fi