Skip to content

[run-clang-tidy] Accept export directory if PyYAML is not installed #69700

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

amgebauer
Copy link
Contributor

@amgebauer amgebauer commented Oct 20, 2023

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

Mentioning @PiotrZSL @dyung

Follows #69453

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

Follows !69453
@llvmbot
Copy link
Member

llvmbot commented Oct 20, 2023

@llvm/pr-subscribers-clang-tidy

Author: Amadeus Gebauer (amgebauer)

Changes

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

Follows #69453


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

2 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py (+15-1)
  • (modified) clang-tools-extra/clang-tidy/tool/run-clang-tidy.py (+15-1)
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):

@amgebauer
Copy link
Contributor Author

Is there any way to trigger the failing tests within this PR?

Copy link
Member

@PiotrZSL PiotrZSL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PiotrZSL
Copy link
Member

Is there any way to trigger the failing tests within this PR?

No, in worst case we can revert faulty change.

@PiotrZSL
Copy link
Member

Lets push this, if it wont help then we can revert oryginal change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants