Skip to content

Commit 8dfc023

Browse files
authored
[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).
1 parent 411c5dd commit 8dfc023

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ def main():
300300
"the main file of each translation unit are always "
301301
"displayed.",
302302
)
303+
parser.add_argument(
304+
"-source-filter",
305+
default=None,
306+
help="Regular expression matching the names of the "
307+
"source files from compilation database to output "
308+
"diagnostics from.",
309+
)
303310
parser.add_argument(
304311
"-line-filter",
305312
default=None,
@@ -462,6 +469,19 @@ def main():
462469
[make_absolute(entry["file"], entry["directory"]) for entry in database]
463470
)
464471

472+
# Filter source files from compilation database.
473+
if args.source_filter:
474+
try:
475+
source_filter_re = re.compile(args.source_filter)
476+
except:
477+
print(
478+
"Error: unable to compile regex from arg -source-filter:",
479+
file=sys.stderr,
480+
)
481+
traceback.print_exc()
482+
sys.exit(1)
483+
files = {f for f in files if source_filter_re.match(f)}
484+
465485
max_task = args.j
466486
if max_task == 0:
467487
max_task = multiprocessing.cpu_count()

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ The improvements are...
9797
Improvements to clang-tidy
9898
--------------------------
9999

100+
- Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
101+
to filter source files from the compilation database, via a RegEx. In a
102+
similar fashion to what `-header-filter` does for header files.
103+
100104
New checks
101105
^^^^^^^^^^
102106

0 commit comments

Comments
 (0)