Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into linker-lib-flags2
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker committed Jan 9, 2025
2 parents 0464dc5 + e7ae9fe commit d806432
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 2 additions & 0 deletions source/fab/steps/compile_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def _compile_file(arg: Tuple[AnalysedC, MpCommonArgs]):
if compiler.category != Category.C_COMPILER:
raise RuntimeError(f"Unexpected tool '{compiler.name}' of category "
f"'{compiler.category}' instead of CCompiler")
# Tool box returns a Tool, in order to make mypy happy, we need
# to cast it to be a Compiler.
compiler = cast(Compiler, compiler)
with Timer() as timer:
flags = Flags(mp_payload.flags.flags_for_path(path=analysed_file.fpath,
Expand Down
4 changes: 4 additions & 0 deletions source/fab/steps/compile_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def handle_compiler_args(config: BuildConfig, common_flags=None,
if compiler.category != Category.FORTRAN_COMPILER:
raise RuntimeError(f"Unexpected tool '{compiler.name}' of category "
f"'{compiler.category}' instead of FortranCompiler")
# The ToolBox returns a Tool. In order to make mypy happy, we need to
# cast this to become a Compiler.
compiler = cast(Compiler, compiler)
logger.info(
f'Fortran compiler is {compiler} {compiler.get_version_string()}')
Expand Down Expand Up @@ -268,6 +270,8 @@ def process_file(arg: Tuple[AnalysedFortran, MpCommonArgs]) \
raise RuntimeError(f"Unexpected tool '{compiler.name}' of "
f"category '{compiler.category}' instead of "
f"FortranCompiler")
# The ToolBox returns a Tool, but we need to tell mypy that
# this is a Compiler
compiler = cast(Compiler, compiler)
flags = Flags(mp_common_args.flags.flags_for_path(
path=analysed_file.fpath, config=config))
Expand Down
4 changes: 2 additions & 2 deletions source/fab/tools/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, name: str,

@property
def mpi(self) -> bool:
'''Returns whether this compiler supports MPI or not.'''
''':returns: whether this compiler supports MPI or not.'''
return self._mpi

@property
Expand All @@ -75,7 +75,7 @@ def openmp(self) -> bool:

@property
def openmp_flag(self) -> str:
'''Returns the flag to enable OpenMP.'''
''':returns: the flag to enable OpenMP.'''
return self._openmp_flag

def get_hash(self) -> int:
Expand Down
3 changes: 3 additions & 0 deletions source/fab/tools/compiler_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def compile_file(self, input_file: Path,
a syntax check
'''

# TODO #370: replace change_exec_name, and instead provide
# a function that returns the whole command line, which can
# then be modified here.
orig_compiler_name = self._compiler.exec_name
self._compiler.change_exec_name(self.exec_name)
if add_flags is None:
Expand Down
22 changes: 11 additions & 11 deletions tests/unit_tests/tools/test_compiler_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'''Tests the compiler wrapper implementation.
'''

from pathlib import Path, PosixPath
from pathlib import Path
from unittest import mock

import pytest
Expand Down Expand Up @@ -178,10 +178,10 @@ def test_compiler_wrapper_fortran_with_add_args():
syntax_only=True)
# Notice that "-J/b" has been removed
mpif90.compiler.run.assert_called_with(
cwd=PosixPath('.'), additional_parameters=['-c', "-O3",
'-fsyntax-only',
'-J', '/module_out',
'a.f90', '-o', 'a.o'])
cwd=Path('.'), additional_parameters=['-c', "-O3",
'-fsyntax-only',
'-J', '/module_out',
'a.f90', '-o', 'a.o'])


def test_compiler_wrapper_fortran_with_add_args_unnecessary_openmp():
Expand All @@ -198,7 +198,7 @@ def test_compiler_wrapper_fortran_with_add_args_unnecessary_openmp():
add_flags=["-fopenmp", "-O3"],
openmp=True, syntax_only=True)
mpif90.compiler.run.assert_called_with(
cwd=PosixPath('.'),
cwd=Path('.'),
additional_parameters=['-c', '-fopenmp', '-fopenmp', '-O3',
'-fsyntax-only', '-J', '/module_out',
'a.f90', '-o', 'a.o'])
Expand All @@ -218,8 +218,8 @@ def test_compiler_wrapper_c_with_add_args():
mpicc.compile_file(Path("a.f90"), "a.o", openmp=False,
add_flags=["-O3"])
mpicc.compiler.run.assert_called_with(
cwd=PosixPath('.'), additional_parameters=['-c', "-O3",
'a.f90', '-o', 'a.o'])
cwd=Path('.'), additional_parameters=['-c', "-O3", 'a.f90',
'-o', 'a.o'])
# Invoke C compiler with syntax-only flag (which is only supported
# by Fortran compilers), which should raise an exception.
with pytest.raises(RuntimeError) as err:
Expand All @@ -237,7 +237,7 @@ def test_compiler_wrapper_c_with_add_args():
add_flags=["-fopenmp", "-O3"],
openmp=True)
mpicc.compiler.run.assert_called_with(
cwd=PosixPath('.'),
cwd=Path('.'),
additional_parameters=['-c', '-fopenmp', '-fopenmp', '-O3',
'a.f90', '-o', 'a.o'])

Expand Down Expand Up @@ -280,7 +280,7 @@ def test_compiler_wrapper_flags_with_add_arg():
mpicc.compile_file(Path("a.f90"), "a.o", add_flags=["-f"],
openmp=True)
mpicc.compiler.run.assert_called_with(
cwd=PosixPath('.'),
cwd=Path('.'),
additional_parameters=["-c", "-fopenmp", "-a", "-b", "-d",
"-e", "-f", "a.f90", "-o", "a.o"])

Expand All @@ -299,7 +299,7 @@ def test_compiler_wrapper_flags_without_add_arg():
# Test if no add_flags are specified:
mpicc.compile_file(Path("a.f90"), "a.o", openmp=True)
mpicc.compiler.run.assert_called_with(
cwd=PosixPath('.'),
cwd=Path('.'),
additional_parameters=["-c", "-fopenmp", "-a", "-b", "-d",
"-e", "a.f90", "-o", "a.o"])

Expand Down

0 comments on commit d806432

Please sign in to comment.