diff --git a/lib/spack/spack/target.py b/lib/spack/spack/target.py index cd28d8e5fa3..5f1f4f9e5a9 100644 --- a/lib/spack/spack/target.py +++ b/lib/spack/spack/target.py @@ -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)) diff --git a/lib/spack/spack/version/version_types.py b/lib/spack/spack/version/version_types.py index e34dc859967..3e403256ea8 100644 --- a/lib/spack/spack/version/version_types.py +++ b/lib/spack/spack/version/version_types.py @@ -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.