[PATCH] D72730: [clang-tools-extra] run-clang-tidy -export-fixes exports only fixes, not all warnings
Alexander Lanin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 14 12:59:34 PST 2020
AlexanderLanin created this revision.
AlexanderLanin added a project: clang-tools-extra.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
AlexanderLanin added a comment.
Important: I'm not a python expert. It works fine as far as I can tell. I would feel better if someone with more than a day python experience would say that it is fine.
The generated file is now small enough to not hinder any post processing.
>> Create a yaml file to store suggested fixes in, which can be applied with clang-apply-replacements.
So it's enough to store the fixes, not all the warnings.
Before this change the resulting file was simply too large as it contained all warnings, least of which had FIX-ITs.
This is trivially achievable with no measureable runtime overhead during run-clang-tidy runs, instead of post processing where even parsing the file once is extremely slow.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72730
Files:
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
Index: clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
===================================================================
--- clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -105,6 +105,16 @@
start.append(f)
return start
+# returns whether passed yaml Diagnostic (see mergekey) element contains FIX-IT
+def isAutoFixable(diag):
+ if diag["DiagnosticMessage"]["Replacements"]: return True
+
+ if "Notes" in diag:
+ for note in diag["Notes"]:
+ if "Replacements" in note and note["Replacements"]:
+ return True
+
+ return False
def merge_replacement_files(tmpdir, mergefile):
"""Merge all replacement files in a directory into a single file"""
@@ -116,7 +126,9 @@
content = yaml.safe_load(open(replacefile, 'r'))
if not content:
continue # Skip empty files.
- merged.extend(content.get(mergekey, []))
+ for d in content.get(mergekey, []):
+ if isAutoFixable(d):
+ merged.append(d)
if merged:
# MainSourceFile: The key is required by the definition inside
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72730.238076.patch
Type: text/x-patch
Size: 1098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200114/9353a3dc/attachment.bin>
More information about the cfe-commits
mailing list