summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-12-29 21:16:07 +0100
committerGitHub <noreply@github.com>2021-12-29 12:16:07 -0800
commitc2e1a12cdf44edd7f29e465bbdfdc511b97d9669 (patch)
tree2d24203ed88b5b99ba612e6a141abaed45952c50 /lib
parent27202b22402f1655c730fc167d4e659db82eab54 (diff)
downloadspack-c2e1a12cdf44edd7f29e465bbdfdc511b97d9669.tar.gz
spack-c2e1a12cdf44edd7f29e465bbdfdc511b97d9669.tar.bz2
spack-c2e1a12cdf44edd7f29e465bbdfdc511b97d9669.tar.xz
spack-c2e1a12cdf44edd7f29e465bbdfdc511b97d9669.zip
Ensure some version known to Spack can satisfy constraints in `depends_on` (#28131)
Add a new check to `spack audit` to scan and verify that version constraints may be satisfied Modifications: - [x] Add a new check to `spack audit` to scan and verify that version constraints may be satisfied by some version declared in the built-in repository - [x] Fix issues found by CI Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/audit.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/spack/spack/audit.py b/lib/spack/spack/audit.py
index f6ef90e0b8..db68460394 100644
--- a/lib/spack/spack/audit.py
+++ b/lib/spack/spack/audit.py
@@ -407,6 +407,46 @@ def _unknown_variants_in_dependencies(pkgs, error_cls):
return errors
+@package_directives
+def _version_constraints_are_satisfiable_by_some_version_in_repo(pkgs, error_cls):
+ """Report if version constraints used in directives are not satisfiable"""
+ import spack.repo
+
+ errors = []
+ for pkg_name in pkgs:
+ pkg = spack.repo.get(pkg_name)
+ filename = spack.repo.path.filename_for_package_name(pkg_name)
+ dependencies_to_check = []
+ for dependency_name, dependency_data in pkg.dependencies.items():
+ # Skip virtual dependencies for the time being, check on
+ # their versions can be added later
+ if spack.repo.path.is_virtual(dependency_name):
+ continue
+
+ dependencies_to_check.extend(
+ [edge.spec for edge in dependency_data.values()]
+ )
+
+ for s in dependencies_to_check:
+ dependency_pkg = None
+ try:
+ dependency_pkg = spack.repo.get(s.name)
+ assert any(
+ v.satisfies(s.versions) for v in list(dependency_pkg.versions)
+ )
+ except Exception:
+ summary = ("{0}: dependency on {1} cannot be satisfied "
+ "by known versions of {1.name}").format(pkg_name, s)
+ details = ['happening in ' + filename]
+ if dependency_pkg is not None:
+ details.append('known versions of {0.name} are {1}'.format(
+ s, ', '.join([str(x) for x in dependency_pkg.versions])
+ ))
+ errors.append(error_cls(summary=summary, details=details))
+
+ return errors
+
+
def _analyze_variants_in_directive(pkg, constraint, directive, error_cls):
import spack.variant
variant_exceptions = (