Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions homcc/common/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,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 @@ -594,12 +594,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 @@ -634,7 +635,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