65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
GCC compiler implementation.
|
|
"""
|
|
|
|
from typing import Optional
|
|
from .base_gcc import BaseGCCCompiler
|
|
|
|
|
|
class GCCCompiler(BaseGCCCompiler):
|
|
"""GCC compiler implementation."""
|
|
|
|
def __init__(self, executable: str = "gcc"):
|
|
"""
|
|
Initialize GCC compiler.
|
|
|
|
Args:
|
|
executable: Compiler executable name ("gcc")
|
|
"""
|
|
super().__init__("GCC", executable)
|
|
|
|
def get_version(self) -> Optional[str]:
|
|
"""
|
|
Get the GCC version string.
|
|
|
|
Returns:
|
|
Version string if available, None otherwise
|
|
"""
|
|
import subprocess
|
|
|
|
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_gcc_compiler() -> Optional[GCCCompiler]:
|
|
"""
|
|
Detect and return an available GCC compiler.
|
|
|
|
Returns:
|
|
GCCCompiler instance if found, None otherwise
|
|
"""
|
|
from build_system.utils import which
|
|
|
|
# Try to find GCC
|
|
compilers = ["gcc", "gcc-13", "gcc-12", "gcc-11", "cc"]
|
|
|
|
for compiler in compilers:
|
|
if which(compiler):
|
|
return GCCCompiler(compiler)
|
|
|
|
return None
|