[clang-tools-extra] [run-clang-tidy] Add option -export-directory (PR #69453)
Amadeus Gebauer via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 18 05:05:46 PDT 2023
https://github.com/amgebauer created https://github.com/llvm/llvm-project/pull/69453
Adding an additional parameter to run_clang_tidy.py to accept a directory where the clang-tidy fixes are saved to. This directory can then be used to run `clang-apply-replacements`.
>From fd908df80b14933c849e498769cff6152276c2c3 Mon Sep 17 00:00:00 2001
From: Amadeus Gebauer <amadeus.gebauer at tum.de>
Date: Wed, 18 Oct 2023 14:02:44 +0200
Subject: [PATCH] [run-clang-tidy] Add option -export-directory
---
.../clang-tidy/tool/run-clang-tidy.py | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
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 312d9241cfa57c5..b8d482809e293a5 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -372,6 +372,11 @@ def main():
default=None,
help="Upgrades warnings to errors. Same format as " "'-checks'",
)
+ parser.add_argument(
+ "-export-directory",
+ default=None,
+ help="Path to the export directory. Within this directory, a file with the fixes will be created for every compilation unit.",
+ )
args = parser.parse_args()
db_path = "compile_commands.json"
@@ -384,15 +389,17 @@ def main():
clang_tidy_binary = find_binary(args.clang_tidy_binary, "clang-tidy", build_path)
- tmpdir = None
if args.fix:
clang_apply_replacements_binary = find_binary(
args.clang_apply_replacements_binary, "clang-apply-replacements", build_path
)
- if args.fix or (yaml and args.export_fixes):
+ tmpdir = args.export_directory
+ if tmpdir is None and (args.fix or (yaml and args.export_fixes)):
tmpdir = tempfile.mkdtemp()
+ delete_temporary_directory = args.export_directory is None and tmpdir is not None
+
try:
invocation = get_tidy_invocation(
"",
@@ -474,7 +481,7 @@ def main():
# This is a sad hack. Unfortunately subprocess goes
# bonkers with ctrl-c and we start forking merrily.
print("\nCtrl-C detected, goodbye.")
- if tmpdir:
+ if tmpdir and delete_temporary_directory:
shutil.rmtree(tmpdir)
os.kill(0, 9)
@@ -496,7 +503,7 @@ def main():
traceback.print_exc()
return_code = 1
- if tmpdir:
+ if tmpdir and delete_temporary_directory:
shutil.rmtree(tmpdir)
sys.exit(return_code)
More information about the cfe-commits
mailing list