Skip to content

Commit

Permalink
Allow for dyld in ld linker version regex
Browse files Browse the repository at this point in the history
Allow for language dependency to not be a full path
Fix errors
Standardize use of splitext and handle case of version in extension
  • Loading branch information
langmm committed May 22, 2024
1 parent 0f1e581 commit e33c1e3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
4 changes: 3 additions & 1 deletion tests/drivers/test_CompiledModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ def test_libraries_getfile_library(self, python_class):
libtype = 'shared'
else:
libtype = 'static'
with pytest.raises(KeyError):
try:
python_class.libraries.getfile(dep, libtype)
except KeyError:
pass
with pytest.raises(KeyError):
python_class.libraries.getfile('invalid', 'library')
assert (python_class.libraries.getfile(
Expand Down
2 changes: 1 addition & 1 deletion tests/languages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_get_language_ext():
test_lang = constants.LANGUAGES_WITH_ALIASES['all']
for lang in test_lang:
if ((((lang == 'executable') and (not platform._is_win))
or (lang in ['dummy', 'mpi']))):
or (lang in ['dummy', 'mpi', 'make', 'cmake']))):
with pytest.raises(ValueError):
languages.get_language_ext(lang)
languages.get_language_ext(lang, default='')
Expand Down
5 changes: 3 additions & 2 deletions yggdrasil/drivers/CModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class ClangCompiler(CCompilerBase):
'prepend': True}),
('mmacosx-version-min',
'-mmacosx-version-min=%s')])
version_regex = r'(?P<version>(?:Apple )?clang version \d+\.\d+\.\d+)'
version_regex = [
r'(?P<version>(?:Apple )?clang version \d+\.\d+\.\d+)']
product_exts = ['.dSYM']
# Set to False since ClangLinker has its own class to handle
# conflict between versions of clang and ld.
Expand Down Expand Up @@ -219,7 +220,7 @@ class LDLinker(LinkerBase):
default_flags_env = 'LDFLAGS'
version_flags = ['-v']
version_regex = [
r'PROJECT:ld64-(?P<version>\d+(?:\.\d+)?)',
r'PROJECT:(?:(?:ld64)|(?:dyld))-(?P<version>\d+(?:\.\d+)?)',
(r'GNU ld \((?:GNU )?Binutils(?: for (?P<os>.+))?\) '
r'(?P<version>\d+(?:\.\d+){0,2})')
]
Expand Down
43 changes: 15 additions & 28 deletions yggdrasil/drivers/CompiledModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,11 @@ def tool_instance(self, tooltype, toolname=None, language=None,
if driver:
kwargs.setdefault('flags', self._flags(tooltype, driver))
if toolname and not kwargs.get('executable', None):
kwargs['executable'] = driver.cfg.get(
language, f'{toolname}_executable', None)
if hasattr(driver, 'cfg'):
kwargs['executable'] = driver.cfg.get(
language, f'{toolname}_executable', None)
else:
kwargs['executable'] = None
for k in out.associated_tooltypes:
kwargs.setdefault(k, self._toolname(k, driver))
kwargs.setdefault(f'{k}_flags',
Expand Down Expand Up @@ -685,7 +688,7 @@ def create_windows_import(dll, dst=None, for_gnu=False, overwrite=False,
else:
ext = '.lib'
assert ext in ['.dll.a', '.lib']
base = os.path.splitext(os.path.basename(dll))[0]
base = DependencyRegistry.splitext(os.path.basename(dll))[0]
if dst is None:
libbase = base
if ext == '.dll.a' and not libbase.startswith('lib'):
Expand Down Expand Up @@ -3442,7 +3445,7 @@ def _dep_libtool_kwargs(self, key, to_update=None, dep_libtype=None,
if self.is_rebuildable and not os.path.isfile(dep_lib):
dep_lib_result = self.build()[0]
assert dep_lib == dep_lib_result
if not os.path.isfile(dep_lib):
if (not os.path.isfile(dep_lib)) and (self.origin != 'language'):
raise RuntimeError(f"Library for {self.name} dependency "
f"does not exist: '{dep_lib}'.")
if ((self['libtype'] in self.library_files
Expand Down Expand Up @@ -4271,10 +4274,7 @@ def file2base(cls, fname):
str: File name without extension.
"""
out = os.path.splitext(os.path.basename(fname))[0]
if out.endswith('.dll'):
out = os.path.splitext(out)[0]
return out
return DependencyRegistry.splitext(os.path.basename(fname))[0]

@classmethod
def append_flags(cls, out, key, value, **kwargs):
Expand Down Expand Up @@ -4823,23 +4823,6 @@ def get_search_path(cls, env_only=False, libtype=None, cfg=None,
out.append(x)
return out

@classmethod
def splitext(cls, fname):
r"""Split a file extension, taking special care for the .dll.a
windows import extension.
Args:
fname (str): File path to split extension for.
Returns:
tuple(str, str): File base name and extension.
"""
if fname.endswith('.dll.a'):
ext = '.dll.a'
return fname.rsplit(ext, 1)[0], ext
return os.path.splitext(fname)

@classmethod
def cache_key(cls, fname, libtype, cache_toolname=False,
cache_key_base=None, **kwargs):
Expand All @@ -4859,7 +4842,8 @@ def cache_key(cls, fname, libtype, cache_toolname=False,
"""
if cache_key_base is None:
cache_key_base = os.path.basename(cls.splitext(fname)[0])
cache_key_base = os.path.basename(
DependencyRegistry.splitext(fname)[0])
if cache_key_base.startswith('lib'):
cache_key_base = cache_key_base[3:]
if '.' in cache_key_base:
Expand Down Expand Up @@ -5488,8 +5472,11 @@ def is_standard_libname(cls, libname):
"""
if cls.toolset == 'msvc': # pragma: windows
return False # Pass all libraries w/ ext
return (libname.startswith(cls.libtype_prefix[cls.library_libtype])
and libname.endswith(tuple(cls.all_library_ext)))
return (
libname.startswith(cls.libtype_prefix[cls.library_libtype])
and (libname.endswith(tuple(cls.all_library_ext))
or DependencyRegistry.splitext(libname).startswith(
tuple(cls.all_library_ext))))

@classmethod
def libpath2libname(cls, libpath):
Expand Down

0 comments on commit e33c1e3

Please sign in to comment.