Skip to content

Commit

Permalink
[run-clang-tidy] Accept export directory if PyYAML is not installed (#…
Browse files Browse the repository at this point in the history
…69700)

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

Mentioning @PiotrZSL @dyung 

Follows #69453
  • Loading branch information
amgebauer committed Oct 20, 2023
1 parent 40ba0ca commit 49af650
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 15 additions & 1 deletion clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 49af650

Please sign in to comment.