Fix issues with clang-format version detection.

Recent versions include a suffix in brackets, e.g:

$ clang-format --version
Debian clang-format version 21.1.8 (3+b1)

Require a specific version rather than a minimum one, due to differences
in output between versions.
This commit is contained in:
Martin Ling 2026-04-07 04:34:20 +01:00
parent 1e9991e42c
commit a06232270e

View file

@ -1,12 +1,14 @@
#!/bin/bash
VERSION=`clang-format --version | grep -o '[^ ]*$' | cut -d '.' -f 1`
if [ "$VERSION" -ge "14" ]; then
REQUIRED_VERSION=14
VERSION=`clang-format --version | grep -o 'version [^ ]' | cut -d ' ' -f 2 | cut -d '.' -f 1`
if [ "$VERSION" -eq "$REQUIRED_VERSION" ]; then
CLANG_FORMAT=clang-format
elif clang-format-14 --version > /dev/null; then
CLANG_FORMAT=clang-format-14
elif command -v clang-format-$REQUIRED_VERSION > /dev/null; then
CLANG_FORMAT=clang-format-$REQUIRED_VERSION
else
echo "clang-format version 14 or higher is required."
echo "clang-format version $REQUIRED_VERSION is required."
exit 1
fi