From a46d61c45ca9682ec728c2cdfbce93e3104c0df4 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 25 Sep 2022 15:12:48 +0200 Subject: [PATCH] Simplify script to check clang-format * Check only files from the git repository * Support paths with spaces * Do check in parallel --- CI/check_clang_format.sh | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/CI/check_clang_format.sh b/CI/check_clang_format.sh index 109849a98a..3acb7a5c72 100755 --- a/CI/check_clang_format.sh +++ b/CI/check_clang_format.sh @@ -1,33 +1,10 @@ -#!/bin/bash +#!/bin/bash -ex + +set -o pipefail CLANG_FORMAT="${CLANG_FORMAT:-clang-format}" -HAS_DIFFS=0 - -check_format_file() { - local item=$1 - "$CLANG_FORMAT" --dry-run -Werror "$item" &>/dev/null - if [[ $? = 1 ]]; then - "${CLANG_FORMAT}" "${item}" | git diff --color=always --no-index "${item}" - - HAS_DIFFS=1 - fi -} - -check_format() { - local path=$1 - find "$path" -type f -name "*" | while read item; - do - if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then - check_format_file "$item" - fi; - done; -} - -check_format "./apps" -check_format "./components" - -if [[ $HAS_DIFFS -eq 1 ]]; then - echo "clang-format differences detected" - exit 1 -fi; - -exit 0 \ No newline at end of file +git ls-files | + grep -v '^extern/' | + grep -P '\.(cpp|hpp|h)$' | + xargs -I '{}' -P $(nproc) bash -ec "\"${CLANG_FORMAT:?}\" --dry-run -Werror \"\${0:?}\" &> /dev/null || \"${CLANG_FORMAT:?}\" \"\${0:?}\" | git diff --color=always --no-index \"\${0:?}\" -" '{}' || + ( echo "clang-format differences detected"; exit -1 )