concretizer: ensure upfront that variants are valid
This commit is contained in:
parent
ae1ef85af5
commit
a0e8ad7a8b
@ -207,7 +207,7 @@ def check_packages_exist(specs):
|
|||||||
tty.debug(msg)
|
tty.debug(msg)
|
||||||
|
|
||||||
if not check_passed:
|
if not check_passed:
|
||||||
raise spack.error.SpecError(str(s.name))
|
raise spack.repo.UnknownPackageError(str(s.fullname))
|
||||||
|
|
||||||
|
|
||||||
class Result(object):
|
class Result(object):
|
||||||
@ -1753,5 +1753,12 @@ def solve(specs, dump=(), models=0, timers=False, stats=False, tests=False):
|
|||||||
if "asp" in dump:
|
if "asp" in dump:
|
||||||
driver.out = sys.stdout
|
driver.out = sys.stdout
|
||||||
|
|
||||||
|
# Check upfront that the variants are admissible
|
||||||
|
for root in specs:
|
||||||
|
for s in root.traverse():
|
||||||
|
if s.virtual:
|
||||||
|
continue
|
||||||
|
spack.spec.Spec.ensure_valid_variants(s)
|
||||||
|
|
||||||
setup = SpackSolverSetup()
|
setup = SpackSolverSetup()
|
||||||
return driver.solve(setup, specs, dump, models, timers, stats, tests)
|
return driver.solve(setup, specs, dump, models, timers, stats, tests)
|
||||||
|
@ -2858,17 +2858,29 @@ def validate_or_raise(self):
|
|||||||
|
|
||||||
# Ensure correctness of variants (if the spec is not virtual)
|
# Ensure correctness of variants (if the spec is not virtual)
|
||||||
if not spec.virtual:
|
if not spec.virtual:
|
||||||
|
Spec.ensure_valid_variants(spec)
|
||||||
|
vt.substitute_abstract_variants(spec)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def ensure_valid_variants(spec):
|
||||||
|
"""Ensures that the variant attached to a spec are valid.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
spec (Spec): spec to be analyzed
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
UnknownVariantError: on the first unknown variant found
|
||||||
|
"""
|
||||||
pkg_cls = spec.package_class
|
pkg_cls = spec.package_class
|
||||||
pkg_variants = pkg_cls.variants
|
pkg_variants = pkg_cls.variants
|
||||||
# reserved names are variants that may be set on any package
|
# reserved names are variants that may be set on any package
|
||||||
# but are not necessarily recorded by the package's class
|
# but are not necessarily recorded by the package's class
|
||||||
not_existing = set(spec.variants) - (
|
not_existing = set(spec.variants) - (
|
||||||
set(pkg_variants) | set(spack.directives.reserved_names))
|
set(pkg_variants) | set(spack.directives.reserved_names)
|
||||||
|
)
|
||||||
if not_existing:
|
if not_existing:
|
||||||
raise vt.UnknownVariantError(spec, not_existing)
|
raise vt.UnknownVariantError(spec, not_existing)
|
||||||
|
|
||||||
vt.substitute_abstract_variants(spec)
|
|
||||||
|
|
||||||
def constrain(self, other, deps=True):
|
def constrain(self, other, deps=True):
|
||||||
"""Merge the constraints of other with self.
|
"""Merge the constraints of other with self.
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ def test_compiler_version_matches_any_entry_in_compilers_yaml(self):
|
|||||||
assert str(s.compiler.version) == '4.5.0'
|
assert str(s.compiler.version) == '4.5.0'
|
||||||
|
|
||||||
def test_concretize_anonymous(self):
|
def test_concretize_anonymous(self):
|
||||||
with pytest.raises(spack.error.SpecError):
|
with pytest.raises(spack.error.SpackError):
|
||||||
s = Spec('+variant')
|
s = Spec('+variant')
|
||||||
s.concretize()
|
s.concretize()
|
||||||
|
|
||||||
@ -657,6 +657,6 @@ def test_concretize_anonymous(self):
|
|||||||
'mpileaks ^%gcc', 'mpileaks ^cflags=-g'
|
'mpileaks ^%gcc', 'mpileaks ^cflags=-g'
|
||||||
])
|
])
|
||||||
def test_concretize_anonymous_dep(self, spec_str):
|
def test_concretize_anonymous_dep(self, spec_str):
|
||||||
with pytest.raises(spack.error.SpecError):
|
with pytest.raises(spack.error.SpackError):
|
||||||
s = Spec(spec_str)
|
s = Spec(spec_str)
|
||||||
s.concretize()
|
s.concretize()
|
||||||
|
Loading…
Reference in New Issue
Block a user