Skip to content

Commit

Permalink
Fix compiler normalization issue
Browse files Browse the repository at this point in the history
  • Loading branch information
OliLay authored Aug 12, 2022
1 parent 68927cd commit 295b331
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
13 changes: 7 additions & 6 deletions homcc/common/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions tests/common/arguments_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 295b331

Please sign in to comment.