YREA-SLS/SLS_C/build_system/compilers/clang.py

64 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""
Clang compiler implementation.
"""
from typing import Optional
from .base_gcc import BaseGCCCompiler
import subprocess
class ClangCompiler(BaseGCCCompiler):
"""Clang compiler implementation."""
def __init__(self, executable: str = "clang"):
"""
Initialize Clang compiler.
Args:
executable: Compiler executable name ("clang")
"""
super().__init__("Clang", executable)
def get_version(self) -> Optional[str]:
"""
Get the Clang version string.
Returns:
Version string if available, None otherwise
"""
try:
result = subprocess.run(
[self.executable, "--version"],
capture_output=True,
text=True,
check=False
)
if result.returncode == 0 and result.stdout:
# Parse first line of version output
first_line = result.stdout.strip().split('\n')[0]
return first_line
except Exception:
pass
return None
def detect_clang_compiler() -> Optional[ClangCompiler]:
"""
Detect and return an available Clang compiler.
Returns:
ClangCompiler instance if found, None otherwise
"""
from build_system.utils import which
# Try to find Clang
compilers = ["clang", "clang-18", "clang-17", "clang-16", "clang-15"]
for compiler in compilers:
if which(compiler):
return ClangCompiler(compiler)
return None