From 2fafba4395657eb740630f15abe96fe84ce8762e Mon Sep 17 00:00:00 2001 From: Philip Sakievich Date: Fri, 28 Feb 2025 12:48:39 -0700 Subject: [PATCH] Add package class hook for SNL work --- lib/spack/spack/package_base.py | 9 ++++++ lib/spack/spack/solver/asp.py | 36 ++++++++++++++++++++++++ lib/spack/spack/version/version_types.py | 6 ++++ 3 files changed, 51 insertions(+) diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py index b2ab47ed359..c84221462e0 100644 --- a/lib/spack/spack/package_base.py +++ b/lib/spack/spack/package_base.py @@ -989,6 +989,15 @@ def detect_dev_src_change(self) -> bool: assert dev_path_var and record, "dev_path variant and record must be present" return fsys.recursive_mtime_greater_than(dev_path_var.value, record.installation_time) + def resolve_binary_provenance(self): + """ + Method to ensure concrete spec has binary provenance. + Base implementation will look up git commits when appropriate. + Packages may override this implementation for custom implementations + """ + # TODO in follow on PR adding here so SNL team can begin work ahead of spack core + pass + def all_urls_for_version(self, version: StandardVersion) -> List[str]: """Return all URLs derived from version_urls(), url, urls, and list_url (if it contains a version) in a package in that order. diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index 262e4b2e18a..d20b37efd19 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -4185,6 +4185,42 @@ def execute_explicit_splices(self): return specs +def _specs_with_commits(spec): + # StandardVersions paired to git branches or tags and GitVersions + if not spec.version.needs_commit: + return + spec.package.resolve_binary_provenance() + + # method above is in charge of assigning the commit variant + has_commit_var = "commit" in spec.variants + has_git_version = isinstance(spec.version, vn.GitVersion) + + if not (has_commit_var or has_git_version): + return + + # Specs with commit variants + # - variant value satsifies commit regex + # - paired to a GitVersion or version that is associated with a branch/tag + # - variant value should match GitVersion's commit value + if has_commit_var: + invalid_commit_msg = ( + f"Internal Error: {spec.name}'s assigned commit {spec.variants['commit'].value}" + " does not meet commit syntax requirements." + ) + + # TODO probably want a more specific function just for sha validation + assert vn.is_git_version(spec.variants["commit"].value), invalid_commit_msg + + # Specs with GitVersions + # - must have a commit variant, or add it here + # - must have a commit on the GitVersion (enforce after look up implemented) + if has_git_version: + if not spec.version.commit_sha: + # TODO(psakiev) this will be a failure when commit look up is automated + return + spec.variants["commit"] = vt.SingleValuedVariant("commit", spec.version.commit_sha) + + def _inject_patches_variant(root: spack.spec.Spec) -> None: # This dictionary will store object IDs rather than Specs as keys # since the Spec __hash__ will change as patches are added to them diff --git a/lib/spack/spack/version/version_types.py b/lib/spack/spack/version/version_types.py index 7f9f91004dd..d80354cdb7e 100644 --- a/lib/spack/spack/version/version_types.py +++ b/lib/spack/spack/version/version_types.py @@ -391,6 +391,9 @@ def isdevelop(self) -> bool: isinstance(p, VersionStrComponent) and isinstance(p.data, int) for p in self.version[0] ) + def needs_commit(self) -> bool: + return bool(self.get("branch") or self.get("tag")) + def is_prerelease(self) -> bool: return self.version[1][0] != FINAL @@ -716,6 +719,9 @@ def __hash__(self): def __contains__(self, other: object) -> bool: raise NotImplementedError + def needs_commit(self) -> bool: + return True + @property def ref_lookup(self): if self._ref_lookup: