-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_quality.sh
More file actions
executable file
Β·124 lines (115 loc) Β· 4.29 KB
/
check_quality.sh
File metadata and controls
executable file
Β·124 lines (115 loc) Β· 4.29 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
set -e
echo "============================================"
echo "π iolinki Code Quality & Safety Check"
echo "============================================"
# 1. Compiler Warnings (Strict)
# We rely on CMake to set -Wall -Wextra -Werror via the build system
echo -e "\n[1/3] π‘οΈ Verifying Compilation Warnings..."
BUILD_DIR="${IOLINKI_BUILD_DIR:-build_quality}"
if [ -f "${BUILD_DIR}/CMakeCache.txt" ]; then
cached_src=$(grep -E '^CMAKE_HOME_DIRECTORY:INTERNAL=' "${BUILD_DIR}/CMakeCache.txt" | cut -d= -f2-)
if [ -n "${cached_src}" ] && [ "${cached_src}" != "$(pwd)" ]; then
rm -rf "${BUILD_DIR}"
fi
fi
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
# Enable Strict Mode (we need to add this flag support to CMakeLists or force it here)
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-Wall -Wextra -Werror -Wpedantic -Wconversion -Wshadow"
if make -j"$(nproc)"; then
echo " β
Strict Compilation Passed"
else
echo " β Strict Compilation FAILED"
exit 1
fi
cd ..
# 2. Static Analysis (Cppcheck)
echo -e "\n[2/4] π§Ή Running Static Analysis (Cppcheck)..."
if command -v cppcheck &> /dev/null; then
# Run cppcheck with rigorous settings
# --enable=all: Enable all checks (style, performance, portability, etc.)
# --suppress=missingIncludeSystem: Don't fail on missing standard headers
# --error-exitcode=1: Fail script if errors found
# --addon=misra: Ideally we would use this, but it requires a rules text file.
# We'll use --enable=warning,style,performance,portability for now.
if cppcheck --enable=warning,style,performance,portability \
--error-exitcode=1 \
--suppress=missingIncludeSystem \
--inline-suppr \
--quiet \
-I include \
src/ examples/; then
echo " β
Static Analysis Passed"
else
echo " β Static Analysis FAILED"
exit 1
fi
else
echo " β οΈ Cppcheck not installed. Skipping static analysis."
echo " Install with: sudo apt-get install cppcheck"
fi
# 3. MISRA C:2012 Check (Cppcheck addon)
echo -e "\n[3/4] π Running MISRA C:2012 Check..."
if command -v cppcheck &> /dev/null; then
# Use cppcheck MISRA addon if available in the environment.
# If the addon is not present, fail in enforce mode.
MISRA_ADDON=""
for path in /usr/share/cppcheck/addons/misra.py /usr/lib/cppcheck/addons/misra.py; do
if [ -f "$path" ]; then
MISRA_ADDON="$path"
break
fi
done
if [ -n "$MISRA_ADDON" ]; then
cppcheck --addon=misra \
--enable=warning,style,performance,portability \
--error-exitcode=1 \
--suppress=missingIncludeSystem \
--inline-suppr \
--quiet \
-I include \
src/ examples/
echo " β
MISRA Check Passed"
else
if [ "${IOLINKI_MISRA_ENFORCE}" = "1" ]; then
echo " β MISRA addon not available in cppcheck. Enforced mode fails."
exit 1
else
echo " β οΈ Cppcheck MISRA addon not available. Skipping MISRA checks."
fi
fi
else
echo " β οΈ Cppcheck not installed. Skipping MISRA checks."
fi
# 4. Code Formatting Check
echo -e "\n[4/5] π¨ Checking Code Formatting..."
if command -v clang-format &> /dev/null; then
if find src include tests examples -type f \( -name "*.c" -o -name "*.h" \) -print0 | xargs -0 clang-format --dry-run --Werror; then
echo " β
Code Formatting Passed"
else
echo " β Code Formatting FAILED"
exit 1
fi
else
echo " β οΈ clang-format not installed. Skipping check."
fi
# 5. Doxygen Warning Check
echo -e "\n[5/5] π Checking Doxygen Warnings..."
if command -v doxygen &> /dev/null; then
doxygen Doxyfile > /dev/null 2> doxygen.log
if grep -q "warning:" doxygen.log; then
echo " β Doxygen warnings found:"
grep "warning:" doxygen.log
exit 1
else
echo " β
Doxygen Check Passed"
rm doxygen.log
fi
else
echo " β οΈ Doxygen not installed. Skipping check."
fi
echo -e "\n============================================"
echo "β
Code Quality Checks Completed"
echo "============================================"
exit 0