https://github.com/duddel created 
https://github.com/llvm/llvm-project/pull/82416

I added the option `-source-ignore` to the `run-clang-tidy.py` script in the 
clang-tools-extra.

This option allows for handing over a regex, to ignore matching source files 
from the compilation database (not run `clang-tidy` on them).

**Why "ignore" instead of "filter"?**
I found it more useful to actively filter out (ignore) source files, rather 
than the inverse logic. One usually knows where the source files reside and can 
now easily ignore e.g. the `thirdparty/` directory.

>From a3596bf357ef991abcaef04f8811958c0984d9f6 Mon Sep 17 00:00:00 2001
From: duddel <dud...@users.noreply.github.com>
Date: Tue, 20 Feb 2024 21:11:26 +0100
Subject: [PATCH] add -source-ignore option to run-clang-tidy.py

---
 .../clang-tidy/tool/run-clang-tidy.py             | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 70f8cbcdcb2f11..ba4314dfb50aa1 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -300,6 +300,12 @@ def main():
         "the main file of each translation unit are always "
         "displayed.",
     )
+    parser.add_argument(
+        "-source-ignore",
+        default=None,
+        help="Regular expression matching the names of the "
+        "source files from compilation database to ignore.",
+    )
     parser.add_argument(
         "-line-filter",
         default=None,
@@ -462,6 +468,15 @@ def main():
         [make_absolute(entry["file"], entry["directory"]) for entry in 
database]
     )
 
+    # Remove source file to be ignored from database.
+    if args.source_ignore:
+        try:
+            source_ignore_re = re.compile(args.source_ignore)
+        except:
+            print("Error: unable to compile regex from arg -source-ignore.", 
file=sys.stderr)
+            sys.exit(1)
+        files = {f for f in files if not source_ignore_re.match(f)}
+
     max_task = args.j
     if max_task == 0:
         max_task = multiprocessing.cpu_count()

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to