Skip to content

Commit 294cb29

Browse files
[#88885] Add check-format.sh script
1 parent bd7b3be commit 294cb29

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

check-format.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
CLANG_FORMAT_COMMAND=${1:-clang-format-19}
4+
5+
TLIB_DIR="$(dirname $0)"
6+
7+
TEMP_FILE=$(mktemp)
8+
9+
NON_CONFORMING_FILES=0
10+
for file in $(find $TLIB_DIR -name '*.c' -o -name '*.h'| grep -v softfloat-3); do
11+
echo "Checking $file"
12+
FORMATTING_OUTPUT=$(${CLANG_FORMAT_COMMAND} --style=file --dry-run --Werror --verbose $file 2>${TEMP_FILE})
13+
COMMAND_EXIT_CODE=$?
14+
OUTPUT_ERRORS=$(grep error ${TEMP_FILE} | wc -l)
15+
if [ ${OUTPUT_ERRORS} -ne 0 ] || [ ${COMMAND_EXIT_CODE} -ne 0 ] ; then
16+
if [ ${COMMAND_EXIT_CODE} -ne 0 ]; then
17+
echo "Clang-format exited with code ${COMMAND_EXIT_CODE}!!"
18+
fi
19+
cat ${TEMP_FILE}
20+
((NON_CONFORMING_FILES++))
21+
fi
22+
done
23+
24+
if [ ${NON_CONFORMING_FILES} -ne 0 ]; then
25+
echo "Clang-format found non-conforming files: ${NON_CONFORMING_FILES}" >&2
26+
exit 1
27+
fi

0 commit comments

Comments
 (0)