-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-tidy] Add an option to exclude files not present in the compile database #120348
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 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 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. 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: zotnhucucbot (wonbinbk) ChangesA change list may include files that are not part of the compile Full diff: https://github.com/llvm/llvm-project/pull/120348.diff 1 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 62cb4297c50f75..f1560ef892a60c 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -35,6 +35,7 @@
import tempfile
import threading
import traceback
+from pathlib import Path
try:
import yaml
@@ -124,6 +125,19 @@ def merge_replacement_files(tmpdir, mergefile):
open(mergefile, "w").close()
+def get_compiling_file_list(compiledb : Path) -> list[Path]:
+ """ Read a compile_commands.json database and return a list of file paths """
+ file_list = []
+ with open(compiledb) as db_file:
+ db_json = json.load(db_file)
+ for entry in db_json:
+ if "file" not in entry:
+ continue
+ if entry["file"] not in file_list:
+ file_list.append(Path(entry["file"]))
+ return file_list
+
+
def main():
parser = argparse.ArgumentParser(
description="Run clang-tidy against changed files, and "
@@ -234,6 +248,13 @@ def main():
action="store_true",
help="Allow empty enabled checks.",
)
+ parser.add_argument(
+ "-only-check-in-db",
+ dest="skip_non_compiling",
+ default=False,
+ action="store_true",
+ help="Only check files in compile database",
+ )
clang_tidy_args = []
argv = sys.argv[1:]
@@ -243,11 +264,17 @@ def main():
args = parser.parse_args(argv)
+ # Read compile_commands.json database to extract a compiling file list
+ current_dir = Path.cwd()
+ compile_commands_json = (current_dir / args.build_path) if args.build_path else current_dir
+ compile_commands_json = (compile_commands_json / "compile_commands.json")
+ compiling_files = get_compiling_file_list(compile_commands_json)
+
# Extract changed lines for each file.
filename = None
lines_by_file = {}
for line in sys.stdin:
- match = re.search('^\\+\\+\\+\\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
+ match = re.search(r'^\+\+\+\ "?(.*?/){%s}([^ \t\n"]*)' % args.p, line)
if match:
filename = match.group(2)
if filename is None:
@@ -260,6 +287,10 @@ def main():
if not re.match("^%s$" % args.iregex, filename, re.IGNORECASE):
continue
+ # Skip any files not in the compiling list
+ if args.skip_non_compiling and (current_dir / filename) not in compiling_files:
+ continue
+
match = re.search(r"^@@.*\+(\d+)(,(\d+))?", line)
if match:
start_line = int(match.group(1))
|
|
Please mention changes in Release Notes. |
5d912c8 to
b2bac6d
Compare
Thanks. I have updated the Release Notes in |
24d5372 to
d95df90
Compare
|
Rebased. |
HerrCai0907
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
|
feel free to ping me when you want to merge it. |
|
✅ With the latest revision this PR passed the Python code formatter. |
Thank you! I just reformatted the change to make darker happy. Should be all good to merge now if you don't see anything else need to be changed. |
…ation database A change list may include files that are not part of the compilation database, which can cause clang-tidy to fail (e.g., due to missing included headers). To prevent false negatives, we should allow to skip processing these files.
|
Pinging you @HerrCai0907 😃 Please merge this PR if you don't see anything else need to be fixed. |
|
@wonbinbk 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 by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. 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. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
A change list may include files that are not part of the compile
database, which can cause clang-tidy to fail (e.g., due to missing
included headers). To prevent false negatives, we should allow to skip
processing these files.