Skip to content

Commit 295b331

Browse files
authored
Fix compiler normalization issue
1 parent 68927cd commit 295b331

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

homcc/common/arguments.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def compiler_object(self) -> Compiler:
307307
if self.compiler is None:
308308
raise UnsupportedCompilerError
309309

310-
return Compiler.from_str(self.compiler_normalized())
310+
return Compiler.from_arguments(self)
311311

312312
@cached_property
313313
def output(self) -> Optional[str]:
@@ -596,12 +596,13 @@ def __init__(self, compiler_str: str) -> None:
596596
self.compiler_str = compiler_str
597597

598598
@staticmethod
599-
def from_str(compiler_str: str) -> Compiler:
599+
def from_arguments(arguments: Arguments) -> Compiler:
600+
normalized_compiler = arguments.compiler_normalized()
600601
for compiler in Compiler.available_compilers():
601-
if compiler.is_matching_str(compiler_str):
602-
return compiler(compiler_str)
602+
if compiler.is_matching_str(normalized_compiler):
603+
return compiler(arguments.compiler) # type: ignore[arg-type]
603604

604-
raise UnsupportedCompilerError(f"Compiler '{compiler_str}' is not supported.")
605+
raise UnsupportedCompilerError(f"Compiler '{arguments.compiler}' is not supported.")
605606

606607
@staticmethod
607608
@abstractmethod
@@ -636,7 +637,7 @@ class Clang(Compiler):
636637
def is_matching_str(compiler_str: str) -> bool:
637638
return "clang" in compiler_str
638639

639-
def supports_target(self, target: str) -> bool:
640+
def supports_target(self, _: str) -> bool:
640641
"""For clang, we can not really check if it supports the target prior to compiling:
641642
'$ clang --print-targets' does not output the same triple format as we get from
642643
'$ clang --version' (x86_64 vs. x86-64), so we can not properly check if a target is supported.

tests/common/arguments_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,19 @@ def test_compiler_normalized(self):
256256
class TestCompiler:
257257
"""Tests the compiler class of homcc."""
258258

259-
def test_from_str(self):
260-
assert isinstance(Compiler.from_str("gcc"), Gcc)
261-
assert isinstance(Compiler.from_str("gcc-11"), Gcc)
262-
assert isinstance(Compiler.from_str("g++"), Gcc)
263-
assert isinstance(Compiler.from_str("g++-11"), Gcc)
264-
assert isinstance(Compiler.from_str("/usr/lib/ccache/gcc-11"), Gcc)
259+
def test_from_arguments(self):
260+
assert isinstance(Compiler.from_arguments(Arguments("gcc", [])), Gcc)
261+
assert isinstance(Compiler.from_arguments(Arguments("gcc-11", [])), Gcc)
262+
assert isinstance(Compiler.from_arguments(Arguments("g++", [])), Gcc)
263+
assert isinstance(Compiler.from_arguments(Arguments("g++-11", [])), Gcc)
264+
assert isinstance(Compiler.from_arguments(Arguments("/usr/lib/ccache/gcc-11", [])), Gcc)
265265

266-
assert isinstance(Compiler.from_str("clang++"), Clang)
267-
assert isinstance(Compiler.from_str("clang++-11"), Clang)
268-
assert isinstance(Compiler.from_str("/usr/lib/ccache/clang-14"), Clang)
266+
assert isinstance(Compiler.from_arguments(Arguments("clang++", [])), Clang)
267+
assert isinstance(Compiler.from_arguments(Arguments("clang++-11", [])), Clang)
268+
assert isinstance(Compiler.from_arguments(Arguments("/usr/lib/ccache/clang-14", [])), Clang)
269269

270270
with pytest.raises(UnsupportedCompilerError):
271-
Compiler.from_str("unknown++")
271+
Compiler.from_arguments(Arguments("unknown++", []))
272272

273273

274274
class TestGcc:

0 commit comments

Comments
 (0)