https://github.com/amgebauer created 
https://github.com/llvm/llvm-project/pull/69700

If PyYAML is not installed, the `-export-fixes` can be used to specify a 
directory (not a file).

Follows #69453

>From 947b71ca6498f33332783f2b701ad8d03d63779e Mon Sep 17 00:00:00 2001
From: Amadeus Gebauer <amadeus.geba...@tum.de>
Date: Fri, 20 Oct 2023 11:27:17 +0200
Subject: [PATCH] [run-clang-tidy] Accept export directory if PyYAML is not
 installed

If yaml is not installed, the -export-fixes can be used to specify
a directory (not a file).

Follows !69453
---
 .../clang-tidy/tool/clang-tidy-diff.py           | 16 +++++++++++++++-
 .../clang-tidy/tool/run-clang-tidy.py            | 16 +++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

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 6fb5eedf06d5dff..8817e2914f6e25b 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -187,6 +187,15 @@ def main():
             "parameter is a directory, the fixes of each compilation unit are "
             "stored in individual yaml files in the directory.",
         )
+    else:
+        parser.add_argument(
+            "-export-fixes",
+            metavar="DIRECTORY",
+            dest="export_fixes",
+            help="A directory to store suggested fixes in, which can be 
applied "
+            "with clang-apply-replacements. The fixes of each compilation unit 
are "
+            "stored in individual yaml files in the directory.",
+        )
     parser.add_argument(
         "-extra-arg",
         dest="extra_arg",
@@ -270,7 +279,12 @@ def main():
         ):
             os.makedirs(args.export_fixes)
 
-        if not os.path.isdir(args.export_fixes) and yaml:
+        if not os.path.isdir(args.export_fixes):
+            if not yaml:
+                raise RuntimeError(
+                    "Cannot combine fixes in one yaml file. Either install 
PyYAML or specify an output directory."
+                )
+
             combine_fixes = True
 
         if os.path.isdir(args.export_fixes):
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 aa628aa87800693..179759216196f88 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -315,6 +315,15 @@ def main():
             "parameter is a directory, the fixes of each compilation unit are "
             "stored in individual yaml files in the directory.",
         )
+    else:
+        parser.add_argument(
+            "-export-fixes",
+            metavar="directory",
+            dest="export_fixes",
+            help="A directory to store suggested fixes in, which can be 
applied "
+            "with clang-apply-replacements. The fixes of each compilation unit 
are "
+            "stored in individual yaml files in the directory.",
+        )
     parser.add_argument(
         "-j",
         type=int,
@@ -401,7 +410,12 @@ def main():
         ):
             os.makedirs(args.export_fixes)
 
-        if not os.path.isdir(args.export_fixes) and yaml:
+        if not os.path.isdir(args.export_fixes):
+            if not yaml:
+                raise RuntimeError(
+                    "Cannot combine fixes in one yaml file. Either install 
PyYAML or specify an output directory."
+                )
+
             combine_fixes = True
 
         if os.path.isdir(args.export_fixes):

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

Reply via email to