Author: Alexander Scholz Date: 2024-02-25T17:42:57+01:00 New Revision: 8dfc023e80c35aded33b3e5e4739d3a487b95a7a
URL: https://github.com/llvm/llvm-project/commit/8dfc023e80c35aded33b3e5e4739d3a487b95a7a DIFF: https://github.com/llvm/llvm-project/commit/8dfc023e80c35aded33b3e5e4739d3a487b95a7a.diff LOG: [run-clang-tidy.py] Add option to ignore source files from compilation database (#82416) I added the option -source-filter to the `run-clang-tidy.py` script in the clang-tools-extra. This option allows for handing over a regex, to filter out source files from the compilation database (not run `clang-tidy` on them). Added: Modified: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py clang-tools-extra/docs/ReleaseNotes.rst Removed: ################################################################################ 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..1bd4a5b283091c 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,13 @@ def main(): "the main file of each translation unit are always " "displayed.", ) + parser.add_argument( + "-source-filter", + default=None, + help="Regular expression matching the names of the " + "source files from compilation database to output " + "diagnostics from.", + ) parser.add_argument( "-line-filter", default=None, @@ -462,6 +469,19 @@ def main(): [make_absolute(entry["file"], entry["directory"]) for entry in database] ) + # Filter source files from compilation database. + if args.source_filter: + try: + source_filter_re = re.compile(args.source_filter) + except: + print( + "Error: unable to compile regex from arg -source-filter:", + file=sys.stderr, + ) + traceback.print_exc() + sys.exit(1) + files = {f for f in files if source_filter_re.match(f)} + max_task = args.j if max_task == 0: max_task = multiprocessing.cpu_count() diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index a0b9fcfe0d7774..6fd01ed9d471c5 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -97,6 +97,10 @@ The improvements are... Improvements to clang-tidy -------------------------- +- Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter` + to filter source files from the compilation database, via a RegEx. In a + similar fashion to what `-header-filter` does for header files. + New checks ^^^^^^^^^^ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits