diff --git a/homcc/common/arguments.py b/homcc/common/arguments.py index 62bef42..cfef703 100644 --- a/homcc/common/arguments.py +++ b/homcc/common/arguments.py @@ -307,7 +307,7 @@ def compiler_object(self) -> Compiler: if self.compiler is None: raise UnsupportedCompilerError - return Compiler.from_str(self.compiler_normalized()) + return Compiler.from_arguments(self) @cached_property def output(self) -> Optional[str]: @@ -596,12 +596,13 @@ def __init__(self, compiler_str: str) -> None: self.compiler_str = compiler_str @staticmethod - def from_str(compiler_str: str) -> Compiler: + def from_arguments(arguments: Arguments) -> Compiler: + normalized_compiler = arguments.compiler_normalized() for compiler in Compiler.available_compilers(): - if compiler.is_matching_str(compiler_str): - return compiler(compiler_str) + if compiler.is_matching_str(normalized_compiler): + return compiler(arguments.compiler) # type: ignore[arg-type] - raise UnsupportedCompilerError(f"Compiler '{compiler_str}' is not supported.") + raise UnsupportedCompilerError(f"Compiler '{arguments.compiler}' is not supported.") @staticmethod @abstractmethod @@ -636,7 +637,7 @@ class Clang(Compiler): def is_matching_str(compiler_str: str) -> bool: return "clang" in compiler_str - def supports_target(self, target: str) -> bool: + def supports_target(self, _: str) -> bool: """For clang, we can not really check if it supports the target prior to compiling: '$ clang --print-targets' does not output the same triple format as we get from '$ clang --version' (x86_64 vs. x86-64), so we can not properly check if a target is supported. diff --git a/tests/common/arguments_test.py b/tests/common/arguments_test.py index 57c696e..37dad4c 100644 --- a/tests/common/arguments_test.py +++ b/tests/common/arguments_test.py @@ -256,19 +256,19 @@ def test_compiler_normalized(self): class TestCompiler: """Tests the compiler class of homcc.""" - def test_from_str(self): - assert isinstance(Compiler.from_str("gcc"), Gcc) - assert isinstance(Compiler.from_str("gcc-11"), Gcc) - assert isinstance(Compiler.from_str("g++"), Gcc) - assert isinstance(Compiler.from_str("g++-11"), Gcc) - assert isinstance(Compiler.from_str("/usr/lib/ccache/gcc-11"), Gcc) + def test_from_arguments(self): + assert isinstance(Compiler.from_arguments(Arguments("gcc", [])), Gcc) + assert isinstance(Compiler.from_arguments(Arguments("gcc-11", [])), Gcc) + assert isinstance(Compiler.from_arguments(Arguments("g++", [])), Gcc) + assert isinstance(Compiler.from_arguments(Arguments("g++-11", [])), Gcc) + assert isinstance(Compiler.from_arguments(Arguments("/usr/lib/ccache/gcc-11", [])), Gcc) - assert isinstance(Compiler.from_str("clang++"), Clang) - assert isinstance(Compiler.from_str("clang++-11"), Clang) - assert isinstance(Compiler.from_str("/usr/lib/ccache/clang-14"), Clang) + assert isinstance(Compiler.from_arguments(Arguments("clang++", [])), Clang) + assert isinstance(Compiler.from_arguments(Arguments("clang++-11", [])), Clang) + assert isinstance(Compiler.from_arguments(Arguments("/usr/lib/ccache/clang-14", [])), Clang) with pytest.raises(UnsupportedCompilerError): - Compiler.from_str("unknown++") + Compiler.from_arguments(Arguments("unknown++", [])) class TestGcc: