[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-18 Thread via cfe-commits

https://github.com/edunad created 
https://github.com/llvm/llvm-project/pull/89302

Similar to https://github.com/llvm/llvm-project/pull/82416, but it allows you 
to filter full directories without the need of a complex regex in 
`-source-filter`

For example:
```
python run-clang-tidy.py -fix -p \"build\" -j 12 -directory-filter build 
-directory-filter bin -directory-filter tests
```

To filter out `bin`, `build` and `tests` folders

>From 62e47d8b629bd7fff4e7dc9c4ec21bedab142832 Mon Sep 17 00:00:00 2001
From: FailCake 
Date: Thu, 18 Apr 2024 22:24:56 +0200
Subject: [PATCH] Adds -directory-filter option to run-clang-tidy.py

---
 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

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 1bd4a5b283091c..4ef9b0a8ebf5e2 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -307,6 +307,14 @@ def main():
 "source files from compilation database to output "
 "diagnostics from.",
 )
+parser.add_argument(
+"-directory-filter",
+dest="directory_filter",
+action="append",
+default=[],
+help="List of directories matching the names of the "
+"compilation database to filter.",
+)
 parser.add_argument(
 "-line-filter",
 default=None,
@@ -488,6 +496,7 @@ def main():
 
 # Build up a big regexy filter from all command line arguments.
 file_name_re = re.compile("|".join(args.files))
+directory_filters_re = re.compile("|".join(args.directory_filters))
 
 return_code = 0
 try:
@@ -514,7 +523,7 @@ def main():
 
 # Fill the queue with files.
 for name in files:
-if file_name_re.search(name):
+if file_name_re.search(name) and not 
directory_filters_re.search(name):
 task_queue.put(name)
 
 # Wait for all threads to be done.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-18 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

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
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: FailCake (edunad)


Changes

Similar to https://github.com/llvm/llvm-project/pull/82416, but it allows you 
to filter full directories without the need of a complex regex in 
`-source-filter`

For example:
```
python run-clang-tidy.py -fix -p \"build\" -j 12 -directory-filter build 
-directory-filter bin -directory-filter tests
```

To filter out `bin`, `build` and `tests` folders

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


1 Files Affected:

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


``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 1bd4a5b283091c..4ef9b0a8ebf5e2 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -307,6 +307,14 @@ def main():
 "source files from compilation database to output "
 "diagnostics from.",
 )
+parser.add_argument(
+"-directory-filter",
+dest="directory_filter",
+action="append",
+default=[],
+help="List of directories matching the names of the "
+"compilation database to filter.",
+)
 parser.add_argument(
 "-line-filter",
 default=None,
@@ -488,6 +496,7 @@ def main():
 
 # Build up a big regexy filter from all command line arguments.
 file_name_re = re.compile("|".join(args.files))
+directory_filters_re = re.compile("|".join(args.directory_filters))
 
 return_code = 0
 try:
@@ -514,7 +523,7 @@ def main():
 
 # Fill the queue with files.
 for name in files:
-if file_name_re.search(name):
+if file_name_re.search(name) and not 
directory_filters_re.search(name):
 task_queue.put(name)
 
 # Wait for all threads to be done.

``




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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-19 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/89302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-19 Thread Piotr Zegar via cfe-commits


@@ -307,6 +307,14 @@ def main():
 "source files from compilation database to output "
 "diagnostics from.",
 )
+parser.add_argument(
+"-directory-filter",
+dest="directory_filter",
+action="append",
+default=[],
+help="List of directories matching the names of the "
+"compilation database to filter.",

PiotrZSL wrote:

filter in, or filter out ?

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-19 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

Personally I do not see use case for it, as source-filter also apply to 
directories, and better would be to just change source-filter to accept list of 
regexes.

Other thing that directory-filter works as "exclude", not "include", and for me 
this could be just --exclude-files or something like that, but still users may 
use negative regexp.

Release notes change missing.

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-19 Thread Piotr Zegar via cfe-commits


@@ -307,6 +307,14 @@ def main():
 "source files from compilation database to output "
 "diagnostics from.",
 )
+parser.add_argument(
+"-directory-filter",
+dest="directory_filter",
+action="append",
+default=[],
+help="List of directories matching the names of the "
+"compilation database to filter.",

PiotrZSL wrote:

use regexp instead of list of directories

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-19 Thread Piotr Zegar via cfe-commits


@@ -514,7 +523,7 @@ def main():
 
 # Fill the queue with files.
 for name in files:
-if file_name_re.search(name):
+if file_name_re.search(name) and not 
directory_filters_re.search(name):

PiotrZSL wrote:

to be honest those lines should be handled like current filtering in line 491

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-19 Thread Piotr Zegar via cfe-commits


@@ -307,6 +307,14 @@ def main():
 "source files from compilation database to output "
 "diagnostics from.",
 )
+parser.add_argument(
+"-directory-filter",

PiotrZSL wrote:

this basically work opposite to -source-filter, specially because it work on 
full path, not just on directory path.
Therefore I could filter out with this an file also, not only directory.

For me this option is just an negative source-filter, and as you can do 
negative regexp in python, i do not see a reason for it.

Specially that for what this option describes there is already this:
```
parser.add_argument(
"files", nargs="*", default=[".*"], help="files to be processed (regex 
on path)"
)
```

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-23 Thread via cfe-commits

edunad wrote:

@nicovank You're right ^^, it's better to just use negative regex, i'll close 
this PR then

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


[clang-tools-extra] [run-clang-tidy.py] Add -directory-filter option to run-clang-tidy.py (PR #89302)

2024-04-23 Thread via cfe-commits

https://github.com/edunad closed https://github.com/llvm/llvm-project/pull/89302
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits