Commit d96f74ae3483b4e7c4cb3112cb5a7a45d358dbf8
1 parent
a3b939ce
Use version-specific clang-format if available
Showing
1 changed file
with
11 additions
and
6 deletions
format-code
| @@ -25,18 +25,23 @@ | @@ -25,18 +25,23 @@ | ||
| 25 | # that refers to this comment. See also .clang-format. | 25 | # that refers to this comment. See also .clang-format. |
| 26 | min_version=18 | 26 | min_version=18 |
| 27 | 27 | ||
| 28 | -clang_version=$(clang-format --version | \ | ||
| 29 | - awk '{for (i=1; i<=NF; i++) if ($i == "version") {print int($(i+1)); exit}}') | ||
| 30 | -if [ "$clang_version" -lt "$min_version" ]; then | ||
| 31 | - echo "clang-format version >= $min_version is required" | ||
| 32 | - exit 2 | 28 | +clang_format=clang-format |
| 29 | +if clang-format-$min_version --version >/dev/null 2>&1; then | ||
| 30 | + clang_format=clang-format-$min_version | ||
| 31 | +else | ||
| 32 | + clang_version=$(clang-format --version | \ | ||
| 33 | + awk '{for (i=1; i<=NF; i++) if ($i == "version") {print int($(i+1)); exit}}') | ||
| 34 | + if [ "$clang_version" -lt "$min_version" ]; then | ||
| 35 | + echo "clang-format version >= $min_version is required" | ||
| 36 | + exit 2 | ||
| 37 | + fi | ||
| 33 | fi | 38 | fi |
| 34 | 39 | ||
| 35 | cd $(dirname $0) | 40 | cd $(dirname $0) |
| 36 | for i in $(find . -name 'build*' -prune -o '(' \ | 41 | for i in $(find . -name 'build*' -prune -o '(' \ |
| 37 | -name '*.hh' -o -name '*.h' -o -name '*.cc' -o -name '*.c' \ | 42 | -name '*.hh' -o -name '*.h' -o -name '*.cc' -o -name '*.c' \ |
| 38 | ')' -print); do | 43 | ')' -print); do |
| 39 | - if clang-format < $i >| $i.new; then | 44 | + if $clang_format < $i >| $i.new; then |
| 40 | if diff -q $i $i.new >/dev/null 2>/dev/null; then | 45 | if diff -q $i $i.new >/dev/null 2>/dev/null; then |
| 41 | echo "okay: $i" | 46 | echo "okay: $i" |
| 42 | rm $i.new | 47 | rm $i.new |