From 771d11a14816f799cdc97de7b215905415e3b9e1 Mon Sep 17 00:00:00 2001 From: Bartosz Podrygajlo Date: Fri, 6 Sep 2024 08:42:07 +0200 Subject: [PATCH] dockerized clang-format error detection tool --- doc/clang-format.md | 4 +++ tools/formatting/README.md | 26 +++++++++++++++++++ .../formatting/detect_clang_format_errors.sh | 5 ++++ tools/formatting/docker-compose.yaml | 13 ++++++++++ 4 files changed, 48 insertions(+) create mode 100644 tools/formatting/README.md create mode 100755 tools/formatting/detect_clang_format_errors.sh create mode 100644 tools/formatting/docker-compose.yaml diff --git a/doc/clang-format.md b/doc/clang-format.md index fa751b303d..5e2f14c0b6 100644 --- a/doc/clang-format.md +++ b/doc/clang-format.md @@ -64,3 +64,7 @@ When this is done, you are set up. How to use: 6) Commit. It won't work if code is not properly formatted due to the pre-commit hook. Force committing with `git commit --no-verify` + +# Checking errors introduced by a branch + +Here is the script that can be used to detect any clang-format errors introduced by a branch [here](../tools/formatting/README.md) diff --git a/tools/formatting/README.md b/tools/formatting/README.md new file mode 100644 index 0000000000..fe01ed8002 --- /dev/null +++ b/tools/formatting/README.md @@ -0,0 +1,26 @@ +# Overview + +Dockerized tool to list clang-format errors introduced in a branch. + +# Usage + +Checkout the branch you want to compare. This is necessary because if there are files added by the branch +they need to be present for clang-format to analyze them. + +Then: + +``` +./tools/formatting/detect_clang_format_errors.sh +``` + +Or + +``` +docker compose up +``` + +Or (to avoid docker related lines in stdout) + +``` +docker compose run clang-formatter | tee output +``` diff --git a/tools/formatting/detect_clang_format_errors.sh b/tools/formatting/detect_clang_format_errors.sh new file mode 100755 index 0000000000..e8d0c89787 --- /dev/null +++ b/tools/formatting/detect_clang_format_errors.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -eo pipefail + +BASE_COMMIT=$(git merge-base HEAD origin/develop) +git diff -U0 --no-color $BASE_COMMIT...HEAD | clang-format-diff -p1 diff --git a/tools/formatting/docker-compose.yaml b/tools/formatting/docker-compose.yaml new file mode 100644 index 0000000000..d2fa77de72 --- /dev/null +++ b/tools/formatting/docker-compose.yaml @@ -0,0 +1,13 @@ +services: + clang-formatter: + image: clang-formatter + build: + dockerfile_inline: | + FROM ubuntu:22.04 + RUN DEBIAN_FRONTEND=noninteractive apt update && apt install -y git clang-format + volumes: + - ../../:/code/ + command: + bash -c "git config --global --add safe.directory /code && cd /code/ && \ + git config --global clangFormat.style file && \ + ./tools/formatting/detect_clang_format_errors.sh"