-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Alexander (duddel) ChangesI added the option This option allows for handing over a regex, to ignore matching source files from the compilation database (not run Why "ignore" instead of "filter"? Full diff: https://github.com/llvm/llvm-project/pull/82416.diff 1 Files Affected:
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()
|
|
✅ With the latest revision this PR passed the Python code formatter. |
Why can't we make "filter" use a full regex that supports negative expressions instead? |
We can. I provide a patch that inverts the logic ( |
@duddel Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
How do you do that? I thought |
I added the option
-source-ignore
-source-filter
to therun-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).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. thethirdparty/
directory.