[clang-tools-extra] [run-clang-tidy.py] Add option to ignore source files from compilation database (PR #82416)

Alexander Scholz via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 20 12:42:20 PST 2024


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

>From a3596bf357ef991abcaef04f8811958c0984d9f6 Mon Sep 17 00:00:00 2001
From: duddel <duddel at users.noreply.github.com>
Date: Tue, 20 Feb 2024 21:11:26 +0100
Subject: [PATCH 1/2] 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()

>From 6c8cf48bd8ad36ec0e5740eb105742df3f2b60a6 Mon Sep 17 00:00:00 2001
From: duddel <duddel at users.noreply.github.com>
Date: Tue, 20 Feb 2024 21:42:03 +0100
Subject: [PATCH 2/2] Apply suggested python code formatting

---
 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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 ba4314dfb50aa1..66465ba78289d9 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -473,7 +473,10 @@ def main():
         try:
             source_ignore_re = re.compile(args.source_ignore)
         except:
-            print("Error: unable to compile regex from arg -source-ignore.", file=sys.stderr)
+            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)}
 



More information about the cfe-commits mailing list