Skip to content

Commit

Permalink
Allow failure to get tool version for log message
Browse files Browse the repository at this point in the history
Fix is_mingw for fortran compiler
  • Loading branch information
langmm committed Mar 1, 2024
1 parent 2ee5095 commit c5601be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
17 changes: 10 additions & 7 deletions yggdrasil/drivers/CompiledModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ def get_search_path(cls, env_only=False, libtype=None, cfg=None):
# Get flags based on path
if (cls.search_path_flags is not None) and (not env_only):
output = cls.call(cls.search_path_flags, skip_flags=True,
allow_error=True)
allow_error=True, for_version=True)
# Split on beginning & ending regexes if they exist
if cls.search_regex_begin is not None:
output = re.split(cls.search_regex_begin, output)[-1]
Expand Down Expand Up @@ -1107,7 +1107,8 @@ def locate_file(cls, fname, libtype=None, verbose=False, **kwargs):
# On windows search for both gnu and msvc library
# naming conventions
if platform._is_win: # pragma: windows
logger.info("Searching for base: %s" % fname)
logger.info(f"Searching for base (libtype={libtype}): "
f"{fname}")
ext_sets = (('.dll', '.dll.a'),
('.lib', ))
for exts in ext_sets:
Expand Down Expand Up @@ -1348,8 +1349,11 @@ def call(cls, args, language=None, toolname=None, skip_flags=False,
f"Executable: {cls.get_executable(full_path=True)}\n"
f"Command: \"{' '.join(cmd)}\"")
if not for_version:
message_before = (
f"Version: {cls.tool_version()}\n{message_before}")
try:
message_before = (
f"Version: {cls.tool_version()}\n{message_before}")
except BaseException: # pragma: debug
pass
if verbose:
logger.info(message_before)
else:
Expand Down Expand Up @@ -2057,16 +2061,15 @@ def find_standard_library(cls, name=None, flags=None, libtype=None,
libtype = 'shared'
if (not dont_cache) and f"{name}_library" in cls._language_cache:
return cls._language_cache[f"{name}_library"]
if not (cls.source_exts and cls.source_dummy):
return None
if flags is None:
flags = []
products = tools.IntegrationPathSet(overwrite=True)
lib = None
libx = ''
libx_options = [name]
try:
if libtype in ['shared', 'windows_import']:
if ((libtype in ['shared', 'windows_import']
and cls.source_exts and cls.source_dummy)):
linker = cls.linker()
disassembler = cls.disassembler()
fname = os.path.join(os.getcwd(),
Expand Down
18 changes: 12 additions & 6 deletions yggdrasil/drivers/FortranModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class GFortranCompiler(FortranCompilerBase):
default_archiver = 'ar'
default_disassembler = 'objdump'
standard_library = 'gfortran'
is_mingw = False
is_msys = False
# GNU ASAN not currently installed with gfortran on osx
# asan_flags = ['-fsanitize=address']
# linker_attributes = dict(
Expand Down Expand Up @@ -160,12 +158,20 @@ def after_registration(cls, **kwargs):
_compiler_env, followed by the existing class attribute.
"""
FortranCompilerBase.after_registration(cls, **kwargs)
ver = cls.tool_version()
cls.is_mingw = 'mingw' in ver.lower()
cls.is_msys = 'msys' in ver.lower()
if cls.is_mingw or cls.is_msys:
if cls.is_mingw():
cls.standard_library_type = 'static'

@classmethod
def is_mingw(cls):
r"""Check if the class provides access to a mingw/msys compiler"""
if cls._is_mingw is None:
ver = cls.tool_version()
cls._is_mingw = ('mingw' in ver.lower()
or 'msys' in ver.lower())
logger.info(f"Setting is_mingw to {cls._is_mingw}: "
f"ver = {ver}")
return cls._is_mingw


# class IFortCompiler(FortranCompilerBase):
# r"""Interface class for ifort compiler/linker."""
Expand Down

0 comments on commit c5601be

Please sign in to comment.