Make _enable_or_disable(...) return an empty array for conditional variants whose condition is not met (#27504)
This commit is contained in:
parent
cda9d6d981
commit
0024e5cc9b
@ -420,6 +420,24 @@ Or when one variant controls multiple flags:
|
|||||||
config_args += self.with_or_without('memchecker', variant='debug_tools')
|
config_args += self.with_or_without('memchecker', variant='debug_tools')
|
||||||
config_args += self.with_or_without('profiler', variant='debug_tools')
|
config_args += self.with_or_without('profiler', variant='debug_tools')
|
||||||
|
|
||||||
|
|
||||||
|
""""""""""""""""""""
|
||||||
|
Conditional variants
|
||||||
|
""""""""""""""""""""
|
||||||
|
|
||||||
|
When a variant is conditional and its condition is not met on the concrete spec, the
|
||||||
|
``with_or_without`` and ``enable_or_disable`` methods will simply return an empty list.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
variant('profiler', when='@2.0:')
|
||||||
|
config_args += self.with_or_without('profiler)
|
||||||
|
|
||||||
|
will neither add ``--with-profiler`` nor ``--without-profiler`` when the version is
|
||||||
|
below ``2.0``.
|
||||||
|
|
||||||
""""""""""""""""""""
|
""""""""""""""""""""
|
||||||
Activation overrides
|
Activation overrides
|
||||||
""""""""""""""""""""
|
""""""""""""""""""""
|
||||||
|
@ -498,6 +498,9 @@ def _activate_or_not(
|
|||||||
|
|
||||||
for ``<spec-name> foo=x +bar``
|
for ``<spec-name> foo=x +bar``
|
||||||
|
|
||||||
|
Note: returns an empty list when the variant is conditional and its condition
|
||||||
|
is not met.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: list of strings that corresponds to the activation/deactivation
|
list: list of strings that corresponds to the activation/deactivation
|
||||||
of the variant that has been processed
|
of the variant that has been processed
|
||||||
@ -519,6 +522,9 @@ def _activate_or_not(
|
|||||||
msg = '"{0}" is not a variant of "{1}"'
|
msg = '"{0}" is not a variant of "{1}"'
|
||||||
raise KeyError(msg.format(variant, self.name))
|
raise KeyError(msg.format(variant, self.name))
|
||||||
|
|
||||||
|
if variant not in spec.variants:
|
||||||
|
return []
|
||||||
|
|
||||||
# Create a list of pairs. Each pair includes a configuration
|
# Create a list of pairs. Each pair includes a configuration
|
||||||
# option and whether or not that option is activated
|
# option and whether or not that option is activated
|
||||||
variant_desc, _ = self.variants[variant]
|
variant_desc, _ = self.variants[variant]
|
||||||
|
@ -437,3 +437,11 @@ def test_cmake_define_from_variant_conditional(config, mock_packages):
|
|||||||
s = Spec('cmake-conditional-variants-test').concretized()
|
s = Spec('cmake-conditional-variants-test').concretized()
|
||||||
assert 'example' not in s.variants
|
assert 'example' not in s.variants
|
||||||
assert s.package.define_from_variant('EXAMPLE', 'example') == ''
|
assert s.package.define_from_variant('EXAMPLE', 'example') == ''
|
||||||
|
|
||||||
|
|
||||||
|
def test_autotools_args_from_conditional_variant(config, mock_packages):
|
||||||
|
"""Test that _activate_or_not returns an empty string when a condition on a variant
|
||||||
|
is not met. When this is the case, the variant is not set in the spec."""
|
||||||
|
s = Spec('autotools-conditional-variants-test').concretized()
|
||||||
|
assert 'example' not in s.variants
|
||||||
|
assert len(s.package._activate_or_not('example', 'enable', 'disable')) == 0
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
# 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 AutotoolsConditionalVariantsTest(AutotoolsPackage):
|
||||||
|
homepage = "https://www.example.com"
|
||||||
|
has_code = False
|
||||||
|
version('1.0')
|
||||||
|
variant('example', default=True, description='nope', when='@2.0:')
|
Loading…
Reference in New Issue
Block a user