From 51af590e64f6045fb8e72195d4adcd8d50c984bb Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 7 Oct 2019 08:33:54 -0700 Subject: [PATCH] variants: allow MultiValuedVariants to be constructed incrementally --- lib/spack/spack/solver/asp.py | 18 +++++++++++++----- lib/spack/spack/variant.py | 5 +++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index fe72b777d6..74bdeb69a3 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -198,6 +198,11 @@ def spec_versions(self, spec): v for v in self.possible_versions[spec.name] if v.satisfies(spec.versions) ] + + # don't bother restricting anything if all versions are allowed + if len(allowed_versions) == len(self.possible_versions[spec.name]): + return [] + predicates = [fn.version(spec.name, v) for v in allowed_versions] # conflict with any versions that do not satisfy the spec @@ -288,9 +293,6 @@ def spec_clauses(self, spec): """ clauses = [] - if spec.name: - clauses.append(fn.node(spec.name)) - clauses.extend(self.spec_versions(spec)) # seed architecture at the root (we'll propagate later) @@ -428,8 +430,14 @@ def arch_target(self, pkg, target): def variant_value(self, pkg, name, value): pkg_class = spack.repo.path.get_pkg_class(pkg) - variant = pkg_class.variants[name].make_variant(value) - self._specs[pkg].variants[name] = variant + + variant = self._specs[pkg].variants.get(name) + if variant: + # it's multi-valued + variant.append(value) + else: + variant = pkg_class.variants[name].make_variant(value) + self._specs[pkg].variants[name] = variant def version(self, pkg, version): self._specs[pkg].versions = ver([version]) diff --git a/lib/spack/spack/variant.py b/lib/spack/spack/variant.py index 280f2346dd..e50c34a07d 100644 --- a/lib/spack/spack/variant.py +++ b/lib/spack/spack/variant.py @@ -389,6 +389,11 @@ def satisfies(self, other): return super_sat and (all(v in self.value for v in other.value) or '*' in other or '*' in self) + def append(self, value): + """Add another value to this multi-valued variant.""" + self._value = tuple(sorted((value,) + self._value)) + self._original_value = ",".join(self._value) + class SingleValuedVariant(AbstractVariant): """A variant that can hold multiple values, but one at a time."""