Target.optimization_flags converts non-numeric versions to numeric (#43179)
This commit is contained in:
parent
485b6e2170
commit
ecef72c471
@ -155,4 +155,5 @@ def optimization_flags(self, compiler):
|
|||||||
# log this and just return compiler.version instead
|
# log this and just return compiler.version instead
|
||||||
tty.debug(str(e))
|
tty.debug(str(e))
|
||||||
|
|
||||||
|
compiler_version = compiler_version.dotted.force_numeric
|
||||||
return self.microarchitecture.optimization_flags(compiler.name, str(compiler_version))
|
return self.microarchitecture.optimization_flags(compiler.name, str(compiler_version))
|
||||||
|
@ -193,12 +193,15 @@ def __getitem__(self, idx):
|
|||||||
message = "{cls.__name__} indices must be integers"
|
message = "{cls.__name__} indices must be integers"
|
||||||
raise TypeError(message.format(cls=cls))
|
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):
|
def __str__(self):
|
||||||
return (
|
return self.string or self._stringify()
|
||||||
self.string
|
|
||||||
if isinstance(self.string, str)
|
|
||||||
else ".".join((str(c) for c in self.version))
|
|
||||||
)
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
# Print indirect repr through Version(...)
|
# 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
|
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
|
@property
|
||||||
def dotted(self):
|
def dotted(self):
|
||||||
"""The dotted representation of the version.
|
"""The dotted representation of the version.
|
||||||
|
Loading…
Reference in New Issue
Block a user