@@ -11,7 +11,7 @@ declare -F set_colors >/dev/null 2>&1 || { echo "[!] '$common_script' does not d
11
11
# Build unmatched suppressions for each *.c file.
12
12
cppcheck_build_unmatched () {
13
13
local file suppression=" "
14
- for file in * .c tools/ * .c ; do
14
+ for file in * .c; do
15
15
suppression+=" --suppress=unmatchedSuppression:$file "
16
16
done
17
17
echo " $suppression "
@@ -46,12 +46,11 @@ cppcheck_suppressions() {
46
46
" staticFunction:linenoise.c"
47
47
" nullPointerOutOfMemory:web.c"
48
48
" staticFunction:web.c"
49
- " constParameterCallback:tools/fmtscan.c"
50
49
)
51
50
52
51
# Array for additional cppcheck options (non-suppressions)
53
52
local -a other_flags=(
54
- " --inline-suppr harness.c --inline-suppr tools/fmtscan.c "
53
+ " --inline-suppr harness.c"
55
54
)
56
55
57
56
local out=" "
@@ -69,50 +68,20 @@ cppcheck_suppressions() {
69
68
printf " %s" " $out " | sed ' s/[[:space:]]*$//'
70
69
}
71
70
72
- # Generation of standard compliance for GCC/Clang
73
- detect_cc_std () {
74
- local STDC_VERSION=" "
75
- local EXTRA_DEFINES=" "
76
- if command -v cc > /dev/null 2>&1 ; then
77
- if cc --version 2> /dev/null | grep -q " clang" ; then
78
- STDC_VERSION=$( cc -dM -E -xc /dev/null | awk ' /__STDC_VERSION__/ {print $3}' )
79
- EXTRA_DEFINES=" -D__clang__=1"
80
- elif cc --version 2> /dev/null | grep -q " Free Software Foundation" ; then
81
- STDC_VERSION=$( cc -dM -E -xc /dev/null | awk ' /__STDC_VERSION__/ {print $3}' )
82
- EXTRA_DEFINES=" -D__GNUC__=1"
83
- fi
84
- fi
85
- if [ -n " $STDC_VERSION " ]; then
86
- EXTRA_DEFINES+=" -D__STDC__=1 -D__STDC_VERSION__=${STDC_VERSION} "
87
- fi
88
- echo " $EXTRA_DEFINES "
89
- }
90
-
91
71
CPPCHECK_OPTS=" -I. --enable=all --error-exitcode=1"
92
- CPPCHECK_OPTS+=" $( detect_cc_std) "
93
72
CPPCHECK_OPTS+=" --force $( cppcheck_suppressions) $( cppcheck_build_unmatched) "
94
- CPPCHECK_OPTS+=" --cppcheck-build-dir=.out"
73
+ CPPCHECK_OPTS+=" --cppcheck-build-dir=.out . "
95
74
96
75
set_colors
97
76
98
77
RETURN=0
99
78
100
79
# Disallow non-ASCII characters in workspace path
101
80
workspace=$( git rev-parse --show-toplevel)
102
- if echo " $workspace " | LC_ALL=C grep -q " [一-龥]" ; then
81
+ if echo " $workspace " | grep -q " [一-龥]" ; then
103
82
throw " The workspace path '$workspace ' contains non-ASCII characters."
104
83
fi
105
84
106
- # Check for merge conflict markers in staged changes.
107
- # Assemble the conflict marker regex without embedding it directly.
108
- CONFLICT_MARKERS=$( printf ' %s|%s|%s' " <<<<<<<" " =======" " >>>>>>>" )
109
- # Get staged files that contain conflict markers, but exclude hook files.
110
- CONFLICT_FILES=$( git diff --cached --name-only -G " ${CONFLICT_MARKERS} " | \
111
- grep -vE ' (^|/)\.git/hooks/|(^|/)(pre-commit|commit-msg|prepare-commit-msg|pre-push)\.hook$' )
112
- if [ -n " ${CONFLICT_FILES} " ]; then
113
- throw " Conflict markers are still present in the following files:\n%s" ${CONFLICT_FILES}
114
- fi
115
-
116
85
CLANG_FORMAT=$( which clang-format)
117
86
if [ $? -ne 0 ]; then
118
87
throw " clang-format not installed. Unable to check source file format policy."
@@ -179,8 +148,8 @@ if [ "${#binary_files[@]}" -gt 0 ]; then
179
148
printf " ${RED} [!]${NC} Binary data found.\n"
180
149
fi
181
150
182
- C_FILES =$( git diff --cached --name-only --diff-filter=ACMR | grep -E " \.(c|cpp|h|hpp )$" )
183
- for FILE in $C_FILES ; do
151
+ FILES =$( git diff --cached --name-only --diff-filter=ACMR | grep -E " \.(c|cpp|h)$" )
152
+ for FILE in $FILES ; do
184
153
nf=$( git checkout-index --temp $FILE | cut -f 1)
185
154
tempdir=$( mktemp -d) || exit 1
186
155
newfile=$( mktemp ${tempdir} /${nf} .XXXXXX) || exit 1
@@ -207,47 +176,9 @@ for FILE in $C_FILES; do
207
176
fi
208
177
done
209
178
210
- # Check syntax for changed shell scripts
211
- SHELL_FILES=()
212
- for file in " ${FILES[@]} " ; do
213
- if [[ " $file " =~ ^scripts/common\. sh$ || " $file " =~ ^scripts/.* \. hook$ ]]; then
214
- SHELL_FILES+=(" $file " )
215
- fi
216
- done
217
- if [ " ${# SHELL_FILES[@]} " -gt 0 ]; then
218
- for file in " ${SHELL_FILES[@]} " ; do
219
- if ! bash -n " $file " ; then
220
- throw " Syntax errors detected in $file ." >&2
221
- fi
222
- done
223
- fi
224
-
225
- ASPELL_DICT_FILE=' scripts/aspell-pws'
226
- if ! LC_ALL=C tail -n +2 $ASPELL_DICT_FILE | sort -f -cdu; then
227
- throw ' %s\n%s\n%s' \
228
- ' Aspell dictionary is unsorted or contains duplicated entries.' \
229
- ' Make sure that by using:' \
230
- " tail -n +2 $ASPELL_DICT_FILE | sort -f -du"
231
- fi
232
-
233
- # Show insertion and deletion counts.
234
- if [ " ${# FILES[@]} " -gt 0 ]; then
235
- echo " Following files were changed:"
236
- for file in " ${FILES[@]} " ; do
237
- summary=$( git diff --cached --numstat " $file " | awk ' {
238
- if ($1 != "0" && $2 != "0")
239
- printf "%s insertions(+), %s deletions(-)", $1, $2;
240
- else if ($1 != "0")
241
- printf "%s insertions(+)", $1;
242
- else if ($2 != "0")
243
- printf "%s deletions(-)", $2;
244
- }' )
245
- if [ -n " $summary " ]; then
246
- echo " - $file : $summary "
247
- else
248
- echo " - $file "
249
- fi
250
- done
179
+ if [ ! -z " ${FILES[*]} " ]; then
180
+ echo " Following files need to be cleaned up:"
181
+ echo " ${FILES[*]} "
251
182
fi
252
183
253
184
$SHA1SUM -c scripts/checksums 2> /dev/null > /dev/null
259
190
root=$( git rev-parse --show-toplevel)
260
191
banned=" ([^f]gets\()|(sprintf\()|(strcpy\()"
261
192
status=0
262
- for file in $C_FILES ; do
193
+ for file in $( git diff --staged --name-only | grep -E " \.(c|cc|cpp|h|hh|hpp)\$ " )
194
+ do
263
195
filepath=" ${root} /${file} "
264
196
output=$( grep -nrE " ${banned} " " ${filepath} " )
265
197
if [ ! -z " ${output} " ]; then
@@ -272,41 +204,21 @@ for file in $C_FILES; do
272
204
fi
273
205
done
274
206
275
- # format string checks
276
- if [[ " $OSTYPE " != darwin* ]]; then
277
- # Format string checks
278
- if [ ! -f fmtscan ]; then
279
- make fmtscan
280
- if [ ! -f fmtscan ]; then
281
- throw " Fail to build 'fmtscan' tool"
282
- fi
283
- fi
284
- if [ -n " $C_FILES " ]; then
285
- echo " Running fmtscan..."
286
- ./fmtscan
287
- if [ $? -ne 0 ]; then
288
- throw " Check format strings for spelling"
289
- fi
290
- fi
291
- fi
292
-
293
207
# static analysis
294
- if [ -n " $C_FILES " ]; then
295
- echo " Running static analysis..."
296
- $CPPCHECK $CPPCHECK_OPTS $C_FILES > /dev/null
297
- if [ $? -ne 0 ]; then
298
- RETURN=1
299
- echo " " >&2
300
- echo " Fail to pass static analysis." >&2
301
- echo
302
- fi
208
+ echo " Running static analysis..."
209
+ $CPPCHECK $CPPCHECK_OPTS > /dev/null
210
+ if [ $? -ne 0 ]; then
211
+ RETURN=1
212
+ echo " " >&2
213
+ echo " Fail to pass static analysis." >&2
214
+ echo
303
215
fi
304
216
305
217
# non-ASCII filenames are not allowed.
306
218
# Cross platform projects tend to avoid non-ASCII filenames; prevent
307
219
# them from being added to the repository.
308
220
if test $( git diff --cached --name-only --diff-filter=A -z $against |
309
- LC_ALL=C tr -d ' [ -~]\0' | wc -c) ! = 0
221
+ LC_ALL=C tr -d ' [ -~]\0' | wc -c) ! = 0
310
222
then
311
223
cat << \EOF
312
224
ERROR: Attempt to add a non-ASCII file name.
0 commit comments