summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2021-11-22 10:47:09 +0100
committerGitHub <noreply@github.com>2021-11-22 10:47:09 +0100
commit0024e5cc9b5fe2f803d314e80ed14ade22d3bb55 (patch)
treea8deb401b264228c41a3e817384058ba112ed087 /lib
parentcda9d6d98133e6a2eae89d91b0cabce1ce36d48a (diff)
downloadspack-0024e5cc9b5fe2f803d314e80ed14ade22d3bb55.tar.gz
spack-0024e5cc9b5fe2f803d314e80ed14ade22d3bb55.tar.bz2
spack-0024e5cc9b5fe2f803d314e80ed14ade22d3bb55.tar.xz
spack-0024e5cc9b5fe2f803d314e80ed14ade22d3bb55.zip
Make _enable_or_disable(...) return an empty array for conditional variants whose condition is not met (#27504)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/docs/build_systems/autotoolspackage.rst18
-rw-r--r--lib/spack/spack/build_systems/autotools.py6
-rw-r--r--lib/spack/spack/test/build_systems.py8
3 files changed, 32 insertions, 0 deletions
diff --git a/lib/spack/docs/build_systems/autotoolspackage.rst b/lib/spack/docs/build_systems/autotoolspackage.rst
index 71d8d7d866..d62fb08ce8 100644
--- a/lib/spack/docs/build_systems/autotoolspackage.rst
+++ b/lib/spack/docs/build_systems/autotoolspackage.rst
@@ -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('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
""""""""""""""""""""
diff --git a/lib/spack/spack/build_systems/autotools.py b/lib/spack/spack/build_systems/autotools.py
index e0c8cf2e03..9b2de555bc 100644
--- a/lib/spack/spack/build_systems/autotools.py
+++ b/lib/spack/spack/build_systems/autotools.py
@@ -498,6 +498,9 @@ To resolve this problem, please try the following:
for ``<spec-name> foo=x +bar``
+ Note: returns an empty list when the variant is conditional and its condition
+ is not met.
+
Returns:
list: list of strings that corresponds to the activation/deactivation
of the variant that has been processed
@@ -519,6 +522,9 @@ To resolve this problem, please try the following:
msg = '"{0}" is not a variant of "{1}"'
raise KeyError(msg.format(variant, self.name))
+ if variant not in spec.variants:
+ return []
+
# Create a list of pairs. Each pair includes a configuration
# option and whether or not that option is activated
variant_desc, _ = self.variants[variant]
diff --git a/lib/spack/spack/test/build_systems.py b/lib/spack/spack/test/build_systems.py
index 1a46a83d45..fec337eb8f 100644
--- a/lib/spack/spack/test/build_systems.py
+++ b/lib/spack/spack/test/build_systems.py
@@ -437,3 +437,11 @@ def test_cmake_define_from_variant_conditional(config, mock_packages):
s = Spec('cmake-conditional-variants-test').concretized()
assert 'example' not in s.variants
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