summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Becker <becker33@llnl.gov>2024-03-20 09:39:26 -0700
committerGitHub <noreply@github.com>2024-03-20 09:39:26 -0700
commitecef72c47185eb4ee3e8eed0c5448354c16ac30c (patch)
tree10b9062a869b690a986d674097af545f2ba3102c /lib
parent485b6e2170bf4ace96f0cae6635db5aad0468700 (diff)
downloadspack-ecef72c47185eb4ee3e8eed0c5448354c16ac30c.tar.gz
spack-ecef72c47185eb4ee3e8eed0c5448354c16ac30c.tar.bz2
spack-ecef72c47185eb4ee3e8eed0c5448354c16ac30c.tar.xz
spack-ecef72c47185eb4ee3e8eed0c5448354c16ac30c.zip
Target.optimization_flags converts non-numeric versions to numeric (#43179)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/target.py1
-rw-r--r--lib/spack/spack/version/version_types.py28
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/spack/spack/target.py b/lib/spack/spack/target.py
index cd28d8e5fa..5f1f4f9e5a 100644
--- a/lib/spack/spack/target.py
+++ b/lib/spack/spack/target.py
@@ -155,4 +155,5 @@ class Target:
# 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))
diff --git a/lib/spack/spack/version/version_types.py b/lib/spack/spack/version/version_types.py
index e34dc85996..3e403256ea 100644
--- a/lib/spack/spack/version/version_types.py
+++ b/lib/spack/spack/version/version_types.py
@@ -193,12 +193,15 @@ class StandardVersion(ConcreteVersion):
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(...)
@@ -258,6 +261,21 @@ class StandardVersion(ConcreteVersion):
)
@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.