microarchitectures: fix custom compiler versions (#13222)
Custom string versions for compilers were raising a ValueError on conversion to int. This commit fixes the behavior by trying to detect the underlying compiler version when in presence of a custom string version. * Refactor code that deals with custom versions for better readability * Partition version components with a regex * Fix semantic of custom compiler versions with a suffix * clang@x.y-apple has been special-cased * Add unit tests
This commit is contained in:

committed by
Todd Gamblin

parent
4ab63c17d5
commit
498f448ef3
@@ -5,6 +5,7 @@
|
||||
|
||||
from .microarchitecture import Microarchitecture, UnsupportedMicroarchitecture
|
||||
from .microarchitecture import targets, generic_microarchitecture
|
||||
from .microarchitecture import version_components
|
||||
from .detect import host
|
||||
|
||||
__all__ = [
|
||||
@@ -12,5 +13,6 @@
|
||||
'UnsupportedMicroarchitecture',
|
||||
'targets',
|
||||
'generic_microarchitecture',
|
||||
'host'
|
||||
'host',
|
||||
'version_components'
|
||||
]
|
||||
|
@@ -4,6 +4,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
import functools
|
||||
import platform
|
||||
import re
|
||||
import warnings
|
||||
|
||||
try:
|
||||
@@ -219,9 +220,9 @@ def satisfies_constraint(entry, version):
|
||||
min_version, max_version = entry['versions'].split(':')
|
||||
|
||||
# Check version suffixes
|
||||
min_version, _, min_suffix = min_version.partition('-')
|
||||
max_version, _, max_suffix = max_version.partition('-')
|
||||
version, _, suffix = version.partition('-')
|
||||
min_version, min_suffix = version_components(min_version)
|
||||
max_version, max_suffix = version_components(max_version)
|
||||
version, suffix = version_components(version)
|
||||
|
||||
# If the suffixes are not all equal there's no match
|
||||
if ((suffix != min_suffix and min_version) or
|
||||
@@ -277,6 +278,26 @@ def generic_microarchitecture(name):
|
||||
)
|
||||
|
||||
|
||||
def version_components(version):
|
||||
"""Decomposes the version passed as input in version number and
|
||||
suffix and returns them.
|
||||
|
||||
If the version number of the suffix are not present, an empty
|
||||
string is returned.
|
||||
|
||||
Args:
|
||||
version (str): version to be decomposed into its components
|
||||
"""
|
||||
match = re.match(r'([\d.]*)(-?)(.*)', str(version))
|
||||
if not match:
|
||||
return '', ''
|
||||
|
||||
version_number = match.group(1)
|
||||
suffix = match.group(3)
|
||||
|
||||
return version_number, suffix
|
||||
|
||||
|
||||
def _known_microarchitectures():
|
||||
"""Returns a dictionary of the known micro-architectures. If the
|
||||
current host platform is unknown adds it too as a generic target.
|
||||
|
Reference in New Issue
Block a user