-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtools
More file actions
executable file
·144 lines (118 loc) · 3.3 KB
/
tools
File metadata and controls
executable file
·144 lines (118 loc) · 3.3 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env sh
set -eu
if [ -f .env ]; then
. ./.env
fi
color_green='\033[32m'
color_red='\033[0;31m'
color_reset='\033[0m'
build_native_debug_dir=build-native-debug
native_debug_bin=yali-native
native_debug_test_bin=yali-native-tests
info() {
printf "%b%s%b\n" "$color_green" "$1" "$color_reset"
}
error() {
printf "%b%s%b\n" "$color_red" "$1" "$color_reset"
}
if command -v clang-20 >/dev/null 2>&1; then
clang_tidy=clang-tidy-20
clang_format=clang-format-20
llvm_profdata=llvm-profdata-20
llvm_cov=llvm-cov-20
elif command -v clang-19 >/dev/null 2>&1; then
error 'You are running LLVM/Clang 19. Install LLVM/Clang 20!'
clang_tidy=clang-tidy-19
clang_format=clang-format-19
llvm_profdata=llvm-profdata-19
llvm_cov=llvm-cov-19
else
if [ -z "$LLVM_BIN_PATH" ]; then
error 'Clang not found in PATH, and no LLVM_BIN_PATH in .env'
exit 1
fi
clang_tidy=$LLVM_BIN_PATH/clang-tidy
clang_format=$LLVM_BIN_PATH/clang-format
llvm_profdata=$LLVM_BIN_PATH/llvm-profdata
llvm_cov=$LLVM_BIN_PATH/llvm-cov
fi
assert_debug_target() {
if [ ! -f "$build_native_debug_dir/$1" ]; then
error "The '$1' target with the 'Debug' build configuration
has not been built yet.
Build the target using CMake."
exit 1
fi
}
run_clang_tidy() {
assert_debug_target $native_debug_bin
info 'Running ClangTidy on the Commodore version...'
$clang_tidy --quiet --config-file .clang-tidy --extra-arg=-std=c99 --extra-arg=-D__CC65__ src/*.[ch]
echo
info 'Running ClangTidy on the native version...'
$clang_tidy --quiet --config-file .clang-tidy -p $build_native_debug_dir ./**/*.[ch]
}
run_cppcheck() {
if ! command -v cppcheck >/dev/null 2>&1; then
error 'You don'\''t have Cppcheck installed.'
error 'Install Cppcheck by running '\''sudo apt install cppcheck'\''.'
exit 1
fi
assert_debug_target $native_debug_bin
info 'Running Cppcheck on all source files...'
cppcheck \
--std=c23 \
--enable=all \
--check-level=exhaustive \
--inline-suppr \
--suppress=*:*unity.c \
--suppress=missingIncludeSystem:* \
--project=$build_native_debug_dir/compile_commands.json \
--cppcheck-build-dir=$build_native_debug_dir
}
run_clang_format() {
info 'Running ClangFormat on all source files...'
$clang_format --verbose -i -- **/*.[ch]
}
run_tests() {
assert_debug_target $native_debug_test_bin
info 'Running CTest...'
ctest --extra-verbose --test-dir $build_native_debug_dir
echo
info 'Running llvm-profdata...'
$llvm_profdata merge \
-sparse \
$build_native_debug_dir/default.profraw \
-o $build_native_debug_dir/default.profdata
echo
info 'Running llvm-cov report...'
$llvm_cov report \
$build_native_debug_dir/$native_debug_test_bin \
-instr-profile=$build_native_debug_dir/default.profdata \
--ignore-filename-regex='(unity|unity_internals)'
echo
info 'Running llvm-cov show...'
$llvm_cov show \
$build_native_debug_dir/$native_debug_test_bin \
-instr-profile=$build_native_debug_dir/default.profdata \
--ignore-filename-regex='(unity|unity_internals)' \
-format=html \
--output-dir=$build_native_debug_dir/coverage
}
case "$1" in
lint)
run_clang_tidy
echo
run_cppcheck
;;
format)
run_clang_format
;;
test)
run_tests
;;
*)
printf "Usage:\n%s [lint|format|test]\n" "$0"
exit 1
;;
esac