Skip to content

Commit b1b5286

Browse files
[clang-tidy] Check for -ignore-insert-conflict support before using it in apply_fixes in run_clang_tidy.py
1 parent 9251f16 commit b1b5286

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,22 @@ def find_binary(arg: str, name: str, build_path: str) -> str:
195195
raise SystemExit(f"error: failed to find {name} in $PATH or at {built_path}")
196196

197197

198+
def supports_flag(binary: str, flag: str) -> bool:
199+
"""Checks if a given flag is supported by the binary by running --help."""
200+
try:
201+
result = subprocess.run(
202+
[binary, "--help"], capture_output=True, text=True, check=True
203+
)
204+
return flag in result.stdout
205+
except (subprocess.CalledProcessError, FileNotFoundError):
206+
return False # Binary not found or error running it
207+
198208
def apply_fixes(
199209
args: argparse.Namespace, clang_apply_replacements_binary: str, tmpdir: str
200210
) -> None:
201211
"""Calls clang-apply-replacements on a given directory."""
202212
invocation = [clang_apply_replacements_binary]
203-
204-
if args.ignore_insert_conflict:
213+
if supports_flag(clang_apply_replacements_binary, "-ignore-insert-conflict"):
205214
invocation.append("-ignore-insert-conflict")
206215
if args.format:
207216
invocation.append("-format")
@@ -448,12 +457,6 @@ async def main() -> None:
448457
action="store_true",
449458
help="Allow empty enabled checks.",
450459
)
451-
parser.add_argument(
452-
"-ignore-insert-conflict",
453-
action="store_true",
454-
default=True,
455-
help="Ignore insert conflict when applying fixes.",
456-
)
457460
args = parser.parse_args()
458461

459462
db_path = "compile_commands.json"

0 commit comments

Comments
 (0)