Allow conditional variants (#24858)

A common question from users has been how to model variants 
that are new in new versions of a package, or variants that are 
dependent on other variants. Our stock answer so far has been
an unsatisfying combination of "just have it do nothing in the old
version" and "tell Spack it conflicts".

This PR enables conditional variants, on any spec condition. The 
syntax is straightforward, and matches that of previous features.
This commit is contained in:
Greg Becker
2021-11-03 00:11:31 -07:00
committed by GitHub
parent 78c08fccd5
commit 67cd92e6a3
13 changed files with 217 additions and 32 deletions

View File

@@ -0,0 +1,24 @@
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
class ConditionalVariantPkg(Package):
"""This package is used to test conditional variants."""
homepage = "http://www.example.com/conditional-variant-pkg"
url = "http://www.unit-test-should-replace-this-url/conditional-variant-1.0.tar.gz"
version('1.0', '0123456789abcdef0123456789abcdef')
version('2.0', 'abcdef0123456789abcdef0123456789')
variant('version_based', default=True, when='@2.0:',
description="Check that version constraints work")
variant('variant_based', default=False, when='+version_based',
description="Check that variants can depend on variants")
variant('two_whens', default=False, when='@1.0')
variant('two_whens', default=False, when='+variant_based')
def install(self, spec, prefix):
assert False