From 3ec7e1933e6779e6039aca6d3aa201216b72a9e5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 16 Apr 2022 22:23:20 -0500 Subject: [PATCH] build: try clang-format-12 in code_style (#2935) --- code_style.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/code_style.sh b/code_style.sh index f5d77b930..5dd18fa6a 100755 --- a/code_style.sh +++ b/code_style.sh @@ -43,9 +43,27 @@ find_cfiles() { find . \( $(get_find_path_args "${cfile_includes[@]}") \) ! \( $(get_find_path_args "${cfile_excludes[@]}") \) "$@" } +# We're targeting clang-format version 12 and other versions give slightly +# different results, so prefer `clang-format-12` if it's installed. +clang_format_exe_names=( + 'clang-format-12' + 'clang-format' +) +for name in ${clang_format_exe_names[@]}; do + clang_format_exe=$(command -v "${name}") + if [ "$?" -eq 0 ]; then + clang_format_exe="${name}" + break + fi +done +if [ -z "${clang_format_exe}" ]; then + echo "error: clang-format not found"; + exit 1; +fi + # format C/C++ clang_format_args="$([ -n "$fix" ] && echo '-i' || echo '--dry-run --Werror')" -if ! find_cfiles -exec clang-format $clang_format_args '{}' '+'; then +if ! find_cfiles -exec "${clang_format_exe}" $clang_format_args '{}' '+'; then [ -n "$fix" ] || echo 'C/C++ code needs formatting' exitcode=1 fi