Skip to content

Commit d98c890

Browse files
authored
Detect fortran compiler from wrapper (#526)
Small PR to fix #525 (and added additional test coverage).
1 parent 809483e commit d98c890

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

source/fab/tools/tool_repository.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ def get_default(self, category: Category,
294294
if category == Category.LINKER:
295295
tool = cast(Linker, tool)
296296
compiler = tool.compiler
297+
# Find the real compiler if we have a compiler wrapper:
298+
while isinstance(compiler, CompilerWrapper):
299+
compiler = compiler.compiler
297300
# Ignore C linker if Fortran is requested and vice versa:
298301
if (enforce_fortran_linker and
299302
not isinstance(compiler, FortranCompiler)):

tests/unit_tests/tools/test_tool_repository.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from fab.tools.ar import Ar
1616
from fab.tools.category import Category
1717
from fab.tools.compiler import Compiler, FortranCompiler, Gfortran, Ifort
18-
from fab.tools.compiler_wrapper import Mpif90
18+
from fab.tools.compiler_wrapper import Mpicc, Mpif90
19+
from fab.tools.linker import Linker
1920
from fab.tools.tool_repository import ToolRepository
2021

2122
from tests.conftest import call_list
@@ -125,6 +126,33 @@ def test_get_default(stub_tool_repository, stub_fortran_compiler,
125126
assert isinstance(ar, Ar)
126127

127128

129+
def test_get_default_linker_with_wrapper(stub_tool_repository,
130+
stub_fortran_compiler,
131+
stub_c_compiler) -> None:
132+
"""
133+
Tests that we get the right linker if compiler wrapper are used.
134+
"""
135+
136+
# Add a linker around a compiler wrapper, to test that the compiler
137+
# wrapper is recognised as a Fortran compiler:
138+
linker = Linker(Mpif90(stub_fortran_compiler))
139+
linker._is_available = True
140+
stub_tool_repository.add_tool(linker)
141+
for_link = stub_tool_repository.get_default(Category.LINKER, mpi=True,
142+
openmp=True,
143+
enforce_fortran_linker=True)
144+
assert for_link is linker
145+
146+
# Now the same for a linker around a C compiler wrapper:
147+
linker = Linker(Mpicc(stub_c_compiler))
148+
linker._is_available = True
149+
stub_tool_repository.add_tool(linker)
150+
cc_link = stub_tool_repository.get_default(Category.LINKER, mpi=True,
151+
openmp=True,
152+
enforce_fortran_linker=False)
153+
assert cc_link is linker
154+
155+
128156
def test_get_default_error_invalid_category() -> None:
129157
"""
130158
Tests error handling in get_default, the category must be a Category,
@@ -152,6 +180,11 @@ def test_get_default_error_missing_mpi() -> None:
152180
assert str(err.value) == ("Invalid or missing openmp specification "
153181
"for 'FORTRAN_COMPILER'.")
154182

183+
with raises(RuntimeError) as err:
184+
tr.get_default(Category.LINKER, mpi=True, openmp=True)
185+
assert str(err.value) == ("Invalid or missing enforce_fortran_linker "
186+
"specification for 'LINKER'.")
187+
155188

156189
def test_get_default_error_missing_openmp() -> None:
157190
"""

0 commit comments

Comments
 (0)