From 3f568c6d6fee36fad239ab20b98fee0b93c31b3c Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Fri, 8 Sep 2023 09:43:32 +0200
Subject: [PATCH] Add script to run clang-tidy on a source directory

The script allows to run clang-tidy on the complete project by passing the path
to the CbmRoot source directory or only a subdirectory by passing the path to
the subdirectory.
Some of the compilation units should not be tested by clang-tidy.
Exclude checking the dictionaries G__*.cxx since they generated by root-cling.
Exclude all targets from the external directory. This isn't our code and must
not be checked by us.
---
 scripts/apply-tidy.sh | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100755 scripts/apply-tidy.sh

diff --git a/scripts/apply-tidy.sh b/scripts/apply-tidy.sh
new file mode 100755
index 0000000000..292153dc31
--- /dev/null
+++ b/scripts/apply-tidy.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+# SPDX-License-Identifier: GPL-3.0-only
+# First commited by Florian Uhlig
+
+# Extract files with an existing compilation unit from the compile command database
+# which are in the passed directory or in case only one file is passed check if the
+# file is in the compilation database
+# For all found files run clang-tidy to fix the problems found. Exclude files from
+# the external directory and root-cling generated dictionaries. 
+
+source_directory=$1
+build_directory=$2
+
+CLANG_TIDY_BIN=${FAIRROOT_CLANG_TIDY_BIN:-clang-tidy}
+
+FILES=$(grep '"file"' $build_directory/compile_commands.json | grep "$source_directory" | cut -d: -f2 | cut -d\" -f2)
+
+for file in $FILES; do
+  if [[ $file =~ "/external/" ]]; then
+    continue
+  fi
+  if [[ $file =~ "G__" ]]; then
+    continue
+  fi
+  echo "Run clang-tidy on $file"
+  $CLANG_TIDY_BIN --fix -p $build_directory  $file
+done;
-- 
GitLab