From 1dfbf91eaca3adf9ed7c5bc4fed67e5adc97abf5 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 26 Sep 2024 16:14:41 +0200 Subject: [PATCH] spec: bump specfile format to v5 Signed-off-by: Massimiliano Culpo --- lib/spack/spack/database.py | 5 +++- lib/spack/spack/spec.py | 54 +++++++++++++------------------------ 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py index ed68b5d13c0..04030b146f4 100644 --- a/lib/spack/spack/database.py +++ b/lib/spack/spack/database.py @@ -80,7 +80,7 @@ #: DB version. This is stuck in the DB file to track changes in format. #: Increment by one when the database format changes. #: Versions before 5 were not integers. -_DB_VERSION = vn.Version("7") +_DB_VERSION = vn.Version("8") #: For any version combinations here, skip reindex when upgrading. #: Reindexing can take considerable time and is not always necessary. @@ -93,6 +93,8 @@ (vn.Version("0.9.3"), vn.Version("5")), (vn.Version("5"), vn.Version("6")), (vn.Version("6"), vn.Version("7")), + (vn.Version("6"), vn.Version("8")), + (vn.Version("7"), vn.Version("8")), ] #: Default timeout for spack database locks in seconds or None (no timeout). @@ -141,6 +143,7 @@ def reader(version: vn.StandardVersion) -> Type["spack.spec.SpecfileReaderBase"] vn.Version("5"): spack.spec.SpecfileV1, vn.Version("6"): spack.spec.SpecfileV3, vn.Version("7"): spack.spec.SpecfileV4, + vn.Version("8"): spack.spec.SpecfileV5, } return reader_cls[version] diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index af220e7e23c..db46551342f 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -185,7 +185,7 @@ ) #: specfile format version. Must increase monotonically -SPECFILE_FORMAT_VERSION = 4 +SPECFILE_FORMAT_VERSION = 5 class InstallStatus(enum.Enum): @@ -607,42 +607,11 @@ def complete_with_defaults(self) -> None: self.target = default_architecture.target +# FIXME (compiler as nodes): remove this class class CompilerSpec: - """The CompilerSpec field represents the compiler or range of compiler - versions that a package should be built with. CompilerSpecs have a - name and a version list.""" - - __slots__ = "name", "versions" - def __init__(self, *args): raise SystemExit("CompilerSpec is being removed") - @staticmethod - def from_dict(d): - d = d["compiler"] - return Spec( - f"{d['name']}@{vn.VersionList.from_dict(d)}", external_path="/dev-null/", concrete=True - ) - - @property - def display_str(self): - """Equivalent to {compiler.name}{@compiler.version} for Specs, without extra - @= for readability.""" - if self.concrete: - return f"{self.name}@{self.version}" - elif self.versions != vn.any_version: - return f"{self.name}@{self.versions}" - return self.name - - def __str__(self): - out = self.name - if self.versions and self.versions != vn.any_version: - out += f"@{self.versions}" - return out - - def __repr__(self): - return str(self) - @lang.lazy_lexicographic_ordering class DependencySpec: @@ -2521,8 +2490,10 @@ def from_dict(data): spec = SpecfileV2.load(data) elif int(data["spec"]["_meta"]["version"]) == 3: spec = SpecfileV3.load(data) - else: + elif int(data["spec"]["_meta"]["version"]) == 4: spec = SpecfileV4.load(data) + else: + spec = SpecfileV5.load(data) # Any git version should for s in spec.traverse(): @@ -4726,7 +4697,7 @@ def from_node_dict(cls, node): if "compiler" in node: # Annotate the compiler spec, might be used later - spec.compiler_annotation = CompilerSpec.from_dict(node) + spec.compiler_annotation = cls.legacy_compiler(node) propagated_names = node.get("propagate", []) for name, values in node.get("parameters", {}).items(): @@ -4774,6 +4745,13 @@ def from_node_dict(cls, node): return spec + @classmethod + def legacy_compiler(cls, node): + d = node["compiler"] + return Spec( + f"{d['name']}@{vn.VersionList.from_dict(d)}", external_path="/dev-null/", concrete=True + ) + @classmethod def _load(cls, data): """Construct a spec from JSON/YAML using the format version 2. @@ -4980,6 +4958,12 @@ def load(cls, data): return cls._load(data) +class SpecfileV5(SpecfileV4): + @classmethod + def legacy_compiler(cls, node): + raise RuntimeError("The 'compiler' option is unexpected in specfiles at v5 or greater") + + class LazySpecCache(collections.defaultdict): """Cache for Specs that uses a spec_like as key, and computes lazily the corresponding value ``Spec(spec_like``.