Allow setting variant name in AutotoolsPackage._activate_or_not (#26054)
This commit is contained in:
parent
d20fa421ca
commit
ca8d16c9d1
@ -373,14 +373,15 @@ def _activate_or_not(
|
|||||||
name,
|
name,
|
||||||
activation_word,
|
activation_word,
|
||||||
deactivation_word,
|
deactivation_word,
|
||||||
activation_value=None
|
activation_value=None,
|
||||||
|
variant_name=None
|
||||||
):
|
):
|
||||||
"""This function contains the current implementation details of
|
"""This function contains the current implementation details of
|
||||||
:meth:`~spack.build_systems.autotools.AutotoolsPackage.with_or_without` and
|
:meth:`~spack.build_systems.autotools.AutotoolsPackage.with_or_without` and
|
||||||
:meth:`~spack.build_systems.autotools.AutotoolsPackage.enable_or_disable`.
|
:meth:`~spack.build_systems.autotools.AutotoolsPackage.enable_or_disable`.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): name of the variant that is being processed
|
name (str): name of the option that is being activated or not
|
||||||
activation_word (str): the default activation word ('with' in the
|
activation_word (str): the default activation word ('with' in the
|
||||||
case of ``with_or_without``)
|
case of ``with_or_without``)
|
||||||
deactivation_word (str): the default deactivation word ('without'
|
deactivation_word (str): the default deactivation word ('without'
|
||||||
@ -392,6 +393,8 @@ def _activate_or_not(
|
|||||||
|
|
||||||
The special value 'prefix' can also be assigned and will return
|
The special value 'prefix' can also be assigned and will return
|
||||||
``spec[name].prefix`` as activation parameter.
|
``spec[name].prefix`` as activation parameter.
|
||||||
|
variant_name (str): name of the variant that is being processed
|
||||||
|
(if different from option name)
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
@ -401,6 +404,7 @@ def _activate_or_not(
|
|||||||
|
|
||||||
variant('foo', values=('x', 'y'), description='')
|
variant('foo', values=('x', 'y'), description='')
|
||||||
variant('bar', default=True, description='')
|
variant('bar', default=True, description='')
|
||||||
|
variant('ba_z', default=True, description='')
|
||||||
|
|
||||||
calling this function like:
|
calling this function like:
|
||||||
|
|
||||||
@ -410,12 +414,13 @@ def _activate_or_not(
|
|||||||
'foo', 'with', 'without', activation_value='prefix'
|
'foo', 'with', 'without', activation_value='prefix'
|
||||||
)
|
)
|
||||||
_activate_or_not('bar', 'with', 'without')
|
_activate_or_not('bar', 'with', 'without')
|
||||||
|
_activate_or_not('ba-z', 'with', 'without', variant_name='ba_z')
|
||||||
|
|
||||||
will generate the following configuration options:
|
will generate the following configuration options:
|
||||||
|
|
||||||
.. code-block:: console
|
.. code-block:: console
|
||||||
|
|
||||||
--with-x=<prefix-to-x> --without-y --with-bar
|
--with-x=<prefix-to-x> --without-y --with-bar --with-ba-z
|
||||||
|
|
||||||
for ``<spec-name> foo=x +bar``
|
for ``<spec-name> foo=x +bar``
|
||||||
|
|
||||||
@ -432,32 +437,37 @@ def _activate_or_not(
|
|||||||
if activation_value == 'prefix':
|
if activation_value == 'prefix':
|
||||||
activation_value = lambda x: spec[x].prefix
|
activation_value = lambda x: spec[x].prefix
|
||||||
|
|
||||||
|
if variant_name is None:
|
||||||
|
variant_name = name
|
||||||
|
|
||||||
# Defensively look that the name passed as argument is among
|
# Defensively look that the name passed as argument is among
|
||||||
# variants
|
# variants
|
||||||
if name not in self.variants:
|
if variant_name not in self.variants:
|
||||||
msg = '"{0}" is not a variant of "{1}"'
|
msg = '"{0}" is not a variant of "{1}"'
|
||||||
raise KeyError(msg.format(name, self.name))
|
raise KeyError(msg.format(variant_name, self.name))
|
||||||
|
|
||||||
# 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
|
||||||
if set(self.variants[name].values) == set((True, False)):
|
if set(self.variants[variant_name].values) == set((True, False)):
|
||||||
# BoolValuedVariant carry information about a single option.
|
# BoolValuedVariant carry information about a single option.
|
||||||
# Nonetheless, for uniformity of treatment we'll package them
|
# Nonetheless, for uniformity of treatment we'll package them
|
||||||
# in an iterable of one element.
|
# in an iterable of one element.
|
||||||
condition = '+{name}'.format(name=name)
|
condition = '+{name}'.format(name=variant_name)
|
||||||
options = [(name, condition in spec)]
|
options = [(name, condition in spec)]
|
||||||
else:
|
else:
|
||||||
condition = '{name}={value}'
|
condition = '{variant_name}={value}'
|
||||||
# "feature_values" is used to track values which correspond to
|
# "feature_values" is used to track values which correspond to
|
||||||
# features which can be enabled or disabled as understood by the
|
# features which can be enabled or disabled as understood by the
|
||||||
# package's build system. It excludes values which have special
|
# package's build system. It excludes values which have special
|
||||||
# meanings and do not correspond to features (e.g. "none")
|
# meanings and do not correspond to features (e.g. "none")
|
||||||
feature_values = getattr(
|
feature_values = getattr(
|
||||||
self.variants[name].values, 'feature_values', None
|
self.variants[variant_name].values, 'feature_values', None
|
||||||
) or self.variants[name].values
|
) or self.variants[variant_name].values
|
||||||
|
|
||||||
options = [
|
options = [
|
||||||
(value, condition.format(name=name, value=value) in spec)
|
(value,
|
||||||
|
condition.format(variant_name=variant_name,
|
||||||
|
value=value) in spec)
|
||||||
for value in feature_values
|
for value in feature_values
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -485,7 +495,7 @@ def _default_generator(is_activated):
|
|||||||
args.append(line_generator(activated))
|
args.append(line_generator(activated))
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def with_or_without(self, name, activation_value=None):
|
def with_or_without(self, name, activation_value=None, variant_name=None):
|
||||||
"""Inspects a variant and returns the arguments that activate
|
"""Inspects a variant and returns the arguments that activate
|
||||||
or deactivate the selected feature(s) for the configure options.
|
or deactivate the selected feature(s) for the configure options.
|
||||||
|
|
||||||
@ -511,9 +521,10 @@ def with_or_without(self, name, activation_value=None):
|
|||||||
Returns:
|
Returns:
|
||||||
list of arguments to configure
|
list of arguments to configure
|
||||||
"""
|
"""
|
||||||
return self._activate_or_not(name, 'with', 'without', activation_value)
|
return self._activate_or_not(name, 'with', 'without', activation_value,
|
||||||
|
variant_name)
|
||||||
|
|
||||||
def enable_or_disable(self, name, activation_value=None):
|
def enable_or_disable(self, name, activation_value=None, variant_name=None):
|
||||||
"""Same as
|
"""Same as
|
||||||
:meth:`~spack.build_systems.autotools.AutotoolsPackage.with_or_without`
|
:meth:`~spack.build_systems.autotools.AutotoolsPackage.with_or_without`
|
||||||
but substitute ``with`` with ``enable`` and ``without`` with ``disable``.
|
but substitute ``with`` with ``enable`` and ``without`` with ``disable``.
|
||||||
@ -531,7 +542,7 @@ def enable_or_disable(self, name, activation_value=None):
|
|||||||
list of arguments to configure
|
list of arguments to configure
|
||||||
"""
|
"""
|
||||||
return self._activate_or_not(
|
return self._activate_or_not(
|
||||||
name, 'enable', 'disable', activation_value
|
name, 'enable', 'disable', activation_value, variant_name
|
||||||
)
|
)
|
||||||
|
|
||||||
run_after('install')(PackageBase._run_default_install_time_test_callbacks)
|
run_after('install')(PackageBase._run_default_install_time_test_callbacks)
|
||||||
|
@ -169,6 +169,9 @@ def activate(value):
|
|||||||
options = pkg.with_or_without('bvv')
|
options = pkg.with_or_without('bvv')
|
||||||
assert '--with-bvv' in options
|
assert '--with-bvv' in options
|
||||||
|
|
||||||
|
options = pkg.with_or_without('lorem-ipsum', variant_name='lorem_ipsum')
|
||||||
|
assert '--without-lorem-ipsum' in options
|
||||||
|
|
||||||
def test_none_is_allowed(self):
|
def test_none_is_allowed(self):
|
||||||
s = Spec('a foo=none')
|
s = Spec('a foo=none')
|
||||||
s.concretize()
|
s.concretize()
|
||||||
|
@ -28,6 +28,8 @@ class A(AutotoolsPackage):
|
|||||||
multi=False
|
multi=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
variant('lorem_ipsum', description='', default=False)
|
||||||
|
|
||||||
variant('bvv', default=True, description='The good old BV variant')
|
variant('bvv', default=True, description='The good old BV variant')
|
||||||
|
|
||||||
depends_on('b', when='foobar=bar')
|
depends_on('b', when='foobar=bar')
|
||||||
|
Loading…
Reference in New Issue
Block a user