From afa1b0077d1f231b066c0509f35e15e2d8a021a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Thu, 22 Sep 2022 22:53:39 +0300 Subject: [PATCH] Improve clang-format checking script --- .gitlab-ci.yml | 2 ++ CI/check_clang_format.sh | 26 ++++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a494c6b7c..8bd6c60fd5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -127,6 +127,8 @@ Clang_Format: key: Ubuntu_Clang_Format.ubuntu_22.04.v1 paths: - apt-cache/ + variables: + CLANG_FORMAT: clang-format-14 before_script: - CI/install_debian_deps.sh openmw-clang-format script: diff --git a/CI/check_clang_format.sh b/CI/check_clang_format.sh index a4aafb3837..eedd661ef6 100755 --- a/CI/check_clang_format.sh +++ b/CI/check_clang_format.sh @@ -1,25 +1,23 @@ #!/bin/bash -CLANG_FORMAT="clang-format-14" +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 - for item in $(find $path -type f -name "*"); + for item in $(find "$path" -type f -name "*"); do if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then - echo "Checking code formatting on $item" - $CLANG_FORMAT --dry-run -Werror "$item" - if [[ $? = 1 ]]; then - local tempfile=$(mktemp) - # Avoid having different modes in the diff. - chmod --reference="$item" "$tempfile" - # Generate diff - $CLANG_FORMAT "$item" > "$tempfile" - git diff --color=always --no-index $item $tempfile - rm -f "$tempfile" - HAS_DIFFS=1 - fi + check_format_file "$item" & fi; done; }