Skip to content

Commit 49af650

Browse files
authored
[run-clang-tidy] Accept export directory if PyYAML is not installed (#69700)
If PyYAML is not installed, the `-export-fixes` can be used to specify a directory (not a file). Mentioning @PiotrZSL @dyung Follows #69453
1 parent 40ba0ca commit 49af650

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ def main():
187187
"parameter is a directory, the fixes of each compilation unit are "
188188
"stored in individual yaml files in the directory.",
189189
)
190+
else:
191+
parser.add_argument(
192+
"-export-fixes",
193+
metavar="DIRECTORY",
194+
dest="export_fixes",
195+
help="A directory to store suggested fixes in, which can be applied "
196+
"with clang-apply-replacements. The fixes of each compilation unit are "
197+
"stored in individual yaml files in the directory.",
198+
)
190199
parser.add_argument(
191200
"-extra-arg",
192201
dest="extra_arg",
@@ -270,7 +279,12 @@ def main():
270279
):
271280
os.makedirs(args.export_fixes)
272281

273-
if not os.path.isdir(args.export_fixes) and yaml:
282+
if not os.path.isdir(args.export_fixes):
283+
if not yaml:
284+
raise RuntimeError(
285+
"Cannot combine fixes in one yaml file. Either install PyYAML or specify an output directory."
286+
)
287+
274288
combine_fixes = True
275289

276290
if os.path.isdir(args.export_fixes):

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ def main():
315315
"parameter is a directory, the fixes of each compilation unit are "
316316
"stored in individual yaml files in the directory.",
317317
)
318+
else:
319+
parser.add_argument(
320+
"-export-fixes",
321+
metavar="directory",
322+
dest="export_fixes",
323+
help="A directory to store suggested fixes in, which can be applied "
324+
"with clang-apply-replacements. The fixes of each compilation unit are "
325+
"stored in individual yaml files in the directory.",
326+
)
318327
parser.add_argument(
319328
"-j",
320329
type=int,
@@ -401,7 +410,12 @@ def main():
401410
):
402411
os.makedirs(args.export_fixes)
403412

404-
if not os.path.isdir(args.export_fixes) and yaml:
413+
if not os.path.isdir(args.export_fixes):
414+
if not yaml:
415+
raise RuntimeError(
416+
"Cannot combine fixes in one yaml file. Either install PyYAML or specify an output directory."
417+
)
418+
405419
combine_fixes = True
406420

407421
if os.path.isdir(args.export_fixes):

0 commit comments

Comments
 (0)