From f79a5d5ec3cc4c5d81f8cb87a1358328013b3134 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 30 Jul 2024 15:40:27 +0200 Subject: [PATCH 1/2] Make sure that clang-tidy can find sio headers --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 26225e67f..f179fb5ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,9 +9,9 @@ repos: hooks: - id: clang-tidy name: clang-tidy - entry: clang-tidy -warnings-as-errors='*,-clang-diagnostic-deprecated-declarations' -p compile_commands.json + entry: clang-tidy -warnings-as-errors='*,-clang-diagnostic-deprecated-declarations' -p compile_commands.json --extra-arg=-I$(realpath $(dirname $(which sio-dump))/../include) types: [c++] - exclude: (tests/(datamodel|src|extra_code)/.*(h|cc)|podioVersion.in.h|SIOFrame.*h) + exclude: (tests/(datamodel|src|extra_code)/.*(h|cc)|podioVersion.in.h) language: system - id: clang-format name: clang-format From 4723560029f5823a4255177fb6fd96d1bdb67d6d Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 31 Jul 2024 11:14:55 +0200 Subject: [PATCH 2/2] Put clang-tidy into thin wrapper script Otherwise we are not able to use the shell to dynamically get things --- .github/scripts/clang-tidy-hook | 19 +++++++++++++++++++ .pre-commit-config.yaml | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/clang-tidy-hook diff --git a/.github/scripts/clang-tidy-hook b/.github/scripts/clang-tidy-hook new file mode 100755 index 000000000..f58b8d2d2 --- /dev/null +++ b/.github/scripts/clang-tidy-hook @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# Thin wrapper around clang-tidy that we need to make sure that we can pass the +# include directories for SIO to clang-tidy as it seems that it's not always +# present in the compile database that is generated by CMake. This is mainly +# necessary for template heavy header only parts that get included and for which +# clang-tidy runs into a clang-diagnostic-error because it cannot find an SIO +# header. We cannot do this in the pre-commit configuration because we cannot do +# any shell expansion there. + +# Safe guard against environments where we do not have SIO available. The +# clang-tidy checks will probably fail, but at least we are not getting problems +# with passing garbage as extra arguments +EXTRA_ARGS="" +if which sio-dump > /dev/null 2>&1; then + EXTRA_ARGS="--extra-arg=-I$(realpath $(dirname $(which sio-dump))/../include)" +fi + +clang-tidy -warnings-as-errors='*,-clang-diagnostic-deprecated-declarations' -p compile_commands.json $EXTRA_ARGS ${@} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f179fb5ac..04edf3cde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: hooks: - id: clang-tidy name: clang-tidy - entry: clang-tidy -warnings-as-errors='*,-clang-diagnostic-deprecated-declarations' -p compile_commands.json --extra-arg=-I$(realpath $(dirname $(which sio-dump))/../include) + entry: .github/scripts/clang-tidy-hook types: [c++] exclude: (tests/(datamodel|src|extra_code)/.*(h|cc)|podioVersion.in.h) language: system