build: try clang-format-12 in code_style (#2935)

This commit is contained in:
Charles Kerr 2022-04-16 22:23:20 -05:00 committed by GitHub
parent d765b7ee3b
commit 3ec7e1933e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -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