llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Alexander (duddel)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/82416.diff


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/tool/run-clang-tidy.py (+15) 


``````````diff
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()

``````````

</details>


https://github.com/llvm/llvm-project/pull/82416
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to