@@ -15,75 +15,75 @@ PY_FORMAT_EXIT=0
1515# Use git ls-files to exclude submodules and untracked files
1616C_SOURCES=()
1717while IFS= read -r file; do
18- [ -n " $file " ] && C_SOURCES+=(" $file " )
18+ [ -n " $file " ] && C_SOURCES+=(" $file " )
1919done < <( git ls-files -- ' include/*.h' ' src/*.c' ' src/*.h' ' ports/*.c' ' ports/*.h' ' tests/*.c' ' tests/*.h' )
2020
2121if [ ${# C_SOURCES[@]} -gt 0 ]; then
22- if command -v clang-format-20 > /dev/null 2>&1 ; then
23- echo " Checking C files with clang-format-20..."
24- clang-format-20 -n --Werror " ${C_SOURCES[@]} "
25- C_FORMAT_EXIT=$?
26- elif command -v clang-format > /dev/null 2>&1 ; then
27- echo " Checking C files with clang-format..."
28- clang-format -n --Werror " ${C_SOURCES[@]} "
29- C_FORMAT_EXIT=$?
30- else
31- if [ " $REQUIRE_TOOLS " = " true" ]; then
32- echo " ERROR: clang-format not found (required in CI)" >&2
33- C_FORMAT_EXIT=1
34- else
35- echo " Skipping C format check: clang-format not found" >&2
36- fi
37- fi
22+ if command -v clang-format-20 > /dev/null 2>&1 ; then
23+ echo " Checking C files with clang-format-20..."
24+ clang-format-20 -n --Werror " ${C_SOURCES[@]} "
25+ C_FORMAT_EXIT=$?
26+ elif command -v clang-format > /dev/null 2>&1 ; then
27+ echo " Checking C files with clang-format..."
28+ clang-format -n --Werror " ${C_SOURCES[@]} "
29+ C_FORMAT_EXIT=$?
30+ else
31+ if [ " $REQUIRE_TOOLS " = " true" ]; then
32+ echo " ERROR: clang-format not found (required in CI)" >&2
33+ C_FORMAT_EXIT=1
34+ else
35+ echo " Skipping C format check: clang-format not found" >&2
36+ fi
37+ fi
3838fi
3939
4040SH_SOURCES=()
4141while IFS= read -r file; do
42- [ -n " $file " ] && SH_SOURCES+=(" $file " )
42+ [ -n " $file " ] && SH_SOURCES+=(" $file " )
4343done < <( git ls-files -- ' *.sh' ' .ci/*.sh' ' scripts/*.sh' )
4444
4545if [ ${# SH_SOURCES[@]} -gt 0 ]; then
46- if command -v shfmt > /dev/null 2>&1 ; then
47- echo " Checking shell scripts..."
48- MISMATCHED_SH=$( shfmt -l " ${SH_SOURCES[@]} " )
49- if [ -n " $MISMATCHED_SH " ]; then
50- echo " The following shell scripts are not formatted correctly:"
51- printf ' %s\n' " $MISMATCHED_SH "
52- shfmt -d " ${SH_SOURCES[@]} "
53- SH_FORMAT_EXIT=1
54- fi
55- else
56- if [ " $REQUIRE_TOOLS " = " true" ]; then
57- echo " ERROR: shfmt not found (required in CI)" >&2
58- SH_FORMAT_EXIT=1
59- else
60- echo " Skipping shell script format check: shfmt not found" >&2
61- fi
62- fi
46+ if command -v shfmt > /dev/null 2>&1 ; then
47+ echo " Checking shell scripts..."
48+ MISMATCHED_SH=$( shfmt -l " ${SH_SOURCES[@]} " )
49+ if [ -n " $MISMATCHED_SH " ]; then
50+ echo " The following shell scripts are not formatted correctly:"
51+ printf ' %s\n' " $MISMATCHED_SH "
52+ shfmt -d " ${SH_SOURCES[@]} "
53+ SH_FORMAT_EXIT=1
54+ fi
55+ else
56+ if [ " $REQUIRE_TOOLS " = " true" ]; then
57+ echo " ERROR: shfmt not found (required in CI)" >&2
58+ SH_FORMAT_EXIT=1
59+ else
60+ echo " Skipping shell script format check: shfmt not found" >&2
61+ fi
62+ fi
6363fi
6464
6565PY_SOURCES=()
6666while IFS= read -r file; do
67- [ -n " $file " ] && PY_SOURCES+=(" $file " )
67+ [ -n " $file " ] && PY_SOURCES+=(" $file " )
6868done < <( git ls-files -- ' scripts/*.py' )
6969
7070if [ ${# PY_SOURCES[@]} -gt 0 ]; then
71- if command -v black > /dev/null 2>&1 ; then
72- echo " Checking Python files..."
73- black --check --diff " ${PY_SOURCES[@]} "
74- PY_FORMAT_EXIT=$?
75- else
76- if [ " $REQUIRE_TOOLS " = " true" ]; then
77- echo " ERROR: black not found (required in CI)" >&2
78- PY_FORMAT_EXIT=1
79- else
80- echo " Skipping Python format check: black not found" >&2
81- fi
82- fi
71+ if command -v black > /dev/null 2>&1 ; then
72+ echo " Checking Python files..."
73+ black --check --diff " ${PY_SOURCES[@]} "
74+ PY_FORMAT_EXIT=$?
75+ else
76+ if [ " $REQUIRE_TOOLS " = " true" ]; then
77+ echo " ERROR: black not found (required in CI)" >&2
78+ PY_FORMAT_EXIT=1
79+ else
80+ echo " Skipping Python format check: black not found" >&2
81+ fi
82+ fi
8383fi
8484
8585# Use logical OR to avoid exit code overflow (codes are mod 256)
8686if [ $C_FORMAT_EXIT -ne 0 ] || [ $SH_FORMAT_EXIT -ne 0 ] || [ $PY_FORMAT_EXIT -ne 0 ]; then
87- exit 1
87+ exit 1
8888fi
8989exit 0
0 commit comments