summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2020-01-30 12:34:54 -0800
committerGitHub <noreply@github.com>2020-01-30 12:34:54 -0800
commit7b2895109cac96174949b51ba19c5fc9aa011ad7 (patch)
tree4a636503458add81e606cf88ea5f9e4fe3d97609
parentb2adcdb389ed684fd4dbb15e44da163c816548a7 (diff)
downloadspack-7b2895109cac96174949b51ba19c5fc9aa011ad7.tar.gz
spack-7b2895109cac96174949b51ba19c5fc9aa011ad7.tar.bz2
spack-7b2895109cac96174949b51ba19c5fc9aa011ad7.tar.xz
spack-7b2895109cac96174949b51ba19c5fc9aa011ad7.zip
Document how to add conditional dependencies (#14694)
* add short docs section on conditional dependencies * add reference to spec syntax * add note that conditional dependencies can save time
-rw-r--r--lib/spack/docs/packaging_guide.rst22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/spack/docs/packaging_guide.rst b/lib/spack/docs/packaging_guide.rst
index 223c509ac1..e566cb4545 100644
--- a/lib/spack/docs/packaging_guide.rst
+++ b/lib/spack/docs/packaging_guide.rst
@@ -1989,6 +1989,28 @@ inject the dependency's ``prefix/lib`` directory, but the package needs to
be in ``PATH`` and ``PYTHONPATH`` during the build process and later when
a user wants to run the package.
+^^^^^^^^^^^^^^^^^^^^^^^^
+Conditional dependencies
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+You may have a package that only requires a dependency under certain
+conditions. For example, you may have a package that has optional MPI support,
+- MPI is only a dependency when you want to enable MPI support for the
+package. In that case, you could say something like:
+
+.. code-block:: python
+
+ variant('mpi', default=False)
+ depends_on('mpi', when='+mpi')
+
+``when`` can include constraints on the variant, version, compiler, etc. and
+the :mod:`syntax<spack.spec>` is the same as for Specs written on the command
+line.
+
+If a dependency/feature of a package isn't typically used, you can save time
+by making it conditional (since Spack will not build the dependency unless it
+is required for the Spec).
+
.. _dependency_dependency_patching:
^^^^^^^^^^^^^^^^^^^