@@ -4,29 +4,41 @@ set -eo pipefail
44
55echo " 💡 If you get 'spawn Unknown system error -86', try running this script manually:"
66echo " ./scripts/clang-format.sh $1 "
7- echo " "
7+ echo " 💡 It is also recommended to use clang-version v20 or v21. "
88
99# Prioritize finding clang-format executable from brew since the run-s may introduce X86/ARM64 mismatch.
1010CLANG_FORMAT_PATH=" "
1111if [ -f " /opt/homebrew/bin/clang-format" ]; then
1212 CLANG_FORMAT_PATH=" /opt/homebrew/bin/clang-format"
13- elif [ -f " /usr/local/bin/clang-format" ]; then
14- CLANG_FORMAT_PATH=" /usr/local/bin/clang-format"
1513else
16- CLANG_FORMAT_PATH=$( which clang-format 2> /dev/null)
14+ CLANG_FORMAT_PATH=$( which clang-format 2> /dev/null || true )
1715fi
1816
1917if [ -z " $CLANG_FORMAT_PATH " ]; then
2018 echo " ❌ clang-format is not installed or not found in PATH"
2119 echo " "
2220 echo " To install clang-format:"
23- echo " • macOS: brew install clang-format"
24- echo " • Linux: install package clang-format or clang-tools-extra"
25- echo " "
21+ echo " * macOS: brew install clang-format"
22+ echo " * Ubuntu: install package clang-format or clang-tools-extra"
23+ echo " * Arch: pacman -S clang llvm llvm-libs"
24+ exit 1
25+ fi
26+
27+ CLANG_VERSION=" $( " $CLANG_FORMAT_PATH " --version 2> /dev/null) "
28+ CLANG_MAJOR_VERSION=" $( printf ' %s' " $CLANG_VERSION " | grep -oE ' [0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1 | cut -d. -f1) "
29+
30+ echo " clang-format version: $CLANG_VERSION , MAJOR: $CLANG_MAJOR_VERSION "
31+
32+ if ! printf ' %s' " $CLANG_MAJOR_VERSION " | grep -qE ' ^[0-9]+$' ; then
33+ echo " ❌ Could not parse clang-format version from: $CLANG_VERSION "
2634 exit 1
2735fi
2836
29- echo " clang-format version: $( $CLANG_FORMAT_PATH --version) "
37+ REQUIRED_MAJOR=20
38+ if [ " $CLANG_MAJOR_VERSION " -lt " $REQUIRED_MAJOR " ]; then
39+ echo " ❌ clang-format major version $CLANG_MAJOR_VERSION is lower than required $REQUIRED_MAJOR "
40+ exit 1
41+ fi
3042
3143# Check if an argument is provided
3244if [ $# -eq 0 ]; then
0 commit comments