Skip to content

Commit

Permalink
Update is_installed for compiled tools to check version regex
Browse files Browse the repository at this point in the history
  • Loading branch information
langmm committed Jun 26, 2024
1 parent 57077c7 commit 970c689
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
2 changes: 2 additions & 0 deletions yggdrasil/drivers/CModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ class LibtoolArchiver(ArchiverBase):
libtype_flags = {'static': '-static'}
toolset = 'llvm'
search_path_envvar = ['LIBRARY_PATH']
version_regex = [
r'(?P<version>)error\: .*libtool\: .+']


class MSVCArchiver(ArchiverBase):
Expand Down
40 changes: 28 additions & 12 deletions yggdrasil/drivers/CompiledModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,22 @@ def logInfo(self, msg='', level=logging.INFO, tooltype=None,
continue
cls = self.tooltype[tooltype][k]
row = []
is_installed = None
for col in columns:
val = False
if col == 'installed':
if cls.is_installed():
val = cls.tool_version(require_match=True)
val = val.splitlines()[0] if val else True
val = cls.tool_version(require_match=True,
default=False)
assert val is not False
if val is not False:
val = val.splitlines()[0] if val else True
is_installed = bool(val)
elif col == 'alias for':
val = cls.is_alias()
elif col == 'executable':
if cls.is_installed():
assert is_installed is not None
if is_installed:
val = cls.get_executable(full_path=True)
else:
val = getattr(cls, col)
Expand All @@ -169,7 +175,7 @@ def logInfo(self, msg='', level=logging.INFO, tooltype=None,
else:
val = ', '.join(val)
val = str(val)
if col != 'executable': # 'installed':
if col != columns[-1]:
widths[col] = max(widths[col], len(val))
row.append(val)
rows.append(row)
Expand Down Expand Up @@ -4759,7 +4765,9 @@ def is_installed(cls, cfg=None):
"""
try:
cls.get_executable(cfg=cfg)
return True
ver = cls.tool_version(require_match=True,
default=False, cfg=cfg)
return isinstance(ver, str)
except InvalidCompilationTool:
return False

Expand Down Expand Up @@ -5235,7 +5243,7 @@ def cache_key(cls, fname, libtype, cache_toolname=False,
@classmethod
def get_executable_command(cls, args, skip_flags=False,
unused_kwargs=None, use_ccache=False,
executable=None, **kwargs):
executable=None, cfg=None, **kwargs):
r"""Determine the command required to run the tool using the
specified arguments and options.
Expand All @@ -5255,6 +5263,9 @@ def get_executable_command(cls, args, skip_flags=False,
executable (str, optional): Executable that should be used.
If not provided, the output of cls.get_executable(full_path=True)
will be used.
cfg (CisConfigParser, optional): Configuration options that
should be checked for a tool executable path. If not
provided, yggdrasil.config.ygg_cfg will be used.
**kwargs: Additional keyword arguments are ignored and stored in
unused_kwargs if provided.
Expand All @@ -5276,7 +5287,7 @@ def get_executable_command(cls, args, skip_flags=False,
library_flags=library_flags, **kwargs)
# Form command
if executable is None:
executable = cls.get_executable(full_path=True)
executable = cls.get_executable(full_path=True, cfg=cfg)
cmd = flags + args + library_flags
cmd = [executable] + cmd
if use_ccache and shutil.which('ccache'):
Expand Down Expand Up @@ -5324,13 +5335,15 @@ def append_product(cls, products, new, sources=None,
return products.last

@staticmethod
def extract_tool_version(cls, x, require_match=False):
def extract_tool_version(cls, x, require_match=False, default=''):
r"""Extract the tool's version from the provided string.
Args:
x (str): Raw version string.
require_match (bool, optional): If True, a match to
version_regex is required.
default (str, optional): String that should be returned if
there is no match and require_match is True.
Returns:
str: Extracted version string.
Expand All @@ -5347,15 +5360,15 @@ def extract_tool_version(cls, x, require_match=False):
if match is not None:
return match.group('version')
if require_match:
return ''
return default
warnings.warn(
f"Could not locate version in string: {x} with "
f"regex {cls.version_regex}")
if x and require_match:
# raise Exception(f"{cls}: {cls.tooltype.title()} "
# f"{cls.toolname} does not have a "
# f"version regex")
return ''
return default
return x

@staticmethod
Expand Down Expand Up @@ -5393,14 +5406,17 @@ class properties.
return CompilationToolBase.extract_tool_version(cls, out, **kwargs)

@classmethod
def tool_version(cls, skip_regex=False, require_match=False, **kwargs):
def tool_version(cls, skip_regex=False, require_match=False,
default='', **kwargs):
r"""Get the version of the compilation tool.
Args:
skip_regex (bool, optional): If True, don't call
extract_tool_version and return the raw version result.
require_match (bool, optional): If True, a match to
version_regex is required.
default (str, optional): String that should be returned if
there is no match and require_match is True.
**kwargs: Additional keyword arguments are passed to call.
Returns:
Expand All @@ -5412,7 +5428,7 @@ def tool_version(cls, skip_regex=False, require_match=False, **kwargs):
if skip_regex:
return out
return CompilationToolBase.extract_tool_version(
cls, out, require_match=require_match)
cls, out, require_match=require_match, default=default)

@classmethod
def run_executable_command(cls, args, skip_flags=False,
Expand Down

0 comments on commit 970c689

Please sign in to comment.