Skip to content

[run-clang-tidy.py] Add option to ignore source files from compilation database #82416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^

Expand Down