Skip to content
Closed
15 changes: 13 additions & 2 deletions clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,23 @@ def find_binary(arg: str, name: str, build_path: str) -> str:
raise SystemExit(f"error: failed to find {name} in $PATH or at {built_path}")


def supports_flag(binary: str, flag: str) -> bool:
"""Checks if a given flag is supported by the binary by running --help."""
try:
result = subprocess.run(
[binary, "--help"], capture_output=True, text=True, check=True
)
return flag in result.stdout
except (subprocess.CalledProcessError, FileNotFoundError):
return False # Binary not found or error running it

def apply_fixes(
args: argparse.Namespace, clang_apply_replacements_binary: str, tmpdir: str
) -> None:
"""Calls clang-apply-fixes on a given directory."""
"""Calls clang-apply-replacements on a given directory."""
invocation = [clang_apply_replacements_binary]
invocation.append("-ignore-insert-conflict")
if supports_flag(clang_apply_replacements_binary, "-ignore-insert-conflict"):
invocation.append("-ignore-insert-conflict")
if args.format:
invocation.append("-format")
if args.style:
Expand Down