diff options
-rw-r--r-- | lib/spack/spack/concretize.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/config.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/preferred_packages.py | 7 |
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/spack/spack/concretize.py b/lib/spack/spack/concretize.py index 386df08b2e..622a7efde5 100644 --- a/lib/spack/spack/concretize.py +++ b/lib/spack/spack/concretize.py @@ -254,13 +254,18 @@ class DefaultConcretizer(object): def concretize_variants(self, spec): """If the spec already has variants filled in, return. Otherwise, add - the default variants from the package specification. + the user preferences from packages.yaml or the default variants from + the package specification. """ changed = False + preferred_variants = spack.pkgsort.spec_preferred_variants(spec.package_class.name) for name, variant in spec.package_class.variants.items(): if name not in spec.variants: - spec.variants[name] = spack.spec.VariantSpec(name, variant.default) changed = True + if name in preferred_variants: + spec.variants[name] = preferred_variants.get(name) + else: + spec.variants[name] = spack.spec.VariantSpec(name, variant.default) return changed diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index 8b5e96f97d..e2e7dbc0ee 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -257,7 +257,13 @@ section_schemas = { 'paths': { 'type' : 'object', 'default' : {}, - } + }, + 'variants': { + 'oneOf' : [ + { 'type' : 'string' }, + { 'type' : 'array', + 'items' : { 'type' : 'string' } }, + ], }, },},},},},}, 'modules': { diff --git a/lib/spack/spack/preferred_packages.py b/lib/spack/spack/preferred_packages.py index 1b94f03de7..5f18e212b6 100644 --- a/lib/spack/spack/preferred_packages.py +++ b/lib/spack/spack/preferred_packages.py @@ -158,6 +158,13 @@ class PreferredPackages(object): return bool(self._order_for_package(pkgname, 'providers', provider_str, False)) + def spec_preferred_variants(self, pkgname): + """Return a VariantMap of preferred variants and their values""" + variants = self.preferred.get(pkgname, {}).get('variants', '') + if not isinstance(variants, basestring): + variants = "".join(variants) + return spack.spec.Spec(pkgname + variants).variants + def version_compare(self, pkgname, a, b): """Return less-than-0, 0, or greater than 0 if version a of pkgname is respectively less-than, equal-to, or greater-than version b of |