ci: Validate clang-format
authorColin Walters <walters@verbum.org>
Mon, 1 May 2023 18:24:23 +0000 (14:24 -0400)
committerColin Walters <walters@verbum.org>
Tue, 2 May 2023 14:39:04 +0000 (10:39 -0400)
ci/codestyle.sh

index 850661e576c7464fb0f1b7b7f2a5cb06d257c8de..1db6c1f85562116cc3508d7a1dc93e4e86151199 100755 (executable)
@@ -15,12 +15,23 @@ done
 echo "ok"
 fi
 
-# Will uncomment this once we reformat
-#if command -v clang-format; then
-#    echo -n "checking clang-format... "
-#    git ls-files '**.c' '**.cxx' '**.h' '**.hpp' | xargs clang-format --Werror --dry-run
-#    echo "ok"
-#fi
+if command -v clang-format; then
+    clang_ver=$(clang-format --version)
+    clang_min_ver=15
+    version_re=" version ([0-9]+)."
+    if [[ $clang_ver =~ $version_re ]]; then
+        if test "${BASH_REMATCH[1]}" -ge "${clang_min_ver}"; then
+            echo -n "checking clang-format... "
+            git ls-files '**.c' '**.cxx' '**.h' '**.hpp' | xargs clang-format --Werror --dry-run
+            echo "ok"
+        else
+            echo "notice: clang-format ${clang_ver}" is too old
+        fi
+    else
+        echo "failed to parse clang-format version ${clang_ver}" 1>&2
+        exit 1
+    fi
+fi
 
 echo -n 'grep-based static analysis... '
 patterns=(glnx_fd_close)