Target.optimization_flags converts non-numeric versions to numeric (#43179)

This commit is contained in:
Greg Becker 2024-03-20 09:39:26 -07:00 committed by GitHub
parent 485b6e2170
commit ecef72c471
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 5 deletions

View File

@ -155,4 +155,5 @@ def optimization_flags(self, compiler):
# log this and just return compiler.version instead
tty.debug(str(e))
compiler_version = compiler_version.dotted.force_numeric
return self.microarchitecture.optimization_flags(compiler.name, str(compiler_version))

View File

@ -193,12 +193,15 @@ def __getitem__(self, idx):
message = "{cls.__name__} indices must be integers"
raise TypeError(message.format(cls=cls))
def _stringify(self):
string = ""
for index in range(len(self.version)):
string += str(self.version[index])
string += str(self.separators[index])
return string
def __str__(self):
return (
self.string
if isinstance(self.string, str)
else ".".join((str(c) for c in self.version))
)
return self.string or self._stringify()
def __repr__(self) -> str:
# Print indirect repr through Version(...)
@ -257,6 +260,21 @@ def isdevelop(self):
isinstance(p, VersionStrComponent) and isinstance(p.data, int) for p in self.version
)
@property
def force_numeric(self):
"""Replaces all non-numeric components of the version with 0
This can be used to pass Spack versions to libraries that have stricter version schema.
"""
numeric = tuple(0 if isinstance(v, VersionStrComponent) else v for v in self.version)
# null separators except the final one have to be converted to avoid concatenating ints
# default to '.' as most common delimiter for versions
separators = tuple(
"." if s == "" and i != len(self.separators) - 1 else s
for i, s in enumerate(self.separators)
)
return type(self)(None, numeric, separators)
@property
def dotted(self):
"""The dotted representation of the version.