2025-01-02 22:40:28 +08:00
.. Copyright Spack Project Developers. See COPYRIGHT file for details.
2018-10-08 04:52:23 +08:00
SPDX-License-Identifier: (Apache-2.0 OR MIT)
2014-01-13 01:22:19 +08:00
.. _basic-usage:
2013-12-26 07:30:42 +08:00
2016-08-24 06:03:29 +08:00
===========
2016-10-06 17:49:44 +08:00
Basic Usage
2016-08-24 06:03:29 +08:00
===========
2016-07-15 00:40:47 +08:00
2015-04-15 06:11:01 +08:00
The `` spack `` command has many *subcommands* . You'll only need a
small subset of them for typical usage.
2013-12-12 20:25:31 +08:00
2016-03-28 03:22:52 +08:00
Note that Spack colorizes output. `` less -R `` should be used with
2016-08-27 05:41:00 +08:00
Spack to maintain this colorization. E.g.:
2016-03-28 03:22:52 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2016-03-28 03:22:52 +08:00
2016-08-27 05:41:00 +08:00
$ spack find | less -R
2016-03-28 03:22:52 +08:00
2016-10-06 17:49:44 +08:00
It is recommended that the following be put in your `` .bashrc `` file:
2016-03-28 03:22:52 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: sh
alias less='less -R'
2013-12-12 20:25:31 +08:00
2020-02-26 17:03:03 +08:00
If you do not see colorized output when using `` less -R `` it is because color
is being disabled in the piped output. In this case, tell spack to force
2021-04-28 21:03:25 +08:00
colorized output with a flag
2020-02-26 17:03:03 +08:00
.. code-block :: console
2021-10-13 01:23:53 +08:00
$ spack --color always find | less -R
2020-02-26 17:03:03 +08:00
2021-04-28 21:03:25 +08:00
or an environment variable
.. code-block :: console
2021-10-13 01:23:53 +08:00
$ SPACK_COLOR=always spack find | less -R
2021-04-28 21:03:25 +08:00
2016-08-24 06:03:29 +08:00
--------------------------
2013-12-21 08:10:19 +08:00
Listing available packages
2016-08-24 06:03:29 +08:00
--------------------------
2013-12-12 20:25:31 +08:00
2015-04-15 06:11:01 +08:00
To install software with Spack, you need to know what software is
available. You can see a list of available package names at the
2023-10-01 11:36:22 +08:00
`packages.spack.io <https://packages.spack.io> `_ website, or
using the `` spack list `` command.
2013-12-12 20:25:31 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-list:
2015-02-24 18:33:29 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2013-12-12 20:25:31 +08:00
`` spack list ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2013-12-12 20:25:31 +08:00
2019-05-24 01:44:14 +08:00
The `` spack list `` command prints out a list of all of the packages Spack
can install:
2013-12-12 20:25:31 +08:00
.. command-output :: spack list
2019-05-24 01:44:14 +08:00
:ellipsis: 10
2013-12-12 20:25:31 +08:00
2020-02-26 17:03:03 +08:00
There are thousands of them, so we've truncated the output above, but you
2023-10-01 11:36:22 +08:00
can find a `full list here <https://packages.spack.io> `_ .
2019-05-24 01:44:14 +08:00
Packages are listed by name in alphabetical order.
2016-10-13 00:43:28 +08:00
A pattern to match with no wildcards, `` * `` or `` ? `` ,
will be treated as though it started and ended with
`` * `` , so `` util `` is equivalent to `` *util* `` . All patterns will be treated
as case-insensitive. You can also add the `` -d `` to search the description of
2016-06-21 02:33:56 +08:00
the package in addition to the name. Some examples:
2014-10-28 13:40:04 +08:00
2016-10-13 00:43:28 +08:00
All packages whose names contain "sql":
2014-10-28 13:40:04 +08:00
2016-06-21 02:33:56 +08:00
.. command-output :: spack list sql
2016-10-13 00:43:28 +08:00
All packages whose names or descriptions contain documentation:
2016-06-21 02:33:56 +08:00
2016-10-06 17:49:44 +08:00
.. command-output :: spack list --search-description documentation
2013-12-12 20:25:31 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-info:
2013-12-12 20:25:31 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2013-12-12 20:25:31 +08:00
`` spack info ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2013-12-12 20:25:31 +08:00
2015-02-23 17:22:49 +08:00
To get more information on a particular package from `spack list` , use
`spack info` . Just supply the name of a package:
2013-12-12 20:25:31 +08:00
2022-10-19 03:11:21 +08:00
.. command-output :: spack info --all mpich
2013-12-12 20:25:31 +08:00
2015-04-15 06:11:01 +08:00
Most of the information is self-explanatory. The *safe versions* are
versions that Spack knows the checksum for, and it will use the
checksum to verify that these versions download without errors or
viruses.
:ref: `Dependencies <sec-specs>` and :ref:`virtual dependencies
<sec-virtual-dependencies> ` are described in more detail later.
2013-12-19 03:02:31 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-versions:
2015-02-24 18:33:29 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
`` spack versions ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
2015-04-15 06:11:01 +08:00
To see *more* available versions of a package, run `` spack versions `` .
For example:
2013-12-19 03:02:31 +08:00
.. command-output :: spack versions libelf
2015-04-15 06:11:01 +08:00
There are two sections in the output. *Safe versions* are versions
for which Spack has a checksum on file. It can verify that these
versions are downloaded correctly.
In many cases, Spack can also show you what versions are available out
on the web---these are *remote versions* . Spack gets this information
by scraping it directly from package web pages. Depending on the
package and how its releases are organized, Spack may or may not be
able to find remote versions.
2015-02-23 17:22:49 +08:00
2016-08-24 06:03:29 +08:00
---------------------------
2015-02-23 17:22:49 +08:00
Installing and uninstalling
2016-08-24 06:03:29 +08:00
---------------------------
2015-02-23 17:22:49 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-install:
2015-02-24 18:33:29 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
`` spack install ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
`` spack install `` will install any package shown by `` spack list `` .
2015-04-15 06:11:01 +08:00
For example, To install the latest version of the `` mpileaks ``
package, you might type this:
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
$ spack install mpileaks
2016-08-27 05:41:00 +08:00
If `` mpileaks `` depends on other packages, Spack will install the
2015-04-15 06:11:01 +08:00
dependencies first. It then fetches the `` mpileaks `` tarball, expands
it, verifies that it was downloaded without errors, builds it, and
installs it in its own directory under `` $SPACK_ROOT/opt `` . You'll see
Support parallel environment builds (#18131)
As of #13100, Spack installs the dependencies of a _single_ spec in parallel.
Environments, when installed, can only get parallelism from each individual
spec, as they're installed in order. This PR makes entire environments build
in parallel by extending Spack's package installer to accept multiple root
specs. The install command and Environment class have been updated to use
the new parallel install method.
The specs and kwargs for each *uninstalled* package (when not force-replacing
installations) of an environment are collected, passed to the `PackageInstaller`,
and processed using a single build queue.
This introduces a `BuildRequest` class to track install arguments, and it
significantly cleans up the code used to track package ids during installation.
Package ids in the build queue are now just DAG hashes as you would expect,
Other tasks:
- [x] Finish updating the unit tests based on `PackageInstaller`'s use of
`BuildRequest` and the associated changes
- [x] Change `environment.py`'s `install_all` to use the `PackageInstaller` directly
- [x] Change the `install` command to leverage the new installation process for multiple specs
- [x] Change install output messages for external packages, e.g.:
`[+] /usr` -> `[+] /usr (external bzip2-1.0.8-<dag-hash>`
- [x] Fix incomplete environment install's view setup/update and not confirming all
packages are installed (?)
- [x] Ensure externally installed package dependencies are properly accounted for in
remaining build tasks
- [x] Add tests for coverage (if insufficient and can identity the appropriate, uncovered non-comment lines)
- [x] Add documentation
- [x] Resolve multi-compiler environment install issues
- [x] Fix issue with environment installation reporting (restore CDash/JUnit reports)
2020-11-17 18:41:07 +08:00
a number of messages from Spack, a lot of build output, and a message
2020-12-17 05:57:08 +08:00
that the package is installed.
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
$ spack install mpileaks
Support parallel environment builds (#18131)
As of #13100, Spack installs the dependencies of a _single_ spec in parallel.
Environments, when installed, can only get parallelism from each individual
spec, as they're installed in order. This PR makes entire environments build
in parallel by extending Spack's package installer to accept multiple root
specs. The install command and Environment class have been updated to use
the new parallel install method.
The specs and kwargs for each *uninstalled* package (when not force-replacing
installations) of an environment are collected, passed to the `PackageInstaller`,
and processed using a single build queue.
This introduces a `BuildRequest` class to track install arguments, and it
significantly cleans up the code used to track package ids during installation.
Package ids in the build queue are now just DAG hashes as you would expect,
Other tasks:
- [x] Finish updating the unit tests based on `PackageInstaller`'s use of
`BuildRequest` and the associated changes
- [x] Change `environment.py`'s `install_all` to use the `PackageInstaller` directly
- [x] Change the `install` command to leverage the new installation process for multiple specs
- [x] Change install output messages for external packages, e.g.:
`[+] /usr` -> `[+] /usr (external bzip2-1.0.8-<dag-hash>`
- [x] Fix incomplete environment install's view setup/update and not confirming all
packages are installed (?)
- [x] Ensure externally installed package dependencies are properly accounted for in
remaining build tasks
- [x] Add tests for coverage (if insufficient and can identity the appropriate, uncovered non-comment lines)
- [x] Add documentation
- [x] Resolve multi-compiler environment install issues
- [x] Fix issue with environment installation reporting (restore CDash/JUnit reports)
2020-11-17 18:41:07 +08:00
... dependency build output ...
==> Installing mpileaks-1.0-ph7pbnhl334wuhogmugriohcwempqry2
==> No binary for mpileaks-1.0-ph7pbnhl334wuhogmugriohcwempqry2 found: installing from source
==> mpileaks: Executing phase: 'autoreconf'
==> mpileaks: Executing phase: 'configure'
==> mpileaks: Executing phase: 'build'
==> mpileaks: Executing phase: 'install'
[+] ~/spack/opt/linux-rhel7-broadwell/gcc-8.1.0/mpileaks-1.0-ph7pbnhl334wuhogmugriohcwempqry2
2015-02-23 17:22:49 +08:00
The last line, with the `` [+] `` , indicates where the package is
installed.
2020-12-17 05:57:08 +08:00
Add the Spack debug option (one or more times) -- `` spack -d install
mpileaks`` -- to get additional (and even more verbose) output.
Support parallel environment builds (#18131)
As of #13100, Spack installs the dependencies of a _single_ spec in parallel.
Environments, when installed, can only get parallelism from each individual
spec, as they're installed in order. This PR makes entire environments build
in parallel by extending Spack's package installer to accept multiple root
specs. The install command and Environment class have been updated to use
the new parallel install method.
The specs and kwargs for each *uninstalled* package (when not force-replacing
installations) of an environment are collected, passed to the `PackageInstaller`,
and processed using a single build queue.
This introduces a `BuildRequest` class to track install arguments, and it
significantly cleans up the code used to track package ids during installation.
Package ids in the build queue are now just DAG hashes as you would expect,
Other tasks:
- [x] Finish updating the unit tests based on `PackageInstaller`'s use of
`BuildRequest` and the associated changes
- [x] Change `environment.py`'s `install_all` to use the `PackageInstaller` directly
- [x] Change the `install` command to leverage the new installation process for multiple specs
- [x] Change install output messages for external packages, e.g.:
`[+] /usr` -> `[+] /usr (external bzip2-1.0.8-<dag-hash>`
- [x] Fix incomplete environment install's view setup/update and not confirming all
packages are installed (?)
- [x] Ensure externally installed package dependencies are properly accounted for in
remaining build tasks
- [x] Add tests for coverage (if insufficient and can identity the appropriate, uncovered non-comment lines)
- [x] Add documentation
- [x] Resolve multi-compiler environment install issues
- [x] Fix issue with environment installation reporting (restore CDash/JUnit reports)
2020-11-17 18:41:07 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
Building a specific version
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
Spack can also build *specific versions* of a package. To do this,
just add `` @ `` after the package name, followed by a version:
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
$ spack install mpich@3.0.4
Any number of versions of the same package can be installed at once
without interfering with each other. This is good for multi-user
sites, as installing a version that one user needs will not disrupt
existing installations for other users.
In addition to different versions, Spack can customize the compiler,
2016-05-26 01:56:12 +08:00
compile-time options (variants), compiler flags, and platform (for
cross compiles) of an installation. Spack is unique in that it can
also configure the *dependencies* a package is built with. For example,
two configurations of the same version of a package, one built with boost
2015-02-23 17:22:49 +08:00
1.39.0, and the other version built with version 1.43.0, can coexist.
2015-04-15 06:11:01 +08:00
This can all be done on the command line using the *spec* syntax.
Spack calls the descriptor used to refer to a particular package
configuration a **spec** . In the commands above, `` mpileaks `` and
2016-08-27 05:41:00 +08:00
`` mpileaks@3.0.4 `` are both valid *specs* . We'll talk more about how
you can use them to customize an installation in :ref: `sec-specs` .
2015-02-23 17:22:49 +08:00
2021-11-05 13:47:20 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Reusing installed dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2022-05-14 00:11:10 +08:00
By default, when you run `` spack install `` , Spack tries hard to reuse existing installations
as dependencies, either from a local store or from remote buildcaches if configured.
This minimizes unwanted rebuilds of common dependencies, in particular if
you update Spack frequently.
2021-11-05 13:47:20 +08:00
2022-05-14 00:11:10 +08:00
In case you want the latest versions and configurations to be installed instead,
you can add the `` --fresh `` option:
2021-11-05 13:47:20 +08:00
.. code-block :: console
2022-05-14 00:11:10 +08:00
$ spack install --fresh mpich
Reusing installations in this mode is "accidental", and happening only if
there's a match between existing installations and what Spack would have installed
anyhow.
2021-11-05 13:47:20 +08:00
2022-05-14 00:11:10 +08:00
You can use the `` spack spec -I mpich `` command to see what
2021-11-05 13:47:20 +08:00
will be reused and what will be built before you install.
2022-05-14 00:11:10 +08:00
You can configure Spack to use the `` --fresh `` behavior by default in
`` concretizer.yaml `` :
.. code-block :: yaml
concretizer:
reuse: false
2022-02-13 17:26:53 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-uninstall:
2015-02-23 17:22:49 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
`` spack uninstall ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
To uninstall a package, type `` spack uninstall <package> `` . This will ask
2016-10-06 17:49:44 +08:00
the user for confirmation before completely removing the directory
2016-08-27 05:41:00 +08:00
in which the package was installed.
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
$ spack uninstall mpich
2015-02-23 17:22:49 +08:00
If there are still installed packages that depend on the package to be
2016-04-04 16:59:01 +08:00
uninstalled, spack will refuse to uninstall it.
2015-02-23 17:22:49 +08:00
2016-04-04 16:59:01 +08:00
To uninstall a package and every package that depends on it, you may give the
2016-08-27 05:41:00 +08:00
`` --dependents `` option.
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
$ spack uninstall --dependents mpich
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
will display a list of all the packages that depend on `` mpich `` and, upon
confirmation, will uninstall them in the right order.
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
A command like
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
$ spack uninstall mpich
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
may be ambiguous if multiple `` mpich `` configurations are installed.
For example, if both `` mpich@3.0.2 `` and `` mpich@3.1 `` are installed,
`` mpich `` could refer to either one. Because it cannot determine which
one to uninstall, Spack will ask you either to provide a version number
to remove the ambiguity or use the `` --all `` option to uninstall all of
the matching packages.
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
You may force uninstall a package with the `` --force `` option
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
$ spack uninstall --force mpich
2016-04-04 16:59:01 +08:00
2016-08-27 05:41:00 +08:00
but you risk breaking other installed packages. In general, it is safer to
remove dependent packages *before* removing their dependencies or use the
`` --dependents `` option.
2015-02-23 17:22:49 +08:00
2016-10-06 04:00:27 +08:00
.. _nondownloadable:
2020-01-08 00:16:54 +08:00
^^^^^^^^^^^^^^^^^^
Garbage collection
^^^^^^^^^^^^^^^^^^
When Spack builds software from sources, if often installs tools that are needed
just to build or test other software. These are not necessary at runtime.
To support cases where removing these tools can be a benefit Spack provides
the `` spack gc `` ("garbage collector") command, which will uninstall all unneeded packages:
.. code-block :: console
$ spack find
==> 24 installed packages
-- linux-ubuntu18.04-broadwell / gcc@9.0.1 ----------------------
autoconf@2.69 findutils@4.6.0 libiconv@1.16 libszip@2.1.1 m4@1.4.18 openjpeg@2.3.1 pkgconf@1.6.3 util-macros@1.19.1
automake@1.16.1 gdbm@1.18.1 libpciaccess@0.13.5 libtool@2.4.6 mpich@3.3.2 openssl@1.1.1d readline@8.0 xz@5.2.4
cmake@3.16.1 hdf5@1.10.5 libsigsegv@2.12 libxml2@2.9.9 ncurses@6.1 perl@5.30.0 texinfo@6.5 zlib@1.2.11
$ spack gc
==> The following packages will be uninstalled:
-- linux-ubuntu18.04-broadwell / gcc@9.0.1 ----------------------
vn47edz autoconf@2.69 6m3f2qn findutils@4.6.0 ubl6bgk libtool@2.4.6 pksawhz openssl@1.1.1d urdw22a readline@8.0
ki6nfw5 automake@1.16.1 fklde6b gdbm@1.18.1 b6pswuo m4@1.4.18 k3s2csy perl@5.30.0 lp5ya3t texinfo@6.5
ylvgsov cmake@3.16.1 5omotir libsigsegv@2.12 leuzbbh ncurses@6.1 5vmfbrq pkgconf@1.6.3 5bmv4tg util-macros@1.19.1
==> Do you want to proceed? [y/N] y
[ ... ]
$ spack find
==> 9 installed packages
-- linux-ubuntu18.04-broadwell / gcc@9.0.1 ----------------------
hdf5@1.10.5 libiconv@1.16 libpciaccess@0.13.5 libszip@2.1.1 libxml2@2.9.9 mpich@3.3.2 openjpeg@2.3.1 xz@5.2.4 zlib@1.2.11
2020-02-26 17:03:03 +08:00
In the example above Spack went through all the packages in the package database
2020-01-08 00:16:54 +08:00
and removed everything that is not either:
1. A package installed upon explicit request of the user
2. A `` link `` or `` run `` dependency, even transitive, of one of the packages at point 1.
You can check :ref: `cmd-spack-find-metadata` to see how to query for explicitly installed packages
or :ref: `dependency-types` for a more thorough treatment of dependency types.
2020-11-18 19:20:56 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Marking packages explicit or implicit
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
By default, Spack will mark packages a user installs as explicitly installed,
while all of its dependencies will be marked as implicitly installed. Packages
can be marked manually as explicitly or implicitly installed by using
`` spack mark `` . This can be used in combination with `` spack gc `` to clean up
packages that are no longer required.
.. code-block :: console
$ spack install m4
==> 29005: Installing libsigsegv
[...]
==> 29005: Installing m4
[...]
$ spack install m4 ^libsigsegv@2.11
==> 39798: Installing libsigsegv
[...]
==> 39798: Installing m4
[...]
$ spack find -d
==> 4 installed packages
-- linux-fedora32-haswell / gcc@10.1.1 --------------------------
libsigsegv@2.11
libsigsegv@2.12
m4@1.4.18
libsigsegv@2.12
m4@1.4.18
libsigsegv@2.11
$ spack gc
==> There are no unused specs. Spack's store is clean.
$ spack mark -i m4 ^libsigsegv@2.11
==> m4@1.4.18 : marking the package implicit
$ spack gc
==> The following packages will be uninstalled:
-- linux-fedora32-haswell / gcc@10.1.1 --------------------------
5fj7p2o libsigsegv@2.11 c6ensc6 m4@1.4.18
==> Do you want to proceed? [y/N]
In the example above, we ended up with two versions of `` m4 `` since they depend
on different versions of `` libsigsegv `` . `` spack gc `` will not remove any of
the packages since both versions of `` m4 `` have been installed explicitly
and both versions of `` libsigsegv `` are required by the `` m4 `` packages.
`` spack mark `` can also be used to implement upgrade workflows. The following
example demonstrates how the `` spack mark `` and `` spack gc `` can be used to
only keep the current version of a package installed.
When updating Spack via `` git pull `` , new versions for either `` libsigsegv ``
or `` m4 `` might be introduced. This will cause Spack to install duplicates.
Since we only want to keep one version, we mark everything as implicitly
installed before updating Spack. If there is no new version for either of the
packages, `` spack install `` will simply mark them as explicitly installed and
`` spack gc `` will not remove them.
.. code-block :: console
$ spack install m4
==> 62843: Installing libsigsegv
[...]
==> 62843: Installing m4
[...]
$ spack mark -i -a
==> m4@1.4.18 : marking the package implicit
$ git pull
[...]
$ spack install m4
[...]
==> m4@1.4.18 : marking the package explicit
[...]
$ spack gc
==> There are no unused specs. Spack's store is clean.
When using this workflow for installations that contain more packages, care
has to be taken to either only mark selected packages or issue `` spack install ``
for all packages that should be kept.
You can check :ref: `cmd-spack-find-metadata` to see how to query for explicitly
or implicitly installed packages.
2016-10-06 04:00:27 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^
Non-Downloadable Tarballs
^^^^^^^^^^^^^^^^^^^^^^^^^
The tarballs for some packages cannot be automatically downloaded by
Spack. This could be for a number of reasons:
#. The author requires users to manually accept a license agreement
before downloading (`` jdk `` and `` galahad `` ).
#. The software is proprietary and cannot be downloaded on the open
Internet.
To install these packages, one must create a mirror and manually add
the tarballs in question to it (see :ref: `mirrors` ):
#. Create a directory for the mirror. You can create this directory
anywhere you like, it does not have to be inside `` ~/.spack `` :
.. code-block :: console
$ mkdir ~/.spack/manual_mirror
#. Register the mirror with Spack by creating `` ~/.spack/mirrors.yaml `` :
.. code-block :: yaml
mirrors:
2016-12-26 04:36:35 +08:00
manual: file://~/.spack/manual_mirror
2016-10-06 04:00:27 +08:00
#. Put your tarballs in it. Tarballs should be named
`` <package>/<package>-<version>.tar.gz `` . For example:
.. code-block :: console
$ ls -l manual_mirror/galahad
-rw-------. 1 me me 11657206 Jun 21 19:25 galahad-2.60003.tar.gz
#. Install as usual:
.. code-block :: console
$ spack install galahad
2019-10-16 05:24:52 +08:00
2016-08-24 06:03:29 +08:00
-------------------------
2015-02-23 17:22:49 +08:00
Seeing installed packages
2016-08-24 06:03:29 +08:00
-------------------------
2015-02-23 17:22:49 +08:00
We know that `` spack list `` shows you the names of available packages,
2016-08-27 05:41:00 +08:00
but how do you figure out which are already installed?
2015-02-23 17:22:49 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-find:
2015-02-23 17:22:49 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
`` spack find ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2015-02-23 17:22:49 +08:00
`` spack find `` shows the *specs* of installed packages. A spec is
like a name, but it has a version, compiler, architecture, and build
options associated with it. In spack, you can have many installations
of the same package with different specs.
Running `` spack find `` with no arguments lists installed packages:
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
$ spack find
==> 74 installed packages.
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.4.7 --------------------------------
2015-02-23 17:22:49 +08:00
ImageMagick@6.8.9-10 libdwarf@20130729 py-dateutil@2.4.0
adept-utils@1.0 libdwarf@20130729 py-ipython@2.3.1
atk@2.14.0 libelf@0.8.12 py-matplotlib@1.4.2
boost@1.55.0 libelf@0.8.13 py-nose@1.3.4
bzip2@1.0.6 libffi@3.1 py-numpy@1.9.1
cairo@1.14.0 libmng@2.0.2 py-pygments@2.0.1
callpath@1.0.2 libpng@1.6.16 py-pyparsing@2.0.3
cmake@3.0.2 libtiff@4.0.3 py-pyside@1.2.2
dbus@1.8.6 libtool@2.4.2 py-pytz@2014.10
dbus@1.9.0 libxcb@1.11 py-setuptools@11.3.1
dyninst@8.1.2 libxml2@2.9.2 py-six@1.9.0
fontconfig@2.11.1 libxml2@2.9.2 python@2.7.8
freetype@2.5.3 llvm@3.0 qhull@1.0
gdk-pixbuf@2.31.2 memaxes@0.5 qt@4.8.6
glib@2.42.1 mesa@8.0.5 qt@5.4.0
graphlib@2.0.0 mpich@3.0.4 readline@6.3
gtkplus@2.24.25 mpileaks@1.0 sqlite@3.8.5
harfbuzz@0.9.37 mrnet@4.1.0 stat@2.1.0
hdf5@1.8.13 ncurses@5.9 tcl@8.6.3
icu@54.1 netcdf@4.3.3 tk@src
jpeg@9a openssl@1.0.1h vtk@6.1.0
launchmon@1.0.1 pango@1.36.8 xcb-proto@1.11
lcms@2.6 pixman@0.32.6 xz@5.2.0
libdrm@2.4.33 py-dateutil@2.4.0 zlib@1.2.8
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.9.2 --------------------------------
2015-02-23 17:22:49 +08:00
libelf@0.8.10 mpich@3.0.4
Packages are divided into groups according to their architecture and
compiler. Within each group, Spack tries to keep the view simple, and
only shows the version of installed packages.
2020-01-08 00:16:54 +08:00
.. _cmd-spack-find-metadata:
2019-09-02 10:41:00 +08:00
""""""""""""""""""""""""""""""""
Viewing more metadata
""""""""""""""""""""""""""""""""
2019-10-24 04:11:35 +08:00
`` spack find `` can filter the package list based on the package name,
spec, or a number of properties of their installation status. For
example, missing dependencies of a spec can be shown with
`` --missing `` , deprecated packages can be included with
`` --deprecated `` , packages which were explicitly installed with
`` spack install <package> `` can be singled out with `` --explicit `` and
those which have been pulled in only as dependencies with
2016-08-27 05:41:00 +08:00
`` --implicit `` .
2016-05-19 05:04:39 +08:00
2015-02-25 02:26:26 +08:00
In some cases, there may be different configurations of the *same*
2015-02-23 17:22:49 +08:00
version of a package installed. For example, there are two
2016-08-27 05:41:00 +08:00
installations of `` libdwarf@20130729 `` above. We can look at them
in more detail using `` spack find --deps `` , and by asking only to show
2015-02-23 17:22:49 +08:00
`` libdwarf `` packages:
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
$ spack find --deps libdwarf
==> 2 installed packages.
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.4.7 --------------------------------
2015-02-23 17:22:49 +08:00
libdwarf@20130729-d9b90962
^libelf@0.8.12
libdwarf@20130729-b52fac98
^libelf@0.8.13
Now we see that the two instances of `` libdwarf `` depend on
*different* versions of `` libelf `` : 0.8.12 and 0.8.13. This view can
become complicated for packages with many dependencies. If you just
want to know whether two packages' dependencies differ, you can use
2016-08-27 05:41:00 +08:00
`` spack find --long `` :
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
$ spack find --long libdwarf
2015-02-23 17:22:49 +08:00
==> 2 installed packages.
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.4.7 --------------------------------
2015-02-23 17:22:49 +08:00
libdwarf@20130729-d9b90962 libdwarf@20130729-b52fac98
2016-08-27 05:41:00 +08:00
Now the `` libdwarf `` installs have hashes after their names. These are
2015-02-23 17:22:49 +08:00
hashes over all of the dependencies of each package. If the hashes
are the same, then the packages have the same dependency configuration.
If you want to know the path where each package is installed, you can
2016-08-27 05:41:00 +08:00
use `` spack find --paths `` :
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
$ spack find --paths
2015-02-23 17:22:49 +08:00
==> 74 installed packages.
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.4.7 --------------------------------
2016-12-26 04:36:35 +08:00
ImageMagick@6.8.9-10 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/ImageMagick@6.8.9-10-4df950dd
adept-utils@1.0 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/adept-utils@1.0-5adef8da
atk@2.14.0 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/atk@2.14.0-3d09ac09
boost@1.55.0 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/boost@1.55.0
bzip2@1.0.6 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/bzip2@1.0.6
cairo@1.14.0 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/cairo@1.14.0-fcc2ab44
callpath@1.0.2 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/callpath@1.0.2-5dce4318
2015-02-23 17:22:49 +08:00
...
2019-09-02 10:41:00 +08:00
You can restrict your search to a particular package by supplying its
name:
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
$ spack find --paths libelf
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.4.7 --------------------------------
2016-12-26 04:36:35 +08:00
libelf@0.8.11 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/libelf@0.8.11
libelf@0.8.12 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/libelf@0.8.12
libelf@0.8.13 ~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/libelf@0.8.13
2015-02-23 17:22:49 +08:00
2019-09-02 10:41:00 +08:00
""""""""""""""""""""""""""""""""
Spec queries
""""""""""""""""""""""""""""""""
2015-02-23 17:22:49 +08:00
`` spack find `` actually does a lot more than this. You can use
*specs* to query for specific configurations and builds of each
package. If you want to find only libelf versions greater than version
0.8.12, you could say:
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
$ spack find libelf@0.8.12:
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.4.7 --------------------------------
2015-02-23 17:22:49 +08:00
libelf@0.8.12 libelf@0.8.13
Finding just the versions of libdwarf built with a particular version
of libelf would look like this:
2016-08-27 05:41:00 +08:00
.. code-block :: console
2015-02-23 17:22:49 +08:00
2016-08-27 05:41:00 +08:00
$ spack find --long libdwarf ^libelf@0.8.12
2015-02-23 17:22:49 +08:00
==> 1 installed packages.
2016-07-01 07:59:36 +08:00
-- linux-debian7-x86_64 / gcc@4.4.7 --------------------------------
2015-02-23 17:22:49 +08:00
libdwarf@20130729-d9b90962
2016-05-26 01:56:12 +08:00
We can also search for packages that have a certain attribute. For example,
2016-08-27 05:41:00 +08:00
`` spack find libdwarf +debug `` will show only installations of libdwarf
with the 'debug' compile-time option enabled.
2016-05-26 01:56:12 +08:00
2015-02-23 17:22:49 +08:00
The full spec syntax is discussed in detail in :ref: `sec-specs` .
2019-09-02 10:41:00 +08:00
""""""""""""""""""""""""""""""""
Machine-readable output
""""""""""""""""""""""""""""""""
If you only want to see very specific things about installed packages,
Spack has some options for you. `` spack find --format `` can be used to
output only specific fields:
.. code-block :: console
$ spack find --format "{name}-{version}-{hash}"
autoconf-2.69-icynozk7ti6h4ezzgonqe6jgw5f3ulx4
automake-1.16.1-o5v3tc77kesgonxjbmeqlwfmb5qzj7zy
bzip2-1.0.6-syohzw57v2jfag5du2x4bowziw3m5p67
bzip2-1.0.8-zjny4jwfyvzbx6vii3uuekoxmtu6eyuj
cmake-3.15.1-7cf6onn52gywnddbmgp7qkil4hdoxpcb
...
or:
.. code-block :: console
$ spack find --format "{hash:7}"
icynozk
o5v3tc7
syohzw5
zjny4jw
7cf6onn
...
This uses the same syntax as described in documentation for
:meth: `~spack.spec.Spec.format` -- you can use any of the options there.
This is useful for passing metadata about packages to other command-line
tools.
Alternately, if you want something even more machine readable, you can
output each spec as JSON records using `` spack find --json `` . This will
output metadata on specs and all dependencies as json:
.. code-block :: console
$ spack find --json sqlite@3.28.0
[
{
"name": "sqlite",
"hash": "3ws7bsihwbn44ghf6ep4s6h4y2o6eznv",
"version": "3.28.0",
"arch": {
"platform": "darwin",
"platform_os": "mojave",
"target": "x86_64"
},
"compiler": {
2020-06-26 00:18:48 +08:00
"name": "apple-clang",
"version": "10.0.0"
2019-09-02 10:41:00 +08:00
},
"namespace": "builtin",
"parameters": {
"fts": true,
"functions": false,
"cflags": [],
"cppflags": [],
"cxxflags": [],
"fflags": [],
"ldflags": [],
"ldlibs": []
},
"dependencies": {
"readline": {
"hash": "722dzmgymxyxd6ovjvh4742kcetkqtfs",
"type": [
"build",
"link"
]
}
}
},
...
]
You can use this with tools like `jq <https://stedolan.github.io/jq/> `_ to quickly create JSON records
structured the way you want:
.. code-block :: console
$ spack find --json sqlite@3.28.0 | jq -C '.[] | { name, version, hash }'
{
"name": "sqlite",
"version": "3.28.0",
"hash": "3ws7bsihwbn44ghf6ep4s6h4y2o6eznv"
}
{
"name": "readline",
"version": "7.0",
"hash": "722dzmgymxyxd6ovjvh4742kcetkqtfs"
}
{
"name": "ncurses",
"version": "6.1",
"hash": "zvaa4lhlhilypw5quj3akyd3apbq5gap"
}
2020-10-24 13:16:01 +08:00
2021-07-30 15:08:38 +08:00
^^^^^^^^^^^^^^
`` spack diff ``
^^^^^^^^^^^^^^
It's often the case that you have two versions of a spec that you need to
disambiguate. Let's say that we've installed two variants of zlib, one with
and one without the optimize variant:
.. code-block :: console
$ spack install zlib
$ spack install zlib -optimize
When we do `` spack find `` we see the two versions.
.. code-block :: console
$ spack find zlib
==> 2 installed packages
-- linux-ubuntu20.04-skylake / gcc@9.3.0 ------------------------
zlib@1.2.11 zlib@1.2.11
Let's now say that we want to uninstall zlib. We run the command, and hit a problem
real quickly since we have two!
.. code-block :: console
$ spack uninstall zlib
==> Error: zlib matches multiple packages:
-- linux-ubuntu20.04-skylake / gcc@9.3.0 ------------------------
efzjziy zlib@1.2.11 sl7m27m zlib@1.2.11
==> Error: You can either:
a) use a more specific spec, or
b) specify the spec by its hash (e.g. `spack uninstall /hash` ), or
c) use `spack uninstall --all` to uninstall ALL matching specs.
Oh no! We can see from the above that we have two different versions of zlib installed,
2021-08-01 13:15:33 +08:00
and the only difference between the two is the hash. This is a good use case for
`` spack diff `` , which can easily show us the "diff" or set difference
2021-07-30 15:08:38 +08:00
between properties for two packages. Let's try it out.
Since the only difference we see in the `` spack find `` view is the hash, let's use
`` spack diff `` to look for more detail. We will provide the two hashes:
2021-08-01 13:15:33 +08:00
.. code-block :: console
2021-07-30 15:08:38 +08:00
$ spack diff /efzjziy /sl7m27m
==> Warning: This interface is subject to change.
--- zlib@1.2.11efzjziyc3dmb5h5u5azsthgbgog5mj7g
+++ zlib@1.2.11sl7m27mzkbejtkrajigj3a3m37ygv4u2
@@ variant_value @@
2021-08-01 13:15:33 +08:00
- zlib optimize False
+ zlib optimize True
2021-07-30 15:08:38 +08:00
The output is colored, and written in the style of a git diff. This means that you
2021-08-01 13:15:33 +08:00
can copy and paste it into a GitHub markdown as a code block with language "diff"
and it will render nicely! Here is an example:
2021-07-30 15:08:38 +08:00
2021-08-18 15:49:51 +08:00
.. code-block :: md
2021-07-30 15:08:38 +08:00
`` ` diff
--- zlib@1.2.11/efzjziyc3dmb5h5u5azsthgbgog5mj7g
+++ zlib@1.2.11/sl7m27mzkbejtkrajigj3a3m37ygv4u2
@@ variant_value @@
2021-08-01 13:15:33 +08:00
- zlib optimize False
+ zlib optimize True
2021-07-30 15:08:38 +08:00
`` `
2021-08-01 13:15:33 +08:00
Awesome! Now let's read the diff. It tells us that our first zlib was built with `` ~optimize ``
(`` False `` ) and the second was built with `` +optimize `` (`` True `` ). You can't see it in the docs
here, but the output above is also colored based on the content being an addition (+) or
subtraction (-).
2021-07-30 15:08:38 +08:00
2021-08-01 13:15:33 +08:00
This is a small example, but you will be able to see differences for any attributes on the
installation spec. Running `` spack diff A B `` means we'll see which spec attributes are on
`` B `` but not on `` A `` (green) and which are on `` A `` but not on `` B `` (red). Here is another
example with an additional difference type, `` version `` :
2021-07-30 15:08:38 +08:00
2021-08-01 13:15:33 +08:00
.. code-block :: console
2021-07-30 15:08:38 +08:00
$ spack diff python@2.7.8 python@3.8.11
==> Warning: This interface is subject to change.
--- python@2.7.8/tsxdi6gl4lihp25qrm4d6nys3nypufbf
+++ python@3.8.11/yjtseru4nbpllbaxb46q7wfkyxbuvzxx
@@ variant_value @@
- python patches a8c52415a8b03c0e5f28b5d52ae498f7a7e602007db2b9554df28cd5685839b8
+ python patches 0d98e93189bc278fbc37a50ed7f183bd8aaf249a8e1670a465f0db6bb4f8cf87
@@ version @@
2021-08-01 13:15:33 +08:00
- openssl 1.0.2u
+ openssl 1.1.1k
- python 2.7.8
+ python 3.8.11
2021-07-30 15:08:38 +08:00
2021-08-01 13:15:33 +08:00
Let's say that we were only interested in one kind of attribute above, `` version `` .
We can ask the command to only output this attribute. To do this, you'd add
the `` --attribute `` for attribute parameter, which defaults to all. Here is how you
would filter to show just versions:
2021-07-30 15:08:38 +08:00
.. code-block :: console
2021-08-01 13:15:33 +08:00
$ spack diff --attribute version python@2.7.8 python@3.8.11
2021-07-30 15:08:38 +08:00
==> Warning: This interface is subject to change.
--- python@2.7.8/tsxdi6gl4lihp25qrm4d6nys3nypufbf
+++ python@3.8.11/yjtseru4nbpllbaxb46q7wfkyxbuvzxx
@@ version @@
2021-08-01 13:15:33 +08:00
- openssl 1.0.2u
+ openssl 1.1.1k
- python 2.7.8
+ python 3.8.11
2021-07-30 15:08:38 +08:00
2021-08-01 13:15:33 +08:00
And you can add as many attributes as you'd like with multiple `--attribute` arguments
(for lots of attributes, you can use `` -a `` for short). Finally, if you want to view the
data as json (and possibly pipe into an output file) just add `` --json `` :
2021-07-30 15:08:38 +08:00
.. code-block :: console
2021-08-01 13:15:33 +08:00
2021-07-30 15:08:38 +08:00
$ spack diff --json python@2.7.8 python@3.8.11
2021-08-01 13:15:33 +08:00
This data will be much longer because along with the differences for `` A `` vs. `` B `` and
`` B `` vs. `` A `` , the JSON output also showsthe intersection.
2021-07-30 15:08:38 +08:00
2020-10-24 13:16:01 +08:00
------------------------
Using installed packages
------------------------
There are several different ways to use Spack packages once you have
installed them. As you've seen, spack packages are installed into long
paths with hashes, and you need a way to get them into your path. The
easiest way is to use :ref: `spack load <cmd-spack-load>` , which is
2024-05-06 22:17:35 +08:00
described in this section.
2020-10-24 13:16:01 +08:00
Some more advanced ways to use Spack packages include:
* :ref: `environments <environments>` , which you can use to bundle a
number of related packages to "activate" all at once, and
* :ref: `environment modules <modules>` , which are commonly used on
supercomputing clusters. Spack generates module files for every
installation automatically, and you can customize how this is done.
.. _cmd-spack-load:
^^^^^^^^^^^^^^^^^^^^^^^
`` spack load / unload ``
^^^^^^^^^^^^^^^^^^^^^^^
If you have :ref: `shell support <shell-support>` enabled you can use the
`` spack load `` command to quickly get a package on your `` PATH `` .
For example this will add the `` mpich `` package built with `` gcc `` to
your path:
.. code-block :: console
$ spack install mpich %gcc@4.4.7
# ... wait for install ...
$ spack load mpich %gcc@4.4.7
$ which mpicc
~/spack/opt/linux-debian7-x86_64/gcc@4.4.7/mpich@3.0.4/bin/mpicc
2022-08-11 22:33:08 +08:00
These commands will add appropriate directories to your `` PATH ``
and `` MANPATH `` according to the
2020-11-18 07:24:00 +08:00
:ref: `prefix inspections <customize-env-modifications>` defined in your
2021-11-03 13:12:08 +08:00
modules configuration.
When you no longer want to use a package, you can type unload or
unuse similarly:
2020-10-24 13:16:01 +08:00
.. code-block :: console
$ spack unload mpich %gcc@4.4.7
"""""""""""""""
Ambiguous specs
"""""""""""""""
If a spec used with load/unload or is ambiguous (i.e. more than one
installed package matches it), then Spack will warn you:
.. code-block :: console
$ spack load libelf
==> Error: libelf matches multiple packages.
Matching packages:
qmm4kso libelf@0.8.13%gcc@4.4.7 arch=linux-debian7-x86_64
cd2u6jt libelf@0.8.13%intel@15.0.0 arch=linux-debian7-x86_64
Use a more specific spec
You can either type the `` spack load `` command again with a fully
qualified argument, or you can add just enough extra constraints to
identify one package. For example, above, the key differentiator is
that one `` libelf `` is built with the Intel compiler, while the other
used `` gcc `` . You could therefore just type:
.. code-block :: console
$ spack load libelf %intel
To identify just the one built with the Intel compiler. If you want to be
*very* specific, you can load it by its hash. For example, to load the
first `` libelf `` above, you would run:
.. code-block :: console
$ spack load /qmm4kso
2023-03-19 09:42:50 +08:00
To see which packages that you have loaded to your environment you would
2021-11-03 13:12:08 +08:00
use `` spack find --loaded `` .
.. code-block :: console
$ spack find --loaded
==> 2 installed packages
-- linux-debian7 / gcc@4.4.7 ------------------------------------
libelf@0.8.13
-- linux-debian7 / intel@15.0.0 ---------------------------------
libelf@0.8.13
2021-11-05 15:58:29 +08:00
You can also use `` spack load --list `` to get the same output, but it
does not have the full set of query options that `` spack find `` offers.
2024-05-06 22:17:35 +08:00
We'll learn more about Spack's spec syntax in :ref: `a later section <sec-specs>` .
.. _extensions:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Python packages and virtual environments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Spack can install a large number of Python packages. Their names are
typically prefixed with `` py- `` . Installing and using them is no
different from any other package:
.. code-block :: console
$ spack install py-numpy
$ spack load py-numpy
$ python3
>>> import numpy
The `` spack load `` command sets the `` PATH `` variable so that the right Python
executable is used, and makes sure that `` numpy `` and its dependencies can be
located in the `` PYTHONPATH `` .
Spack is different from other Python package managers in that it installs
every package into its *own* prefix. This is in contrast to `` pip `` , which
installs all packages into the same prefix, be it in a virtual environment
or not.
For many users, **virtual environments** are more convenient than repeated
`` spack load `` commands, particularly when working with multiple Python
packages. Fortunately Spack supports environments itself, which together
with a view are no different from Python virtual environments.
The recommended way of working with Python extensions such as `` py-numpy ``
is through :ref: `Environments <environments>` . The following example creates
a Spack environment with `` numpy `` in the current working directory. It also
puts a filesystem view in `` ./view `` , which is a more traditional combined
prefix for all packages in the environment.
.. code-block :: console
$ spack env create --with-view view --dir .
$ spack -e . add py-numpy
$ spack -e . concretize
$ spack -e . install
Now you can activate the environment and start using the packages:
.. code-block :: console
$ spack env activate .
$ python3
>>> import numpy
The environment view is also a virtual environment, which is useful if you are
sharing the environment with others who are unfamiliar with Spack. They can
either use the Python executable directly:
.. code-block :: console
$ ./view/bin/python3
>>> import numpy
or use the activation script:
.. code-block :: console
$ source ./view/bin/activate
$ python3
>>> import numpy
In general, there should not be much difference between `` spack env activate ``
and using the virtual environment. The main advantage of `` spack env activate ``
is that it knows about more packages than just Python packages, and it may set
additional runtime variables that are not covered by the virtual environment
activation script.
See :ref: `environments` for a more in-depth description of Spack
environments and customizations to views.
2020-10-24 13:16:01 +08:00
2013-12-12 20:25:31 +08:00
.. _sec-specs:
2016-08-24 06:03:29 +08:00
--------------------
2015-02-24 18:33:29 +08:00
Specs & dependencies
2016-08-24 06:03:29 +08:00
--------------------
2013-12-12 20:25:31 +08:00
2015-02-23 17:22:49 +08:00
We know that `` spack install `` , `` spack uninstall `` , and other
commands take a package name with an optional version specifier. In
Spack, that descriptor is called a *spec* . Spack uses specs to refer
to a particular build configuration (or configurations) of a package.
2013-12-19 03:02:31 +08:00
Specs are more than a package name and a version; you can use them to
specify the compiler, compiler version, architecture, compile options,
2016-08-27 05:41:00 +08:00
and dependency options for a build. In this section, we'll go over
2013-12-19 03:02:31 +08:00
the full syntax of specs.
2016-08-27 05:41:00 +08:00
Here is an example of a much longer spec than we've seen thus far:
.. code-block :: none
2013-12-19 03:02:31 +08:00
2020-07-31 20:54:09 +08:00
mpileaks @1.2:1.4 %gcc@4.7.5 +debug -qt target=x86_64 ^callpath @1.1 %gcc@4.7.2
2013-12-19 03:02:31 +08:00
If provided to `` spack install `` , this will install the `` mpileaks ``
2014-01-15 15:50:50 +08:00
library at some version between `` 1.2 `` and `` 1.4 `` (inclusive),
2020-07-31 20:54:09 +08:00
built using `` gcc `` at version 4.7.5 for a generic `` x86_64 `` architecture,
2013-12-19 03:02:31 +08:00
with debug options enabled, and without Qt support. Additionally, it
says to link it with the `` callpath `` library (which it depends on),
and to build callpath with `` gcc `` 4.7.2. Most specs will not be as
complicated as this one, but this is a good example of what is
possible with specs.
More formally, a spec consists of the following pieces:
* Package name identifier (`` mpileaks `` above)
* `` @ `` Optional version specifier (`` @1.2:1.4 `` )
* `` % `` Optional compiler specifier, with an optional compiler version
(`` gcc `` or `` gcc@4.7.3 `` )
* `` + `` or `` - `` or `` ~ `` Optional variant specifiers (`` +debug `` ,
2022-03-29 05:18:00 +08:00
`` -qt `` , or `` ~qt `` ) for boolean variants. Use `` ++ `` or `` -- `` or
`` ~~ `` to propagate variants through the dependencies (`` ++debug `` ,
`` --qt `` , or `` ~~qt `` ).
2016-05-26 01:56:12 +08:00
* `` name=<value> `` Optional variant specifiers that are not restricted to
2022-03-29 05:18:00 +08:00
boolean variants. Use `` name==<value> `` to propagate variant through the
dependencies.
2016-05-26 01:56:12 +08:00
* `` name=<value> `` Optional compiler flag specifiers. Valid flag names are
2016-07-14 23:31:07 +08:00
`` cflags `` , `` cxxflags `` , `` fflags `` , `` cppflags `` , `` ldflags `` , and `` ldlibs `` .
2022-03-29 05:18:00 +08:00
Use `` name==<value> `` to propagate compiler flags through the dependencies.
2016-07-21 19:15:10 +08:00
* `` target=<value> os=<value> `` Optional architecture specifier
2016-07-14 23:31:07 +08:00
(`` target=haswell os=CNL10 `` )
* `` ^ `` Dependency specs (`` ^callpath@1.1 `` )
2013-12-19 03:02:31 +08:00
2014-07-08 17:41:29 +08:00
There are two things to notice here. The first is that specs are
2013-12-19 03:02:31 +08:00
recursively defined. That is, each dependency after `` ^ `` is a spec
2014-07-08 17:41:29 +08:00
itself. The second is that everything is optional *except* for the
initial package name identifier. Users can be as vague or as specific
as they want about the details of building packages, and this makes
spack good for beginners and experts alike.
2013-12-19 03:02:31 +08:00
To really understand what's going on above, we need to think about how
software is structured. An executable or a library (these are
generally the artifacts produced by building software) depends on
other libraries in order to run. We can represent the relationship
between a package and its dependencies as a graph. Here is the full
dependency graph for `` mpileaks `` :
.. graphviz ::
digraph {
mpileaks -> mpich
mpileaks -> callpath -> mpich
callpath -> dyninst
dyninst -> libdwarf -> libelf
dyninst -> libelf
}
Each box above is a package and each arrow represents a dependency on
some other package. For example, we say that the package `` mpileaks ``
*depends on* `` callpath `` and `` mpich `` . `` mpileaks `` also depends
*indirectly* on `` dyninst `` , `` libdwarf `` , and `` libelf `` , in that
these libraries are dependencies of `` callpath `` . To install
`` mpileaks `` , Spack has to build all of these packages. Dependency
graphs in Spack have to be acyclic, and the *depends on* relationship
is directional, so this is a *directed, acyclic graph* or *DAG* .
The package name identifier in the spec is the root of some dependency
DAG, and the DAG itself is implicit. Spack knows the precise
dependencies among packages, but users do not need to know the full
DAG structure. Each `` ^ `` in the full spec refers to some dependency
of the root package. Spack will raise an error if you supply a name
after `` ^ `` that the root does not actually depend on (e.g. `` mpileaks
^emacs@23.3`` ).
Spack further simplifies things by only allowing one configuration of
each package within any single build. Above, both `` mpileaks `` and
`` callpath `` depend on `` mpich `` , but `` mpich `` appears only once in
the DAG. You cannot build an `` mpileaks `` version that depends on one
version of `` mpich `` *and* on a `` callpath `` version that depends on
some *other* version of `` mpich `` . In general, such a configuration
would likely behave unexpectedly at runtime, and Spack enforces this
to ensure a consistent runtime environment.
The point of specs is to abstract this full DAG from Spack users. If
a user does not care about the DAG at all, she can refer to mpileaks
by simply writing `` mpileaks `` . If she knows that `` mpileaks ``
indirectly uses `` dyninst `` and she wants a particular version of
`` dyninst `` , then she can refer to `` mpileaks ^dyninst@8.1 `` . Spack
will fill in the rest when it parses the spec; the user only needs to
know package names and minimal details about their relationship.
When spack prints out specs, it sorts package names alphabetically to
normalize the way they are displayed, but users do not need to worry
about this when they write specs. The only restriction on the order
of dependencies within a spec is that they appear *after* the root
package. For example, these two specs represent exactly the same
configuration:
2016-08-27 05:41:00 +08:00
.. code-block :: none
2013-12-19 03:02:31 +08:00
mpileaks ^callpath@1.0 ^libelf@0.8.3
mpileaks ^libelf@0.8.3 ^callpath@1.0
You can put all the same modifiers on dependency specs that you would
put on the root spec. That is, you can specify their versions,
compilers, variants, and architectures just like any other spec.
Specifiers are associated with the nearest package name to their left.
For example, above, `` @1.1 `` and `` %gcc@4.7.2 `` associates with the
`` callpath `` package, while `` @1.2:1.4 `` , `` %gcc@4.7.5 `` , `` +debug `` ,
2016-06-28 04:52:48 +08:00
`` -qt `` , and `` target=haswell os=CNL10 `` all associate with the `` mpileaks `` package.
2013-12-19 03:02:31 +08:00
In the diagram above, `` mpileaks `` depends on `` mpich `` with an
unspecified version, but packages can depend on other packages with
*constraints* by adding more specifiers. For example, `` mpileaks ``
could depend on `` mpich@1.2: `` if it can only build with version
`` 1.2 `` or higher of `` mpich `` .
2024-09-21 02:55:17 +08:00
.. note :: Windows Spec Syntax Caveats
Windows has a few idiosyncrasies when it comes to the Spack spec syntax and the use of certain shells
Spack's spec dependency syntax uses the carat (`` ^ `` ) character, however this is an escape string in CMD
so it must be escaped with an additional carat (i.e. `` ^^ `` ).
CMD also will attempt to interpret strings with `` = `` characters in them. Any spec including this symbol
must double quote the string.
Note: All of these issues are unique to CMD, they can be avoided by using Powershell.
For more context on these caveats see the related issues: `carat <https://github.com/spack/spack/issues/42833> `_ and `equals <https://github.com/spack/spack/issues/43348> `_
2013-12-19 03:02:31 +08:00
Below are more details about the specifiers that you can add to specs.
2022-08-05 04:20:33 +08:00
.. _version-specifier:
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
Version specifier
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
Improve version, version range, and version list syntax and behavior (#36273)
## Version types, parsing and printing
- The version classes have changed: `VersionBase` is removed, there is now a
`ConcreteVersion` base class. `StandardVersion` and `GitVersion` both inherit
from this.
- The public api (`Version`, `VersionRange`, `ver`) has changed a bit:
1. `Version` produces either `StandardVersion` or `GitVersion` instances.
2. `VersionRange` produces a `ClosedOpenRange`, but this shouldn't affect the user.
3. `ver` produces any of `VersionList`, `ClosedOpenRange`, `StandardVersion`
or `GitVersion`.
- No unexpected type promotion, so that the following is no longer an identity:
`Version(x) != VersionRange(x, x)`.
- `VersionList.concrete` now returns a version if it contains only a single element
subtyping `ConcreteVersion` (i.e. `StandardVersion(...)` or `GitVersion(...)`)
- In version lists, the parser turns `@x` into `VersionRange(x, x)` instead
of `Version(x)`.
- The above also means that `ver("x")` produces a range, whereas
`ver("=x")` produces a `StandardVersion`. The `=` is part of _VersionList_
syntax.
- `VersionList.__str__` now outputs `=x.y.z` for specific version entries,
and `x.y.z` as a short-hand for ranges `x.y.z:x.y.z`.
- `Spec.format` no longer aliases `{version}` to `{versions}`, but pulls the
concrete version out of the list and prints that -- except when the list is
is not concrete, then is falls back to `{versions}` to avoid a pedantic error.
For projections of concrete specs, `{version}` should be used to render
`1.2.3` instead of `=1.2.3` (which you would get with `{versions}`).
The default `Spec` format string used in `Spec.__str__` now uses
`{versions}` so that `str(Spec(string)) == string` holds.
## Changes to `GitVersion`
- `GitVersion` is a small wrapper around `StandardVersion` which enriches it
with a git ref. It no longer inherits from it.
- `GitVersion` _always_ needs to be able to look up an associated Spack version
if it was not assigned (yet). It throws a `VersionLookupError` whenever `ref_version`
is accessed but it has no means to look up the ref; in the past Spack would
not error and use the commit sha as a literal version, which was incorrect.
- `GitVersion` is never equal to `StandardVersion`, nor is satisfied by it. This
is such that we don't lose transitivity. This fixes the following bug on `develop`
where `git_version_a == standard_version == git_version_b` does not imply
`git_version_a == git_version_b`. It also ensures equality always implies equal
hash, which is also currently broken on develop; inclusion tests of a set of
versions + git versions would behave differently from inclusion tests of a
list of the same objects.
- The above means `ver("ref=1.2.3) != ver("=1.2.3")` could break packages that branch
on specific versions, but that was brittle already, since the same happens with
externals: `pkg@1.2.3-external` suffixes wouldn't be exactly equal either. Instead,
those checks should be `x.satisfies("@1.2.3")` which works both for git versions and
custom version suffixes.
- `GitVersion` from commit will now print as `<hash>=<version>` once the
git ref is resolved to a spack version. This is for reliability -- version is frozen
when added to the database and queried later. It also improves performance
since there is no need to clone all repos of all git versions after `spack clean -m`
is run and something queries the database, triggering version comparison, such
as potentially reuse concretization.
- The "empty VerstionStrComponent trick" for `GitVerison` is dropped since it wasn't
representable as a version string (by design). Instead, it's replaced by `git`,
so you get `1.2.3.git.4` (which reads 4 commits after a tag 1.2.3). This means
that there's an edge case for version schemes `1.1.1`, `1.1.1a`, since the
generated git version `1.1.1.git.1` (1 commit after `1.1.1`) compares larger
than `1.1.1a`, since `a < git` are compared as strings. This is currently a
wont-fix edge case, but if really required, could be fixed by special casing
the `git` string.
- Saved, concrete specs (database, lock file, ...) that only had a git sha as their
version, but have no means to look the effective Spack version anymore, will
now see their version mapped to `hash=develop`. Previously these specs
would always have their sha literally interpreted as a version string (even when
it _could_ be looked up). This only applies to databases, lock files and spec.json
files created before Spack 0.20; after this PR, we always have a Spack version
associated to the relevant GitVersion).
- Fixes a bug where previously `to_dict` / `from_dict` (de)serialization would not
reattach the repo to the GitVersion, causing the git hash to be used as a literal
(bogus) version instead of the resolved version. This was in particularly breaking
version comparison in the build process on macOS/Windows.
## Installing or matching specific versions
- In the past, `spack install pkg@3.2` would install `pkg@=3.2` if it was a
known specific version defined in the package, even when newer patch releases
`3.2.1`, `3.2.2`, `...` were available. This behavior was only there because
there was no syntax to distinguish between `3.2` and `3.2.1`. Since there is
syntax for this now through `pkg@=3.2`, the old exact matching behavior is
removed. This means that `spack install pkg@3.2` constrains the `pkg` version
to the range `3.2`, and `spack install pkg@=3.2` constrains it to the specific
version `3.2`.
- Also in directives such as `depends_on("pkg@2.3")` and their when
conditions `conflicts("...", when="@2.3")` ranges are ranges, and specific
version matches require `@=2.3.`.
- No matching version: in the case `pkg@3.2` matches nothing, concretization
errors. However, if you run `spack install pkg@=3.2` and this version
doesn't exist, Spack will define it; this allows you to install non-registered
versions.
- For consistency, you can now do `%gcc@10` and let it match a configured
`10.x.y` compiler. It errors when there is no matching compiler.
In the past it was interpreted like a specific `gcc@=10` version, which
would get bootstrapped.
- When compiler _bootstrapping_ is enabled, `%gcc@=10.2.0` can be used to
bootstrap a specific compiler version.
## Other changes
- Externals, compilers, and develop spec definitions are backwards compatible.
They are typically defined as `pkg@3.2.1` even though they should be
saying `pkg@=3.2.1`. Spack now transforms `pkg@3` into `pkg@=3` in those cases.
- Finally, fix strictness of `version(...)` directive/declaration. It just does a simple
type check, and now requires strings/integers. Floats are not allowed because
they are ambiguous `str(3.10) == "3.1"`.
2023-05-06 12:04:41 +08:00
A version specifier `` pkg@<specifier> `` comes after a package name
and starts with `` @ `` . It can be something abstract that matches
multiple known versions, or a specific version. During concretization,
Spack will pick the optimal version within the spec's constraints
according to policies set for the particular Spack installation.
The version specifier can be *a specific version* , such as `` @=1.0.0 `` or
`` @=1.2a7 `` . Or, it can be *a range of versions* , such as `` @1.0:1.5 `` .
Version ranges are inclusive, so this example includes both `` 1.0 ``
and any `` 1.5.x `` version. Version ranges can be unbounded, e.g. `` @:3 ``
means any version up to and including `` 3 `` . This would include `` 3.4 ``
and `` 3.4.2 `` . Similarly, `` @4.2: `` means any version above and including
`` 4.2 `` . As a short-hand, `` @3 `` is equivalent to the range `` @3:3 `` and
includes any version with major version `` 3 `` .
Support for prereleases (#43140)
This adds support for prereleases. Alpha, beta and release candidate
suffixes are ordered in the intuitive way:
```
1.2.0-alpha < 1.2.0-alpha.1 < 1.2.0-beta.2 < 1.2.0-rc.3 < 1.2.0 < 1.2.0-xyz
```
Alpha, beta and rc prereleases are defined as follows: split the version
string into components like before (on delimiters and string boundaries).
If there's a string component `alpha`, `beta` or `rc` followed by an optional
numeric component at the end, then the version is prerelease.
So `1.2.0-alpha.1 == 1.2.0alpha1 == 1.2.0.alpha1` are all the same, as usual.
The strings `alpha`, `beta` and `rc` are chosen because they match semver,
they are sufficiently long to be unambiguous, and and all contain at least
one non-hex character so distinguish them from shasum/digest type suffixes.
The comparison key is now stored as `(release_tuple, prerelease_tuple)`, so in
the above example:
```
((1,2,0),(ALPHA,)) < ((1,2,0),(ALPHA,1)) < ((1,2,0),(BETA,2)) < ((1,2,0),(RC,3)) < ((1,2,0),(FINAL,)) < ((1,2,0,"xyz"), (FINAL,))
```
The version ranges `@1.2.0:` and `@:1.1` do *not* include prereleases of
`1.2.0`.
So for packaging, if the `1.2.0alpha` and `1.2.0` versions have the same constraints on
dependencies, it's best to write
```python
depends_on("x@1:", when="@1.2.0alpha:")
```
However, `@1.2:` does include `1.2.0alpha`. This is because Spack considers
`1.2 < 1.2.0` as distinct versions, with `1.2 < 1.2.0alpha < 1.2.0` as a consequence.
Alternatively, the above `depends_on` statement can thus be written
```python
depends_on("x@1:", when="@1.2:")
```
which can be useful too. A short-hand to include prereleases, but you
can still be explicit to exclude the prerelease by specifying the patch version
number.
### Concretization
Concretization uses a different version order than `<`. Prereleases are ordered
between final releases and develop versions. That way, users should not
have to set `preferred=True` on every final release if they add just one
prerelease to a package. The concretizer is unlikely to pick a prerelease when
final releases are possible.
### Limitations
1. You can't express a range that includes all alpha release but excludes all beta
releases. Only alternative is good old repeated nines: `@:1.2.0alpha99`.
2. The Python ecosystem defaults to `a`, `b`, `rc` strings, so translation of Python versions to
Spack versions requires expansion to `alpha`, `beta`, `rc`. It's mildly annoying, because
this means we may need to compute URLs differently (not done in this commit).
### Hash
Care is taken not to break hashes of versions that do not have a prerelease
suffix.
2024-03-23 06:30:32 +08:00
Versions are ordered lexicograpically by its components. For more details
on the order, see :ref: `the packaging guide <version-comparison>` .
Improve version, version range, and version list syntax and behavior (#36273)
## Version types, parsing and printing
- The version classes have changed: `VersionBase` is removed, there is now a
`ConcreteVersion` base class. `StandardVersion` and `GitVersion` both inherit
from this.
- The public api (`Version`, `VersionRange`, `ver`) has changed a bit:
1. `Version` produces either `StandardVersion` or `GitVersion` instances.
2. `VersionRange` produces a `ClosedOpenRange`, but this shouldn't affect the user.
3. `ver` produces any of `VersionList`, `ClosedOpenRange`, `StandardVersion`
or `GitVersion`.
- No unexpected type promotion, so that the following is no longer an identity:
`Version(x) != VersionRange(x, x)`.
- `VersionList.concrete` now returns a version if it contains only a single element
subtyping `ConcreteVersion` (i.e. `StandardVersion(...)` or `GitVersion(...)`)
- In version lists, the parser turns `@x` into `VersionRange(x, x)` instead
of `Version(x)`.
- The above also means that `ver("x")` produces a range, whereas
`ver("=x")` produces a `StandardVersion`. The `=` is part of _VersionList_
syntax.
- `VersionList.__str__` now outputs `=x.y.z` for specific version entries,
and `x.y.z` as a short-hand for ranges `x.y.z:x.y.z`.
- `Spec.format` no longer aliases `{version}` to `{versions}`, but pulls the
concrete version out of the list and prints that -- except when the list is
is not concrete, then is falls back to `{versions}` to avoid a pedantic error.
For projections of concrete specs, `{version}` should be used to render
`1.2.3` instead of `=1.2.3` (which you would get with `{versions}`).
The default `Spec` format string used in `Spec.__str__` now uses
`{versions}` so that `str(Spec(string)) == string` holds.
## Changes to `GitVersion`
- `GitVersion` is a small wrapper around `StandardVersion` which enriches it
with a git ref. It no longer inherits from it.
- `GitVersion` _always_ needs to be able to look up an associated Spack version
if it was not assigned (yet). It throws a `VersionLookupError` whenever `ref_version`
is accessed but it has no means to look up the ref; in the past Spack would
not error and use the commit sha as a literal version, which was incorrect.
- `GitVersion` is never equal to `StandardVersion`, nor is satisfied by it. This
is such that we don't lose transitivity. This fixes the following bug on `develop`
where `git_version_a == standard_version == git_version_b` does not imply
`git_version_a == git_version_b`. It also ensures equality always implies equal
hash, which is also currently broken on develop; inclusion tests of a set of
versions + git versions would behave differently from inclusion tests of a
list of the same objects.
- The above means `ver("ref=1.2.3) != ver("=1.2.3")` could break packages that branch
on specific versions, but that was brittle already, since the same happens with
externals: `pkg@1.2.3-external` suffixes wouldn't be exactly equal either. Instead,
those checks should be `x.satisfies("@1.2.3")` which works both for git versions and
custom version suffixes.
- `GitVersion` from commit will now print as `<hash>=<version>` once the
git ref is resolved to a spack version. This is for reliability -- version is frozen
when added to the database and queried later. It also improves performance
since there is no need to clone all repos of all git versions after `spack clean -m`
is run and something queries the database, triggering version comparison, such
as potentially reuse concretization.
- The "empty VerstionStrComponent trick" for `GitVerison` is dropped since it wasn't
representable as a version string (by design). Instead, it's replaced by `git`,
so you get `1.2.3.git.4` (which reads 4 commits after a tag 1.2.3). This means
that there's an edge case for version schemes `1.1.1`, `1.1.1a`, since the
generated git version `1.1.1.git.1` (1 commit after `1.1.1`) compares larger
than `1.1.1a`, since `a < git` are compared as strings. This is currently a
wont-fix edge case, but if really required, could be fixed by special casing
the `git` string.
- Saved, concrete specs (database, lock file, ...) that only had a git sha as their
version, but have no means to look the effective Spack version anymore, will
now see their version mapped to `hash=develop`. Previously these specs
would always have their sha literally interpreted as a version string (even when
it _could_ be looked up). This only applies to databases, lock files and spec.json
files created before Spack 0.20; after this PR, we always have a Spack version
associated to the relevant GitVersion).
- Fixes a bug where previously `to_dict` / `from_dict` (de)serialization would not
reattach the repo to the GitVersion, causing the git hash to be used as a literal
(bogus) version instead of the resolved version. This was in particularly breaking
version comparison in the build process on macOS/Windows.
## Installing or matching specific versions
- In the past, `spack install pkg@3.2` would install `pkg@=3.2` if it was a
known specific version defined in the package, even when newer patch releases
`3.2.1`, `3.2.2`, `...` were available. This behavior was only there because
there was no syntax to distinguish between `3.2` and `3.2.1`. Since there is
syntax for this now through `pkg@=3.2`, the old exact matching behavior is
removed. This means that `spack install pkg@3.2` constrains the `pkg` version
to the range `3.2`, and `spack install pkg@=3.2` constrains it to the specific
version `3.2`.
- Also in directives such as `depends_on("pkg@2.3")` and their when
conditions `conflicts("...", when="@2.3")` ranges are ranges, and specific
version matches require `@=2.3.`.
- No matching version: in the case `pkg@3.2` matches nothing, concretization
errors. However, if you run `spack install pkg@=3.2` and this version
doesn't exist, Spack will define it; this allows you to install non-registered
versions.
- For consistency, you can now do `%gcc@10` and let it match a configured
`10.x.y` compiler. It errors when there is no matching compiler.
In the past it was interpreted like a specific `gcc@=10` version, which
would get bootstrapped.
- When compiler _bootstrapping_ is enabled, `%gcc@=10.2.0` can be used to
bootstrap a specific compiler version.
## Other changes
- Externals, compilers, and develop spec definitions are backwards compatible.
They are typically defined as `pkg@3.2.1` even though they should be
saying `pkg@=3.2.1`. Spack now transforms `pkg@3` into `pkg@=3` in those cases.
- Finally, fix strictness of `version(...)` directive/declaration. It just does a simple
type check, and now requires strings/integers. Floats are not allowed because
they are ambiguous `str(3.10) == "3.1"`.
2023-05-06 12:04:41 +08:00
Notice that you can distinguish between the specific version `` @=3.2 `` and
the range `` @3.2 `` . This is useful for packages that follow a versioning
scheme that omits the zero patch version number: `` 3.2 `` , `` 3.2.1 `` ,
`` 3.2.2 `` , etc. In general it is preferable to use the range syntax
`` @3.2 `` , since ranges also match versions with one-off suffixes, such as
`` 3.2-custom `` .
A version specifier can also be a list of ranges and specific versions,
separated by commas. For example, `` @1.0:1.5,=1.7.1 `` matches any version
in the range `` 1.0:1.5 `` and the specific version `` 1.7.1 `` .
2013-12-19 03:02:31 +08:00
2024-02-01 16:46:17 +08:00
^^^^^^^^^^^^
Git versions
^^^^^^^^^^^^
remove activate/deactivate support in favor of environments (#29317)
Environments and environment views have taken over the role of `spack activate/deactivate`, and we should deprecate these commands for several reasons:
- Global activation is a really poor idea:
- Install prefixes should be immutable; since they can have multiple, unrelated dependents; see below
- Added complexity elsewhere: verification of installations, tarballs for build caches, creation of environment views of packages with unrelated extensions "globally activated"... by removing the feature, it gets easier for people to contribute, and we'd end up with fewer bugs due to edge cases.
- Environment accomplish the same thing for non-global "activation" i.e. `spack view`, but better.
Also we write in the docs:
```
However, Spack global activations have two potential drawbacks:
#. Activated packages that involve compiled C extensions may still
need their dependencies to be loaded manually. For example,
``spack load openblas`` might be required to make ``py-numpy``
work.
#. Global activations "break" a core feature of Spack, which is that
multiple versions of a package can co-exist side-by-side. For example,
suppose you wish to run a Python package in two different
environments but the same basic Python --- one with
``py-numpy@1.7`` and one with ``py-numpy@1.8``. Spack extensions
will not support this potential debugging use case.
```
Now that environments are established and views can take over the role of activation
non-destructively, we can remove global activation/deactivation.
2022-11-11 16:50:07 +08:00
For packages with a `` git `` attribute, `` git `` references
may be specified instead of a numerical version i.e. branches, tags
and commits. Spack will stage and build based off the `` git ``
2022-08-05 04:20:33 +08:00
reference provided. Acceptable syntaxes for this are:
2022-08-05 10:01:03 +08:00
.. code-block :: sh
remove activate/deactivate support in favor of environments (#29317)
Environments and environment views have taken over the role of `spack activate/deactivate`, and we should deprecate these commands for several reasons:
- Global activation is a really poor idea:
- Install prefixes should be immutable; since they can have multiple, unrelated dependents; see below
- Added complexity elsewhere: verification of installations, tarballs for build caches, creation of environment views of packages with unrelated extensions "globally activated"... by removing the feature, it gets easier for people to contribute, and we'd end up with fewer bugs due to edge cases.
- Environment accomplish the same thing for non-global "activation" i.e. `spack view`, but better.
Also we write in the docs:
```
However, Spack global activations have two potential drawbacks:
#. Activated packages that involve compiled C extensions may still
need their dependencies to be loaded manually. For example,
``spack load openblas`` might be required to make ``py-numpy``
work.
#. Global activations "break" a core feature of Spack, which is that
multiple versions of a package can co-exist side-by-side. For example,
suppose you wish to run a Python package in two different
environments but the same basic Python --- one with
``py-numpy@1.7`` and one with ``py-numpy@1.8``. Spack extensions
will not support this potential debugging use case.
```
Now that environments are established and views can take over the role of activation
non-destructively, we can remove global activation/deactivation.
2022-11-11 16:50:07 +08:00
Improve version, version range, and version list syntax and behavior (#36273)
## Version types, parsing and printing
- The version classes have changed: `VersionBase` is removed, there is now a
`ConcreteVersion` base class. `StandardVersion` and `GitVersion` both inherit
from this.
- The public api (`Version`, `VersionRange`, `ver`) has changed a bit:
1. `Version` produces either `StandardVersion` or `GitVersion` instances.
2. `VersionRange` produces a `ClosedOpenRange`, but this shouldn't affect the user.
3. `ver` produces any of `VersionList`, `ClosedOpenRange`, `StandardVersion`
or `GitVersion`.
- No unexpected type promotion, so that the following is no longer an identity:
`Version(x) != VersionRange(x, x)`.
- `VersionList.concrete` now returns a version if it contains only a single element
subtyping `ConcreteVersion` (i.e. `StandardVersion(...)` or `GitVersion(...)`)
- In version lists, the parser turns `@x` into `VersionRange(x, x)` instead
of `Version(x)`.
- The above also means that `ver("x")` produces a range, whereas
`ver("=x")` produces a `StandardVersion`. The `=` is part of _VersionList_
syntax.
- `VersionList.__str__` now outputs `=x.y.z` for specific version entries,
and `x.y.z` as a short-hand for ranges `x.y.z:x.y.z`.
- `Spec.format` no longer aliases `{version}` to `{versions}`, but pulls the
concrete version out of the list and prints that -- except when the list is
is not concrete, then is falls back to `{versions}` to avoid a pedantic error.
For projections of concrete specs, `{version}` should be used to render
`1.2.3` instead of `=1.2.3` (which you would get with `{versions}`).
The default `Spec` format string used in `Spec.__str__` now uses
`{versions}` so that `str(Spec(string)) == string` holds.
## Changes to `GitVersion`
- `GitVersion` is a small wrapper around `StandardVersion` which enriches it
with a git ref. It no longer inherits from it.
- `GitVersion` _always_ needs to be able to look up an associated Spack version
if it was not assigned (yet). It throws a `VersionLookupError` whenever `ref_version`
is accessed but it has no means to look up the ref; in the past Spack would
not error and use the commit sha as a literal version, which was incorrect.
- `GitVersion` is never equal to `StandardVersion`, nor is satisfied by it. This
is such that we don't lose transitivity. This fixes the following bug on `develop`
where `git_version_a == standard_version == git_version_b` does not imply
`git_version_a == git_version_b`. It also ensures equality always implies equal
hash, which is also currently broken on develop; inclusion tests of a set of
versions + git versions would behave differently from inclusion tests of a
list of the same objects.
- The above means `ver("ref=1.2.3) != ver("=1.2.3")` could break packages that branch
on specific versions, but that was brittle already, since the same happens with
externals: `pkg@1.2.3-external` suffixes wouldn't be exactly equal either. Instead,
those checks should be `x.satisfies("@1.2.3")` which works both for git versions and
custom version suffixes.
- `GitVersion` from commit will now print as `<hash>=<version>` once the
git ref is resolved to a spack version. This is for reliability -- version is frozen
when added to the database and queried later. It also improves performance
since there is no need to clone all repos of all git versions after `spack clean -m`
is run and something queries the database, triggering version comparison, such
as potentially reuse concretization.
- The "empty VerstionStrComponent trick" for `GitVerison` is dropped since it wasn't
representable as a version string (by design). Instead, it's replaced by `git`,
so you get `1.2.3.git.4` (which reads 4 commits after a tag 1.2.3). This means
that there's an edge case for version schemes `1.1.1`, `1.1.1a`, since the
generated git version `1.1.1.git.1` (1 commit after `1.1.1`) compares larger
than `1.1.1a`, since `a < git` are compared as strings. This is currently a
wont-fix edge case, but if really required, could be fixed by special casing
the `git` string.
- Saved, concrete specs (database, lock file, ...) that only had a git sha as their
version, but have no means to look the effective Spack version anymore, will
now see their version mapped to `hash=develop`. Previously these specs
would always have their sha literally interpreted as a version string (even when
it _could_ be looked up). This only applies to databases, lock files and spec.json
files created before Spack 0.20; after this PR, we always have a Spack version
associated to the relevant GitVersion).
- Fixes a bug where previously `to_dict` / `from_dict` (de)serialization would not
reattach the repo to the GitVersion, causing the git hash to be used as a literal
(bogus) version instead of the resolved version. This was in particularly breaking
version comparison in the build process on macOS/Windows.
## Installing or matching specific versions
- In the past, `spack install pkg@3.2` would install `pkg@=3.2` if it was a
known specific version defined in the package, even when newer patch releases
`3.2.1`, `3.2.2`, `...` were available. This behavior was only there because
there was no syntax to distinguish between `3.2` and `3.2.1`. Since there is
syntax for this now through `pkg@=3.2`, the old exact matching behavior is
removed. This means that `spack install pkg@3.2` constrains the `pkg` version
to the range `3.2`, and `spack install pkg@=3.2` constrains it to the specific
version `3.2`.
- Also in directives such as `depends_on("pkg@2.3")` and their when
conditions `conflicts("...", when="@2.3")` ranges are ranges, and specific
version matches require `@=2.3.`.
- No matching version: in the case `pkg@3.2` matches nothing, concretization
errors. However, if you run `spack install pkg@=3.2` and this version
doesn't exist, Spack will define it; this allows you to install non-registered
versions.
- For consistency, you can now do `%gcc@10` and let it match a configured
`10.x.y` compiler. It errors when there is no matching compiler.
In the past it was interpreted like a specific `gcc@=10` version, which
would get bootstrapped.
- When compiler _bootstrapping_ is enabled, `%gcc@=10.2.0` can be used to
bootstrap a specific compiler version.
## Other changes
- Externals, compilers, and develop spec definitions are backwards compatible.
They are typically defined as `pkg@3.2.1` even though they should be
saying `pkg@=3.2.1`. Spack now transforms `pkg@3` into `pkg@=3` in those cases.
- Finally, fix strictness of `version(...)` directive/declaration. It just does a simple
type check, and now requires strings/integers. Floats are not allowed because
they are ambiguous `str(3.10) == "3.1"`.
2023-05-06 12:04:41 +08:00
# commit hashes
foo@abcdef1234abcdef1234abcdef1234abcdef1234 # 40 character hashes are automatically treated as git commits
foo@git.abcdef1234abcdef1234abcdef1234abcdef1234
2022-08-05 04:20:33 +08:00
# branches and tags
foo@git.develop # use the develop branch
foo@git.0.19 # use the 0.19 tag
remove activate/deactivate support in favor of environments (#29317)
Environments and environment views have taken over the role of `spack activate/deactivate`, and we should deprecate these commands for several reasons:
- Global activation is a really poor idea:
- Install prefixes should be immutable; since they can have multiple, unrelated dependents; see below
- Added complexity elsewhere: verification of installations, tarballs for build caches, creation of environment views of packages with unrelated extensions "globally activated"... by removing the feature, it gets easier for people to contribute, and we'd end up with fewer bugs due to edge cases.
- Environment accomplish the same thing for non-global "activation" i.e. `spack view`, but better.
Also we write in the docs:
```
However, Spack global activations have two potential drawbacks:
#. Activated packages that involve compiled C extensions may still
need their dependencies to be loaded manually. For example,
``spack load openblas`` might be required to make ``py-numpy``
work.
#. Global activations "break" a core feature of Spack, which is that
multiple versions of a package can co-exist side-by-side. For example,
suppose you wish to run a Python package in two different
environments but the same basic Python --- one with
``py-numpy@1.7`` and one with ``py-numpy@1.8``. Spack extensions
will not support this potential debugging use case.
```
Now that environments are established and views can take over the role of activation
non-destructively, we can remove global activation/deactivation.
2022-11-11 16:50:07 +08:00
Improve version, version range, and version list syntax and behavior (#36273)
## Version types, parsing and printing
- The version classes have changed: `VersionBase` is removed, there is now a
`ConcreteVersion` base class. `StandardVersion` and `GitVersion` both inherit
from this.
- The public api (`Version`, `VersionRange`, `ver`) has changed a bit:
1. `Version` produces either `StandardVersion` or `GitVersion` instances.
2. `VersionRange` produces a `ClosedOpenRange`, but this shouldn't affect the user.
3. `ver` produces any of `VersionList`, `ClosedOpenRange`, `StandardVersion`
or `GitVersion`.
- No unexpected type promotion, so that the following is no longer an identity:
`Version(x) != VersionRange(x, x)`.
- `VersionList.concrete` now returns a version if it contains only a single element
subtyping `ConcreteVersion` (i.e. `StandardVersion(...)` or `GitVersion(...)`)
- In version lists, the parser turns `@x` into `VersionRange(x, x)` instead
of `Version(x)`.
- The above also means that `ver("x")` produces a range, whereas
`ver("=x")` produces a `StandardVersion`. The `=` is part of _VersionList_
syntax.
- `VersionList.__str__` now outputs `=x.y.z` for specific version entries,
and `x.y.z` as a short-hand for ranges `x.y.z:x.y.z`.
- `Spec.format` no longer aliases `{version}` to `{versions}`, but pulls the
concrete version out of the list and prints that -- except when the list is
is not concrete, then is falls back to `{versions}` to avoid a pedantic error.
For projections of concrete specs, `{version}` should be used to render
`1.2.3` instead of `=1.2.3` (which you would get with `{versions}`).
The default `Spec` format string used in `Spec.__str__` now uses
`{versions}` so that `str(Spec(string)) == string` holds.
## Changes to `GitVersion`
- `GitVersion` is a small wrapper around `StandardVersion` which enriches it
with a git ref. It no longer inherits from it.
- `GitVersion` _always_ needs to be able to look up an associated Spack version
if it was not assigned (yet). It throws a `VersionLookupError` whenever `ref_version`
is accessed but it has no means to look up the ref; in the past Spack would
not error and use the commit sha as a literal version, which was incorrect.
- `GitVersion` is never equal to `StandardVersion`, nor is satisfied by it. This
is such that we don't lose transitivity. This fixes the following bug on `develop`
where `git_version_a == standard_version == git_version_b` does not imply
`git_version_a == git_version_b`. It also ensures equality always implies equal
hash, which is also currently broken on develop; inclusion tests of a set of
versions + git versions would behave differently from inclusion tests of a
list of the same objects.
- The above means `ver("ref=1.2.3) != ver("=1.2.3")` could break packages that branch
on specific versions, but that was brittle already, since the same happens with
externals: `pkg@1.2.3-external` suffixes wouldn't be exactly equal either. Instead,
those checks should be `x.satisfies("@1.2.3")` which works both for git versions and
custom version suffixes.
- `GitVersion` from commit will now print as `<hash>=<version>` once the
git ref is resolved to a spack version. This is for reliability -- version is frozen
when added to the database and queried later. It also improves performance
since there is no need to clone all repos of all git versions after `spack clean -m`
is run and something queries the database, triggering version comparison, such
as potentially reuse concretization.
- The "empty VerstionStrComponent trick" for `GitVerison` is dropped since it wasn't
representable as a version string (by design). Instead, it's replaced by `git`,
so you get `1.2.3.git.4` (which reads 4 commits after a tag 1.2.3). This means
that there's an edge case for version schemes `1.1.1`, `1.1.1a`, since the
generated git version `1.1.1.git.1` (1 commit after `1.1.1`) compares larger
than `1.1.1a`, since `a < git` are compared as strings. This is currently a
wont-fix edge case, but if really required, could be fixed by special casing
the `git` string.
- Saved, concrete specs (database, lock file, ...) that only had a git sha as their
version, but have no means to look the effective Spack version anymore, will
now see their version mapped to `hash=develop`. Previously these specs
would always have their sha literally interpreted as a version string (even when
it _could_ be looked up). This only applies to databases, lock files and spec.json
files created before Spack 0.20; after this PR, we always have a Spack version
associated to the relevant GitVersion).
- Fixes a bug where previously `to_dict` / `from_dict` (de)serialization would not
reattach the repo to the GitVersion, causing the git hash to be used as a literal
(bogus) version instead of the resolved version. This was in particularly breaking
version comparison in the build process on macOS/Windows.
## Installing or matching specific versions
- In the past, `spack install pkg@3.2` would install `pkg@=3.2` if it was a
known specific version defined in the package, even when newer patch releases
`3.2.1`, `3.2.2`, `...` were available. This behavior was only there because
there was no syntax to distinguish between `3.2` and `3.2.1`. Since there is
syntax for this now through `pkg@=3.2`, the old exact matching behavior is
removed. This means that `spack install pkg@3.2` constrains the `pkg` version
to the range `3.2`, and `spack install pkg@=3.2` constrains it to the specific
version `3.2`.
- Also in directives such as `depends_on("pkg@2.3")` and their when
conditions `conflicts("...", when="@2.3")` ranges are ranges, and specific
version matches require `@=2.3.`.
- No matching version: in the case `pkg@3.2` matches nothing, concretization
errors. However, if you run `spack install pkg@=3.2` and this version
doesn't exist, Spack will define it; this allows you to install non-registered
versions.
- For consistency, you can now do `%gcc@10` and let it match a configured
`10.x.y` compiler. It errors when there is no matching compiler.
In the past it was interpreted like a specific `gcc@=10` version, which
would get bootstrapped.
- When compiler _bootstrapping_ is enabled, `%gcc@=10.2.0` can be used to
bootstrap a specific compiler version.
## Other changes
- Externals, compilers, and develop spec definitions are backwards compatible.
They are typically defined as `pkg@3.2.1` even though they should be
saying `pkg@=3.2.1`. Spack now transforms `pkg@3` into `pkg@=3` in those cases.
- Finally, fix strictness of `version(...)` directive/declaration. It just does a simple
type check, and now requires strings/integers. Floats are not allowed because
they are ambiguous `str(3.10) == "3.1"`.
2023-05-06 12:04:41 +08:00
Spack always needs to associate a Spack version with the git reference,
which is used for version comparison. This Spack version is heuristically
taken from the closest valid git tag among ancestors of the git ref.
Once a Spack version is associated with a git ref, it always printed with
the git ref. For example, if the commit `` @git.abcdefg `` is tagged
`` 0.19 `` , then the spec will be shown as `` @git.abcdefg=0.19 `` .
remove activate/deactivate support in favor of environments (#29317)
Environments and environment views have taken over the role of `spack activate/deactivate`, and we should deprecate these commands for several reasons:
- Global activation is a really poor idea:
- Install prefixes should be immutable; since they can have multiple, unrelated dependents; see below
- Added complexity elsewhere: verification of installations, tarballs for build caches, creation of environment views of packages with unrelated extensions "globally activated"... by removing the feature, it gets easier for people to contribute, and we'd end up with fewer bugs due to edge cases.
- Environment accomplish the same thing for non-global "activation" i.e. `spack view`, but better.
Also we write in the docs:
```
However, Spack global activations have two potential drawbacks:
#. Activated packages that involve compiled C extensions may still
need their dependencies to be loaded manually. For example,
``spack load openblas`` might be required to make ``py-numpy``
work.
#. Global activations "break" a core feature of Spack, which is that
multiple versions of a package can co-exist side-by-side. For example,
suppose you wish to run a Python package in two different
environments but the same basic Python --- one with
``py-numpy@1.7`` and one with ``py-numpy@1.8``. Spack extensions
will not support this potential debugging use case.
```
Now that environments are established and views can take over the role of activation
non-destructively, we can remove global activation/deactivation.
2022-11-11 16:50:07 +08:00
Improve version, version range, and version list syntax and behavior (#36273)
## Version types, parsing and printing
- The version classes have changed: `VersionBase` is removed, there is now a
`ConcreteVersion` base class. `StandardVersion` and `GitVersion` both inherit
from this.
- The public api (`Version`, `VersionRange`, `ver`) has changed a bit:
1. `Version` produces either `StandardVersion` or `GitVersion` instances.
2. `VersionRange` produces a `ClosedOpenRange`, but this shouldn't affect the user.
3. `ver` produces any of `VersionList`, `ClosedOpenRange`, `StandardVersion`
or `GitVersion`.
- No unexpected type promotion, so that the following is no longer an identity:
`Version(x) != VersionRange(x, x)`.
- `VersionList.concrete` now returns a version if it contains only a single element
subtyping `ConcreteVersion` (i.e. `StandardVersion(...)` or `GitVersion(...)`)
- In version lists, the parser turns `@x` into `VersionRange(x, x)` instead
of `Version(x)`.
- The above also means that `ver("x")` produces a range, whereas
`ver("=x")` produces a `StandardVersion`. The `=` is part of _VersionList_
syntax.
- `VersionList.__str__` now outputs `=x.y.z` for specific version entries,
and `x.y.z` as a short-hand for ranges `x.y.z:x.y.z`.
- `Spec.format` no longer aliases `{version}` to `{versions}`, but pulls the
concrete version out of the list and prints that -- except when the list is
is not concrete, then is falls back to `{versions}` to avoid a pedantic error.
For projections of concrete specs, `{version}` should be used to render
`1.2.3` instead of `=1.2.3` (which you would get with `{versions}`).
The default `Spec` format string used in `Spec.__str__` now uses
`{versions}` so that `str(Spec(string)) == string` holds.
## Changes to `GitVersion`
- `GitVersion` is a small wrapper around `StandardVersion` which enriches it
with a git ref. It no longer inherits from it.
- `GitVersion` _always_ needs to be able to look up an associated Spack version
if it was not assigned (yet). It throws a `VersionLookupError` whenever `ref_version`
is accessed but it has no means to look up the ref; in the past Spack would
not error and use the commit sha as a literal version, which was incorrect.
- `GitVersion` is never equal to `StandardVersion`, nor is satisfied by it. This
is such that we don't lose transitivity. This fixes the following bug on `develop`
where `git_version_a == standard_version == git_version_b` does not imply
`git_version_a == git_version_b`. It also ensures equality always implies equal
hash, which is also currently broken on develop; inclusion tests of a set of
versions + git versions would behave differently from inclusion tests of a
list of the same objects.
- The above means `ver("ref=1.2.3) != ver("=1.2.3")` could break packages that branch
on specific versions, but that was brittle already, since the same happens with
externals: `pkg@1.2.3-external` suffixes wouldn't be exactly equal either. Instead,
those checks should be `x.satisfies("@1.2.3")` which works both for git versions and
custom version suffixes.
- `GitVersion` from commit will now print as `<hash>=<version>` once the
git ref is resolved to a spack version. This is for reliability -- version is frozen
when added to the database and queried later. It also improves performance
since there is no need to clone all repos of all git versions after `spack clean -m`
is run and something queries the database, triggering version comparison, such
as potentially reuse concretization.
- The "empty VerstionStrComponent trick" for `GitVerison` is dropped since it wasn't
representable as a version string (by design). Instead, it's replaced by `git`,
so you get `1.2.3.git.4` (which reads 4 commits after a tag 1.2.3). This means
that there's an edge case for version schemes `1.1.1`, `1.1.1a`, since the
generated git version `1.1.1.git.1` (1 commit after `1.1.1`) compares larger
than `1.1.1a`, since `a < git` are compared as strings. This is currently a
wont-fix edge case, but if really required, could be fixed by special casing
the `git` string.
- Saved, concrete specs (database, lock file, ...) that only had a git sha as their
version, but have no means to look the effective Spack version anymore, will
now see their version mapped to `hash=develop`. Previously these specs
would always have their sha literally interpreted as a version string (even when
it _could_ be looked up). This only applies to databases, lock files and spec.json
files created before Spack 0.20; after this PR, we always have a Spack version
associated to the relevant GitVersion).
- Fixes a bug where previously `to_dict` / `from_dict` (de)serialization would not
reattach the repo to the GitVersion, causing the git hash to be used as a literal
(bogus) version instead of the resolved version. This was in particularly breaking
version comparison in the build process on macOS/Windows.
## Installing or matching specific versions
- In the past, `spack install pkg@3.2` would install `pkg@=3.2` if it was a
known specific version defined in the package, even when newer patch releases
`3.2.1`, `3.2.2`, `...` were available. This behavior was only there because
there was no syntax to distinguish between `3.2` and `3.2.1`. Since there is
syntax for this now through `pkg@=3.2`, the old exact matching behavior is
removed. This means that `spack install pkg@3.2` constrains the `pkg` version
to the range `3.2`, and `spack install pkg@=3.2` constrains it to the specific
version `3.2`.
- Also in directives such as `depends_on("pkg@2.3")` and their when
conditions `conflicts("...", when="@2.3")` ranges are ranges, and specific
version matches require `@=2.3.`.
- No matching version: in the case `pkg@3.2` matches nothing, concretization
errors. However, if you run `spack install pkg@=3.2` and this version
doesn't exist, Spack will define it; this allows you to install non-registered
versions.
- For consistency, you can now do `%gcc@10` and let it match a configured
`10.x.y` compiler. It errors when there is no matching compiler.
In the past it was interpreted like a specific `gcc@=10` version, which
would get bootstrapped.
- When compiler _bootstrapping_ is enabled, `%gcc@=10.2.0` can be used to
bootstrap a specific compiler version.
## Other changes
- Externals, compilers, and develop spec definitions are backwards compatible.
They are typically defined as `pkg@3.2.1` even though they should be
saying `pkg@=3.2.1`. Spack now transforms `pkg@3` into `pkg@=3` in those cases.
- Finally, fix strictness of `version(...)` directive/declaration. It just does a simple
type check, and now requires strings/integers. Floats are not allowed because
they are ambiguous `str(3.10) == "3.1"`.
2023-05-06 12:04:41 +08:00
If the git ref is not exactly a tag, then the distance to the nearest tag
is also part of the resolved version. `` @git.abcdefg=0.19.git.8 `` means
that the commit is 8 commits away from the `` 0.19 `` tag.
2022-08-05 04:20:33 +08:00
Improve version, version range, and version list syntax and behavior (#36273)
## Version types, parsing and printing
- The version classes have changed: `VersionBase` is removed, there is now a
`ConcreteVersion` base class. `StandardVersion` and `GitVersion` both inherit
from this.
- The public api (`Version`, `VersionRange`, `ver`) has changed a bit:
1. `Version` produces either `StandardVersion` or `GitVersion` instances.
2. `VersionRange` produces a `ClosedOpenRange`, but this shouldn't affect the user.
3. `ver` produces any of `VersionList`, `ClosedOpenRange`, `StandardVersion`
or `GitVersion`.
- No unexpected type promotion, so that the following is no longer an identity:
`Version(x) != VersionRange(x, x)`.
- `VersionList.concrete` now returns a version if it contains only a single element
subtyping `ConcreteVersion` (i.e. `StandardVersion(...)` or `GitVersion(...)`)
- In version lists, the parser turns `@x` into `VersionRange(x, x)` instead
of `Version(x)`.
- The above also means that `ver("x")` produces a range, whereas
`ver("=x")` produces a `StandardVersion`. The `=` is part of _VersionList_
syntax.
- `VersionList.__str__` now outputs `=x.y.z` for specific version entries,
and `x.y.z` as a short-hand for ranges `x.y.z:x.y.z`.
- `Spec.format` no longer aliases `{version}` to `{versions}`, but pulls the
concrete version out of the list and prints that -- except when the list is
is not concrete, then is falls back to `{versions}` to avoid a pedantic error.
For projections of concrete specs, `{version}` should be used to render
`1.2.3` instead of `=1.2.3` (which you would get with `{versions}`).
The default `Spec` format string used in `Spec.__str__` now uses
`{versions}` so that `str(Spec(string)) == string` holds.
## Changes to `GitVersion`
- `GitVersion` is a small wrapper around `StandardVersion` which enriches it
with a git ref. It no longer inherits from it.
- `GitVersion` _always_ needs to be able to look up an associated Spack version
if it was not assigned (yet). It throws a `VersionLookupError` whenever `ref_version`
is accessed but it has no means to look up the ref; in the past Spack would
not error and use the commit sha as a literal version, which was incorrect.
- `GitVersion` is never equal to `StandardVersion`, nor is satisfied by it. This
is such that we don't lose transitivity. This fixes the following bug on `develop`
where `git_version_a == standard_version == git_version_b` does not imply
`git_version_a == git_version_b`. It also ensures equality always implies equal
hash, which is also currently broken on develop; inclusion tests of a set of
versions + git versions would behave differently from inclusion tests of a
list of the same objects.
- The above means `ver("ref=1.2.3) != ver("=1.2.3")` could break packages that branch
on specific versions, but that was brittle already, since the same happens with
externals: `pkg@1.2.3-external` suffixes wouldn't be exactly equal either. Instead,
those checks should be `x.satisfies("@1.2.3")` which works both for git versions and
custom version suffixes.
- `GitVersion` from commit will now print as `<hash>=<version>` once the
git ref is resolved to a spack version. This is for reliability -- version is frozen
when added to the database and queried later. It also improves performance
since there is no need to clone all repos of all git versions after `spack clean -m`
is run and something queries the database, triggering version comparison, such
as potentially reuse concretization.
- The "empty VerstionStrComponent trick" for `GitVerison` is dropped since it wasn't
representable as a version string (by design). Instead, it's replaced by `git`,
so you get `1.2.3.git.4` (which reads 4 commits after a tag 1.2.3). This means
that there's an edge case for version schemes `1.1.1`, `1.1.1a`, since the
generated git version `1.1.1.git.1` (1 commit after `1.1.1`) compares larger
than `1.1.1a`, since `a < git` are compared as strings. This is currently a
wont-fix edge case, but if really required, could be fixed by special casing
the `git` string.
- Saved, concrete specs (database, lock file, ...) that only had a git sha as their
version, but have no means to look the effective Spack version anymore, will
now see their version mapped to `hash=develop`. Previously these specs
would always have their sha literally interpreted as a version string (even when
it _could_ be looked up). This only applies to databases, lock files and spec.json
files created before Spack 0.20; after this PR, we always have a Spack version
associated to the relevant GitVersion).
- Fixes a bug where previously `to_dict` / `from_dict` (de)serialization would not
reattach the repo to the GitVersion, causing the git hash to be used as a literal
(bogus) version instead of the resolved version. This was in particularly breaking
version comparison in the build process on macOS/Windows.
## Installing or matching specific versions
- In the past, `spack install pkg@3.2` would install `pkg@=3.2` if it was a
known specific version defined in the package, even when newer patch releases
`3.2.1`, `3.2.2`, `...` were available. This behavior was only there because
there was no syntax to distinguish between `3.2` and `3.2.1`. Since there is
syntax for this now through `pkg@=3.2`, the old exact matching behavior is
removed. This means that `spack install pkg@3.2` constrains the `pkg` version
to the range `3.2`, and `spack install pkg@=3.2` constrains it to the specific
version `3.2`.
- Also in directives such as `depends_on("pkg@2.3")` and their when
conditions `conflicts("...", when="@2.3")` ranges are ranges, and specific
version matches require `@=2.3.`.
- No matching version: in the case `pkg@3.2` matches nothing, concretization
errors. However, if you run `spack install pkg@=3.2` and this version
doesn't exist, Spack will define it; this allows you to install non-registered
versions.
- For consistency, you can now do `%gcc@10` and let it match a configured
`10.x.y` compiler. It errors when there is no matching compiler.
In the past it was interpreted like a specific `gcc@=10` version, which
would get bootstrapped.
- When compiler _bootstrapping_ is enabled, `%gcc@=10.2.0` can be used to
bootstrap a specific compiler version.
## Other changes
- Externals, compilers, and develop spec definitions are backwards compatible.
They are typically defined as `pkg@3.2.1` even though they should be
saying `pkg@=3.2.1`. Spack now transforms `pkg@3` into `pkg@=3` in those cases.
- Finally, fix strictness of `version(...)` directive/declaration. It just does a simple
type check, and now requires strings/integers. Floats are not allowed because
they are ambiguous `str(3.10) == "3.1"`.
2023-05-06 12:04:41 +08:00
In cases where Spack cannot resolve a sensible version from a git ref,
users can specify the Spack version to use for the git ref. This is done
by appending `` = `` and the Spack version to the git ref. For example:
2022-08-05 04:20:33 +08:00
2022-08-05 10:01:03 +08:00
.. code-block :: sh
2022-08-05 04:20:33 +08:00
foo@git.my_ref=3.2 # use the my_ref tag or branch, but treat it as version 3.2 for version comparisons
foo@git.abcdef1234abcdef1234abcdef1234abcdef1234=develop # use the given commit, but treat it as develop for version comparisons
2013-12-19 03:02:31 +08:00
Details about how versions are compared and how Spack determines if
one version is less than another are discussed in the developer guide.
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
Compiler specifier
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
A compiler specifier comes somewhere after a package name and starts
with `` % `` . It tells Spack what compiler(s) a particular package
should be built with. After the `` % `` should come the name of some
registered Spack compiler. This might include `` gcc `` , or `` intel `` ,
but the specific compilers available depend on the site. You can run
`` spack compilers `` to get a list; more on this below.
The compiler spec can be followed by an optional *compiler version* .
A compiler version specifier looks exactly like a package version
specifier. Version specifiers will associate with the nearest package
name or compiler specifier to their left in the spec.
If the compiler spec is omitted, Spack will choose a default compiler
based on site policies.
2018-08-30 12:09:34 +08:00
.. _basic-variants:
2016-08-24 06:03:29 +08:00
^^^^^^^^
2013-12-19 03:02:31 +08:00
Variants
2016-08-24 06:03:29 +08:00
^^^^^^^^
2013-12-19 03:02:31 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
Variants are named options associated with a particular package and are
typically used to enable or disable certain features at build time. They
are optional, as each package must provide default values for each variant
it makes available.
The names of variants available for a particular package depend on
2016-08-27 05:41:00 +08:00
what was provided by the package author. `` spack info <package> `` will
2013-12-19 03:02:31 +08:00
provide information on what build variants are available.
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
There are different types of variants:
2016-05-26 01:56:12 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
1. Boolean variants. Typically used to enable or disable a feature at
compile time. For example, a package might have a `` debug `` variant that
can be explicitly enabled with `` +debug `` and disabled with `` ~debug `` .
2. Single-valued variants. Often used to set defaults. For example, a package
might have a `` compression `` variant that determines the default
compression algorithm, which users could set to `` compression=gzip `` or
`` compression=zstd `` .
3. Multi-valued variants. A package might have a `` fabrics `` variant that
determines which network fabrics to support. Users could set this to
`` fabrics=verbs,ofi `` to enable both InfiniBand verbs and OpenFabrics
interfaces. The values are separated by commas.
2013-12-19 03:02:31 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
The meaning of `` fabrics=verbs,ofi `` is to enable *at least* the specified
fabrics, but other fabrics may be enabled as well. If the intent is to
enable *only* the specified fabrics, then the `` fabrics:=verbs,ofi ``
syntax should be used with the `` := `` operator.
2013-12-19 03:02:31 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
.. note ::
2013-12-19 03:02:31 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
In certain shells, the the `` ~ `` character is expanded to the home
directory. To avoid these issues, avoid whitespace between the package
name and the variant:
2013-12-19 03:02:31 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
.. code-block :: sh
2013-12-19 03:02:31 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
mpileaks ~debug # shell may try to substitute this!
mpileaks~debug # use this instead
Alternatively, you can use the `` - `` character to disable a variant,
but be aware that this requires a space between the package name and
the variant:
.. code-block :: sh
mpileaks-debug # wrong: refers to a package named "mpileaks-debug"
mpileaks -debug # right: refers to a package named mpileaks with debug disabled
As a last resort, `` debug=False `` can also be used to disable a boolean variant.
2013-12-19 03:02:31 +08:00
Concrete multi-valued variants (#49756)
Similar to the range-or-specific-version ambiguity of `@1.2` in the past,
which was solved with `@1.2` vs `@=1.2` we still have the ambiguity of
`name=a,b,c` in multi-valued variants. Do they mean "at least a,b,c" or
"exactly a,b,c"?
This issue comes up in for example `gcc languages=c,cxx`; there's no
way to exclude `fortran`.
The ambiguity is resolved with syntax `:=` to distinguish concrete from
abstract.
The following strings parse as **concrete** variants:
* `name:=a,b,c` => values exactly {a, b, c}
* `name:=a` => values exactly {a}
* `+name` => values exactly {True}
* `~name` => values exactly {False}
The following strings parse as **abstract** variants:
* `name=a,b,c` values at least {a, b, c}
* `name=*` special case for testing existence of a variant; values are at
least the empty set {}
As a reminder
* `satisfies(lhs, rhs)` means `concretizations(lhs)` ⊆ `concretizations(rhs)`
* `intersects(lhs, rhs)` means `concretizations(lhs)` ∩ `concretizations(rhs)` ≠ ∅
where `concretizations(...)` is the set of sets of variant values in this case.
The satisfies semantics are:
* rhs abstract: rhs values is a subset of lhs values (whether lhs is abstract or concrete)
* lhs concrete, rhs concrete: set equality
* lhs abstract, rhs concrete: false
and intersects should mean
* lhs and rhs abstract: true (the union is a valid concretization under both)
* lhs or rhs abstract: true iff the abstract variant's values are a subset of the concrete one
* lhs concrete, rhs concrete: set equality
Concrete specs with single-valued variants are printed `+foo`, `~foo` and `foo=bar`;
only multi-valued variants are printed with `foo:=bar,baz` to reduce the visual noise.
2025-04-04 12:47:43 +08:00
"""""""""""""""""""""""""""""""""""
Variant propagation to dependencies
"""""""""""""""""""""""""""""""""""
2013-12-19 03:02:31 +08:00
2022-03-29 05:18:00 +08:00
Spack allows variants to propagate their value to the package's
dependency by using `` ++ `` , `` -- `` , and `` ~~ `` for boolean variants.
For example, for a `` debug `` variant:
.. code-block :: sh
mpileaks ++debug # enabled debug will be propagated to dependencies
mpileaks +debug # only mpileaks will have debug enabled
To propagate the value of non-boolean variants Spack uses `` name==value `` .
For example, for the `` stackstart `` variant:
.. code-block :: sh
2022-11-16 08:06:12 +08:00
mpileaks stackstart==4 # variant will be propagated to dependencies
mpileaks stackstart=4 # only mpileaks will have this variant value
2022-03-29 05:18:00 +08:00
2024-11-06 16:53:52 +08:00
Spack also allows variants to be propagated from a package that does
not have that variant.
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2016-05-26 01:56:12 +08:00
Compiler Flags
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2016-05-26 01:56:12 +08:00
Compiler flags are specified using the same syntax as non-boolean variants,
but fulfill a different purpose. While the function of a variant is set by
the package, compiler flags are used by the compiler wrappers to inject
2022-03-29 05:18:00 +08:00
flags into the compile line of the build. Additionally, compiler flags can
be inherited by dependencies by using `` == `` .
`` spack install libdwarf cppflags=="-g" `` will install both libdwarf and
libelf with the `` -g `` flag injected into their compile line.
.. note ::
versions of spack prior to 0.19.0 will propagate compiler flags using
the `` = `` syntax.
2016-05-26 01:56:12 +08:00
2017-01-16 11:17:54 +08:00
Notice that the value of the compiler flags must be quoted if it
contains any spaces. Any of `` cppflags=-O3 `` , `` cppflags="-O3" `` ,
`` cppflags='-O3' `` , and `` cppflags="-O3 -fPIC" `` are acceptable, but
2019-03-12 02:19:13 +08:00
`` cppflags=-O3 -fPIC `` is not. Additionally, if the value of the
2017-01-16 11:17:54 +08:00
compiler flags is not the last thing on the line, it must be followed
2020-04-02 01:02:26 +08:00
by a space. The command `` spack install libelf cppflags="-O3"%intel ``
2019-03-12 02:19:13 +08:00
will be interpreted as an attempt to set `` cppflags="-O3%intel" `` .
2016-05-26 01:56:12 +08:00
The six compiler flags are injected in the order of implicit make commands
2016-08-27 05:41:00 +08:00
in GNU Autotools. If all flags are set, the order is
`` $cppflags $cflags|$cxxflags $ldflags <command> $ldlibs `` for C and C++ and
`` $fflags $cppflags $ldflags <command> $ldlibs `` for Fortran.
2016-05-26 01:56:12 +08:00
2016-11-10 00:00:34 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compiler environment variables and additional RPATHs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020-01-28 00:40:47 +08:00
Sometimes compilers require setting special environment variables to
operate correctly. Spack handles these cases by allowing custom environment
modifications in the `` environment `` attribute of the compiler configuration
section. See also the :ref: `configuration_environment_variables` section
of the configuration files docs for more information.
It is also possible to specify additional `` RPATHs `` that the
2018-09-06 01:56:45 +08:00
compiler will add to all executables generated by that compiler. This is
useful for forcing certain compilers to RPATH their own runtime libraries, so
that executables will run without the need to set `` LD_LIBRARY_PATH `` .
2016-11-10 00:00:34 +08:00
.. code-block :: yaml
2025-04-02 15:33:23 +08:00
packages:
gcc:
externals:
- spec: gcc@4.9.3
prefix: /opt/gcc
extra_attributes:
compilers:
c: /opt/gcc/bin/gcc
cxx: /opt/gcc/bin/g++
fortran: /opt/gcc/bin/gfortran
environment:
unset:
- BAD_VARIABLE
set:
GOOD_VARIABLE_NUM: 1
GOOD_VARIABLE_STR: good
prepend_path:
PATH: /path/to/binutils
append_path:
LD_LIBRARY_PATH: /opt/gcc/lib
extra_rpaths:
- /path/to/some/compiler/runtime/directory
- /path/to/some/other/compiler/runtime/directory
2016-11-10 00:00:34 +08:00
2018-09-06 01:56:45 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^
2016-05-26 01:56:12 +08:00
Architecture specifiers
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
targets: Spack targets can now be fine-grained microarchitectures
Spack can now:
- label ppc64, ppc64le, x86_64, etc. builds with specific
microarchitecture-specific names, like 'haswell', 'skylake' or
'icelake'.
- detect the host architecture of a machine from /proc/cpuinfo or similar
tools.
- Understand which microarchitectures are compatible with which (for
binary reuse)
- Understand which compiler flags are needed (for GCC, so far) to build
binaries for particular microarchitectures.
All of this is managed through a JSON file (microarchitectures.json) that
contains detailed auto-detection, compiler flag, and compatibility
information for specific microarchitecture targets. The `llnl.util.cpu`
module implements a library that allows detection and comparison of
microarchitectures based on the data in this file.
The `target` part of Spack specs is now essentially a Microarchitecture
object, and Specs' targets can be compared for compatibility as well.
This allows us to label optimized binary packages at a granularity that
enables them to be reused on compatible machines. Previously, we only
knew that a package was built for x86_64, NOT which x86_64 machines it
was usable on.
Currently this feature supports Intel, Power, and AMD chips. Support for
ARM is forthcoming.
Specifics:
- Add microarchitectures.json with descriptions of architectures
- Relaxed semantic of compiler's "target" attribute. Before this change
the semantic to check if a compiler could be viable for a given target
was exact match. This made sense as the finest granularity of targets
was architecture families. As now we can target micro-architectures,
this commit changes the semantic by interpreting as the architecture
family what is stored in the compiler's "target" attribute. A compiler
is then a viable choice if the target being concretized belongs to the
same family. Similarly when a new compiler is detected the architecture
family is stored in the "target" attribute.
- Make Spack's `cc` compiler wrapper inject target-specific flags on the
command line
- Architecture concretization updated to use the same algorithm as
compiler concretization
- Micro-architecture features, vendor, generation etc. are included in
the package hash. Generic architectures, such as x86_64 or ppc64, are
still dumped using the name only.
- If the compiler for a target is not supported exit with an intelligible
error message. If the compiler support is unknown don't try to use
optimization flags.
- Support and define feature aliases (e.g., sse3 -> ssse3) in
microarchitectures.json and on Microarchitecture objects. Feature
aliases are defined in targets.json and map a name (the "alias") to a
list of rules that must be met for the test to be successful. The rules
that are available can be extended later using a decorator.
- Implement subset semantics for comparing microarchitectures (treat
microarchitectures as a partial order, i.e. (a < b), (a == b) and (b <
a) can all be false.
- Implement logic to automatically demote the default target if the
compiler being used is too old to optimize for it. Updated docs to make
this behavior explicit. This avoids surprising the user if the default
compiler is older than the host architecture.
This commit adds unit tests to verify the semantics of target ranges and
target lists in constraints. The implementation to allow target ranges
and lists is minimal and doesn't add any new type. A more careful
refactor that takes into account the type system might be due later.
Co-authored-by: Gregory Becker <becker33.llnl.gov>
2019-06-19 21:47:07 +08:00
Each node in the dependency graph of a spec has an architecture attribute.
This attribute is a triplet of platform, operating system and processor.
You can specify the elements either separately, by using
the reserved keywords `` platform `` , `` os `` and `` target `` :
.. code-block :: console
$ spack install libelf platform=linux
$ spack install libelf os=ubuntu18.04
$ spack install libelf target=broadwell
2019-09-24 16:18:48 +08:00
Normally users don't have to bother specifying the architecture if they
are installing software for their current host, as in that case the
values will be detected automatically. If you need fine-grained control
over which packages use which targets (or over *all* packages' default
2022-02-13 17:26:53 +08:00
target), see :ref: `package-preferences` .
targets: Spack targets can now be fine-grained microarchitectures
Spack can now:
- label ppc64, ppc64le, x86_64, etc. builds with specific
microarchitecture-specific names, like 'haswell', 'skylake' or
'icelake'.
- detect the host architecture of a machine from /proc/cpuinfo or similar
tools.
- Understand which microarchitectures are compatible with which (for
binary reuse)
- Understand which compiler flags are needed (for GCC, so far) to build
binaries for particular microarchitectures.
All of this is managed through a JSON file (microarchitectures.json) that
contains detailed auto-detection, compiler flag, and compatibility
information for specific microarchitecture targets. The `llnl.util.cpu`
module implements a library that allows detection and comparison of
microarchitectures based on the data in this file.
The `target` part of Spack specs is now essentially a Microarchitecture
object, and Specs' targets can be compared for compatibility as well.
This allows us to label optimized binary packages at a granularity that
enables them to be reused on compatible machines. Previously, we only
knew that a package was built for x86_64, NOT which x86_64 machines it
was usable on.
Currently this feature supports Intel, Power, and AMD chips. Support for
ARM is forthcoming.
Specifics:
- Add microarchitectures.json with descriptions of architectures
- Relaxed semantic of compiler's "target" attribute. Before this change
the semantic to check if a compiler could be viable for a given target
was exact match. This made sense as the finest granularity of targets
was architecture families. As now we can target micro-architectures,
this commit changes the semantic by interpreting as the architecture
family what is stored in the compiler's "target" attribute. A compiler
is then a viable choice if the target being concretized belongs to the
same family. Similarly when a new compiler is detected the architecture
family is stored in the "target" attribute.
- Make Spack's `cc` compiler wrapper inject target-specific flags on the
command line
- Architecture concretization updated to use the same algorithm as
compiler concretization
- Micro-architecture features, vendor, generation etc. are included in
the package hash. Generic architectures, such as x86_64 or ppc64, are
still dumped using the name only.
- If the compiler for a target is not supported exit with an intelligible
error message. If the compiler support is unknown don't try to use
optimization flags.
- Support and define feature aliases (e.g., sse3 -> ssse3) in
microarchitectures.json and on Microarchitecture objects. Feature
aliases are defined in targets.json and map a name (the "alias") to a
list of rules that must be met for the test to be successful. The rules
that are available can be extended later using a decorator.
- Implement subset semantics for comparing microarchitectures (treat
microarchitectures as a partial order, i.e. (a < b), (a == b) and (b <
a) can all be false.
- Implement logic to automatically demote the default target if the
compiler being used is too old to optimize for it. Updated docs to make
this behavior explicit. This avoids surprising the user if the default
compiler is older than the host architecture.
This commit adds unit tests to verify the semantics of target ranges and
target lists in constraints. The implementation to allow target ranges
and lists is minimal and doesn't add any new type. A more careful
refactor that takes into account the type system might be due later.
Co-authored-by: Gregory Becker <becker33.llnl.gov>
2019-06-19 21:47:07 +08:00
.. _support-for-microarchitectures:
"""""""""""""""""""""""""""""""""""""""
Support for specific microarchitectures
"""""""""""""""""""""""""""""""""""""""
Spack knows how to detect and optimize for many specific microarchitectures
(including recent Intel, AMD and IBM chips) and encodes this information in
the `` target `` portion of the architecture specification. A complete list of
the microarchitectures known to Spack can be obtained in the following way:
.. command-output :: spack arch --known-targets
When a spec is installed Spack matches the compiler being used with the
microarchitecture being targeted to inject appropriate optimization flags
at compile time. Giving a command such as the following:
.. code-block :: console
$ spack install zlib%gcc@9.0.1 target=icelake
will produce compilation lines similar to:
.. code-block :: console
$ /usr/bin/gcc-9 -march=icelake-client -mtune=icelake-client -c ztest10532.c
$ /usr/bin/gcc-9 -march=icelake-client -mtune=icelake-client -c -fPIC -O2 ztest10532.
...
where the flags `` -march=icelake-client -mtune=icelake-client `` are injected
by Spack based on the requested target and compiler.
If Spack knows that the requested compiler can't optimize for the current target
or can't build binaries for that target at all, it will exit with a meaningful error message:
.. code-block :: console
$ spack install zlib%gcc@5.5.0 target=icelake
==> Error: cannot produce optimized binary for micro-architecture "icelake" with gcc@5.5.0 [supported compiler versions are 8:]
When instead an old compiler is selected on a recent enough microarchitecture but there is
no explicit `` target `` specification, Spack will optimize for the best match it can find instead
of failing:
.. code-block :: console
$ spack arch
linux-ubuntu18.04-broadwell
$ spack spec zlib%gcc@4.8
Input spec
--------------------------------
zlib%gcc@4.8
Concretized
--------------------------------
zlib@1.2.11%gcc@4.8+optimize+pic+shared arch=linux-ubuntu18.04-haswell
$ spack spec zlib%gcc@9.0.1
Input spec
--------------------------------
zlib%gcc@9.0.1
Concretized
--------------------------------
zlib@1.2.11%gcc@9.0.1+optimize+pic+shared arch=linux-ubuntu18.04-broadwell
In the snippet above, for instance, the microarchitecture was demoted to `` haswell `` when
compiling with `` gcc@4.8 `` since support to optimize for `` broadwell `` starts from `` gcc@4.9: `` .
2020-02-26 17:03:03 +08:00
Finally, if Spack has no information to match compiler and target, it will
targets: Spack targets can now be fine-grained microarchitectures
Spack can now:
- label ppc64, ppc64le, x86_64, etc. builds with specific
microarchitecture-specific names, like 'haswell', 'skylake' or
'icelake'.
- detect the host architecture of a machine from /proc/cpuinfo or similar
tools.
- Understand which microarchitectures are compatible with which (for
binary reuse)
- Understand which compiler flags are needed (for GCC, so far) to build
binaries for particular microarchitectures.
All of this is managed through a JSON file (microarchitectures.json) that
contains detailed auto-detection, compiler flag, and compatibility
information for specific microarchitecture targets. The `llnl.util.cpu`
module implements a library that allows detection and comparison of
microarchitectures based on the data in this file.
The `target` part of Spack specs is now essentially a Microarchitecture
object, and Specs' targets can be compared for compatibility as well.
This allows us to label optimized binary packages at a granularity that
enables them to be reused on compatible machines. Previously, we only
knew that a package was built for x86_64, NOT which x86_64 machines it
was usable on.
Currently this feature supports Intel, Power, and AMD chips. Support for
ARM is forthcoming.
Specifics:
- Add microarchitectures.json with descriptions of architectures
- Relaxed semantic of compiler's "target" attribute. Before this change
the semantic to check if a compiler could be viable for a given target
was exact match. This made sense as the finest granularity of targets
was architecture families. As now we can target micro-architectures,
this commit changes the semantic by interpreting as the architecture
family what is stored in the compiler's "target" attribute. A compiler
is then a viable choice if the target being concretized belongs to the
same family. Similarly when a new compiler is detected the architecture
family is stored in the "target" attribute.
- Make Spack's `cc` compiler wrapper inject target-specific flags on the
command line
- Architecture concretization updated to use the same algorithm as
compiler concretization
- Micro-architecture features, vendor, generation etc. are included in
the package hash. Generic architectures, such as x86_64 or ppc64, are
still dumped using the name only.
- If the compiler for a target is not supported exit with an intelligible
error message. If the compiler support is unknown don't try to use
optimization flags.
- Support and define feature aliases (e.g., sse3 -> ssse3) in
microarchitectures.json and on Microarchitecture objects. Feature
aliases are defined in targets.json and map a name (the "alias") to a
list of rules that must be met for the test to be successful. The rules
that are available can be extended later using a decorator.
- Implement subset semantics for comparing microarchitectures (treat
microarchitectures as a partial order, i.e. (a < b), (a == b) and (b <
a) can all be false.
- Implement logic to automatically demote the default target if the
compiler being used is too old to optimize for it. Updated docs to make
this behavior explicit. This avoids surprising the user if the default
compiler is older than the host architecture.
This commit adds unit tests to verify the semantics of target ranges and
target lists in constraints. The implementation to allow target ranges
and lists is minimal and doesn't add any new type. A more careful
refactor that takes into account the type system might be due later.
Co-authored-by: Gregory Becker <becker33.llnl.gov>
2019-06-19 21:47:07 +08:00
proceed with the installation but avoid injecting any microarchitecture
specific flags.
.. warning ::
2020-02-26 17:03:03 +08:00
Currently, Spack doesn't print any warning to the user if it has no information
targets: Spack targets can now be fine-grained microarchitectures
Spack can now:
- label ppc64, ppc64le, x86_64, etc. builds with specific
microarchitecture-specific names, like 'haswell', 'skylake' or
'icelake'.
- detect the host architecture of a machine from /proc/cpuinfo or similar
tools.
- Understand which microarchitectures are compatible with which (for
binary reuse)
- Understand which compiler flags are needed (for GCC, so far) to build
binaries for particular microarchitectures.
All of this is managed through a JSON file (microarchitectures.json) that
contains detailed auto-detection, compiler flag, and compatibility
information for specific microarchitecture targets. The `llnl.util.cpu`
module implements a library that allows detection and comparison of
microarchitectures based on the data in this file.
The `target` part of Spack specs is now essentially a Microarchitecture
object, and Specs' targets can be compared for compatibility as well.
This allows us to label optimized binary packages at a granularity that
enables them to be reused on compatible machines. Previously, we only
knew that a package was built for x86_64, NOT which x86_64 machines it
was usable on.
Currently this feature supports Intel, Power, and AMD chips. Support for
ARM is forthcoming.
Specifics:
- Add microarchitectures.json with descriptions of architectures
- Relaxed semantic of compiler's "target" attribute. Before this change
the semantic to check if a compiler could be viable for a given target
was exact match. This made sense as the finest granularity of targets
was architecture families. As now we can target micro-architectures,
this commit changes the semantic by interpreting as the architecture
family what is stored in the compiler's "target" attribute. A compiler
is then a viable choice if the target being concretized belongs to the
same family. Similarly when a new compiler is detected the architecture
family is stored in the "target" attribute.
- Make Spack's `cc` compiler wrapper inject target-specific flags on the
command line
- Architecture concretization updated to use the same algorithm as
compiler concretization
- Micro-architecture features, vendor, generation etc. are included in
the package hash. Generic architectures, such as x86_64 or ppc64, are
still dumped using the name only.
- If the compiler for a target is not supported exit with an intelligible
error message. If the compiler support is unknown don't try to use
optimization flags.
- Support and define feature aliases (e.g., sse3 -> ssse3) in
microarchitectures.json and on Microarchitecture objects. Feature
aliases are defined in targets.json and map a name (the "alias") to a
list of rules that must be met for the test to be successful. The rules
that are available can be extended later using a decorator.
- Implement subset semantics for comparing microarchitectures (treat
microarchitectures as a partial order, i.e. (a < b), (a == b) and (b <
a) can all be false.
- Implement logic to automatically demote the default target if the
compiler being used is too old to optimize for it. Updated docs to make
this behavior explicit. This avoids surprising the user if the default
compiler is older than the host architecture.
This commit adds unit tests to verify the semantics of target ranges and
target lists in constraints. The implementation to allow target ranges
and lists is minimal and doesn't add any new type. A more careful
refactor that takes into account the type system might be due later.
Co-authored-by: Gregory Becker <becker33.llnl.gov>
2019-06-19 21:47:07 +08:00
on which optimization flags should be used for a given compiler. This behavior
might change in the future.
2013-12-19 03:02:31 +08:00
.. _sec-virtual-dependencies:
2013-12-12 20:25:31 +08:00
2016-08-24 06:03:29 +08:00
--------------------
2013-12-12 20:25:31 +08:00
Virtual dependencies
2016-08-24 06:03:29 +08:00
--------------------
2013-12-12 20:25:31 +08:00
2020-02-26 17:03:03 +08:00
The dependency graph for `` mpileaks `` we saw above wasn't *quite*
2013-12-19 03:02:31 +08:00
accurate. `` mpileaks `` uses MPI, which is an interface that has many
different implementations. Above, we showed `` mpileaks `` and
`` callpath `` depending on `` mpich `` , which is one *particular*
implementation of MPI. However, we could build either with another
implementation, such as `` openmpi `` or `` mvapich `` .
2013-12-12 20:25:31 +08:00
2013-12-19 03:02:31 +08:00
Spack represents interfaces like this using *virtual dependencies* .
The real dependency DAG for `` mpileaks `` looks like this:
2013-12-12 20:25:31 +08:00
2013-12-19 03:02:31 +08:00
.. graphviz ::
2013-12-12 20:25:31 +08:00
2013-12-19 03:02:31 +08:00
digraph {
mpi [color=red]
mpileaks -> mpi
mpileaks -> callpath -> mpi
callpath -> dyninst
dyninst -> libdwarf -> libelf
dyninst -> libelf
}
Notice that `` mpich `` has now been replaced with `` mpi `` . There is no
*real* MPI package, but some packages *provide* the MPI interface, and
these packages can be substituted in for `` mpi `` when `` mpileaks `` is
built.
You can see what virtual packages a particular package provides by
getting info on it:
2022-11-02 05:29:50 +08:00
.. command-output :: spack info --virtuals mpich
2013-12-19 03:02:31 +08:00
Spack is unique in that its virtual packages can be versioned, just
like regular packages. A particular version of a package may provide
a particular version of a virtual package, and we can see above that
2014-07-08 17:41:29 +08:00
`` mpich `` versions `` 1 `` and above provide all `` mpi `` interface
versions up to `` 1 `` , and `` mpich `` versions `` 3 `` and above provide
`` mpi `` versions up to `` 3 `` . A package can *depend on* a particular
version of a virtual package, e.g. if an application needs MPI-2
functions, it can depend on `` mpi@2: `` to indicate that it needs some
implementation that provides MPI-2 functions.
2013-12-19 03:02:31 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2013-12-19 03:36:55 +08:00
Constraining virtual packages
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2013-12-19 03:36:55 +08:00
When installing a package that depends on a virtual package, you can
opt to specify the particular provider you want to use, or you can let
2016-08-27 05:41:00 +08:00
Spack pick. For example, if you just type this:
.. code-block :: console
2013-12-19 03:36:55 +08:00
2016-08-27 05:41:00 +08:00
$ spack install mpileaks
2013-12-19 03:36:55 +08:00
Then spack will pick a provider for you according to site policies.
2016-08-27 05:41:00 +08:00
If you really want a particular version, say `` mpich `` , then you could
run this instead:
2013-12-19 03:36:55 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
$ spack install mpileaks ^mpich
2013-12-19 03:36:55 +08:00
This forces spack to use some version of `` mpich `` for its
implementation. As always, you can be even more specific and require
2016-08-27 05:41:00 +08:00
a particular `` mpich `` version:
.. code-block :: console
2013-12-19 03:36:55 +08:00
2016-08-27 05:41:00 +08:00
$ spack install mpileaks ^mpich@3
2013-12-19 03:36:55 +08:00
2014-01-15 15:50:50 +08:00
The `` mpileaks `` package in particular only needs MPI-1 commands, so
any MPI implementation will do. If another package depends on
`` mpi@2 `` and you try to give it an insufficient MPI implementation
(e.g., one that provides only `` mpi@:1 `` ), then Spack will raise an
error. Likewise, if you try to plug in some package that doesn't
provide MPI, Spack will raise an error.
2013-12-19 03:36:55 +08:00
2023-11-02 14:35:23 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Explicit binding of virtual dependencies
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There are packages that provide more than just one virtual dependency. When interacting with them, users
might want to utilize just a subset of what they could provide, and use other providers for virtuals they
need.
It is possible to be more explicit and tell Spack which dependency should provide which virtual, using a
special syntax:
.. code-block :: console
$ spack spec strumpack ^[virtuals=mpi] intel-parallel-studio+mkl ^[virtuals=lapack] openblas
Concretizing the spec above produces the following DAG:
.. figure :: images/strumpack_virtuals.svg
:scale: 60 %
:align: center
where `` intel-parallel-studio `` *could* provide `` mpi `` , `` lapack `` , and `` blas `` but is used only for the former. The `` lapack ``
and `` blas `` dependencies are satisfied by `` openblas `` .
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^
2016-05-26 01:56:12 +08:00
Specifying Specs by Hash
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^
2016-05-26 01:56:12 +08:00
Complicated specs can become cumbersome to enter on the command line,
2017-08-01 04:13:39 +08:00
especially when many of the qualifications are necessary to distinguish
between similar installs. To avoid this, when referencing an existing spec,
2016-05-26 01:56:12 +08:00
Spack allows you to reference specs by their hash. We previously
discussed the spec hash that Spack computes. In place of a spec in any
command, substitute `` /<hash> `` where `` <hash> `` is any amount from
2017-08-01 04:13:39 +08:00
the beginning of a spec hash.
2016-05-26 01:56:12 +08:00
2017-08-01 04:13:39 +08:00
For example, lets say that you accidentally installed two different
`` mvapich2 `` installations. If you want to uninstall one of them but don't
know what the difference is, you can run:
.. code-block :: console
$ spack find --long mvapich2
==> 2 installed packages.
-- linux-centos7-x86_64 / gcc@6.3.0 ----------
qmt35td mvapich2@2.2%gcc
er3die3 mvapich2@2.2%gcc
You can then uninstall the latter installation using:
.. code-block :: console
$ spack uninstall /er3die3
Or, if you want to build with a specific installation as a dependency,
you can use:
.. code-block :: console
$ spack install trilinos ^/er3die3
If the given spec hash is sufficiently long as to be unique, Spack will
replace the reference with the spec to which it refers. Otherwise, it will
prompt for a more qualified hash.
Note that this will not work to reinstall a dependency uninstalled by
2016-08-27 05:41:00 +08:00
`` spack uninstall --force `` .
2016-05-26 01:56:12 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-providers:
2015-02-24 18:33:29 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
`` spack providers ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^^^^^^
2013-12-19 03:02:31 +08:00
You can see what packages provide a particular virtual package using
`` spack providers `` . If you wanted to see what packages provide
`` mpi `` , you would just run:
.. command-output :: spack providers mpi
And if you *only* wanted to see packages that provide MPI-2, you would
add a version specifier to the spec:
.. command-output :: spack providers mpi@2
2013-12-12 20:25:31 +08:00
2013-12-19 03:02:31 +08:00
Notice that the package versions that provide insufficient MPI
versions are now filtered out.
2014-10-27 16:31:53 +08:00
2020-10-24 13:16:01 +08:00
-----------------------------
Deprecating insecure packages
-----------------------------
`` spack deprecate `` allows for the removal of insecure packages with
minimal impact to their dependents.
.. warning ::
The `` spack deprecate `` command is designed for use only in
extraordinary circumstances. This is a VERY big hammer to be used
with care.
The `` spack deprecate `` command will remove one package and replace it
with another by replacing the deprecated package's prefix with a link
to the deprecator package's prefix.
.. warning ::
The `` spack deprecate `` command makes no promises about binary
compatibility. It is up to the user to ensure the deprecator is
suitable for the deprecated package.
Spack tracks concrete deprecated specs and ensures that no future packages
concretize to a deprecated spec.
The first spec given to the `` spack deprecate `` command is the package
to deprecate. It is an abstract spec that must describe a single
installed package. The second spec argument is the deprecator
spec. By default it must be an abstract spec that describes a single
installed package, but with the `` -i/--install-deprecator `` it can be
any abstract spec that Spack will install and then use as the
deprecator. The `` -I/--no-install-deprecator `` option will ensure
the default behavior.
By default, `` spack deprecate `` will deprecate all dependencies of the
deprecated spec, replacing each by the dependency of the same name in
the deprecator spec. The `` -d/--dependencies `` option will ensure the
default, while the `` -D/--no-dependencies `` option will deprecate only
the root of the deprecate spec in favor of the root of the deprecator
spec.
`` spack deprecate `` can use symbolic links or hard links. The default
behavior is symbolic links, but the `` -l/--link-type `` flag can take
options `` hard `` or `` soft `` .
-----------------------
Verifying installations
-----------------------
The `` spack verify `` command can be used to verify the validity of
Spack-installed packages any time after installation.
2025-02-24 18:28:06 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^
`` spack verify manifest ``
^^^^^^^^^^^^^^^^^^^^^^^^^
2020-10-24 13:16:01 +08:00
At installation time, Spack creates a manifest of every file in the
installation prefix. For links, Spack tracks the mode, ownership, and
destination. For directories, Spack tracks the mode, and
ownership. For files, Spack tracks the mode, ownership, modification
2025-02-24 18:28:06 +08:00
time, hash, and size. The `` spack verify manifest `` command will check,
for every file in each package, whether any of those attributes have
changed. It will also check for newly added files or deleted files from
the installation prefix. Spack can either check all installed packages
2020-10-24 13:16:01 +08:00
using the `-a,--all` or accept specs listed on the command line to
verify.
2025-02-24 18:28:06 +08:00
The `` spack verify manifest `` command can also verify for individual files
that they haven't been altered since installation time. If the given file
2020-10-24 13:16:01 +08:00
is not in a Spack installation prefix, Spack will report that it is
not owned by any package. To check individual files instead of specs,
use the `` -f,--files `` option.
Spack installation manifests are part of the tarball signed by Spack
for binary package distribution. When installed from a binary package,
Spack uses the packaged installation manifest instead of creating one
at install time.
The `` spack verify `` command also accepts the `` -l,--local `` option to
check only local packages (as opposed to those used transparently from
`` upstream `` spack instances) and the `` -j,--json `` option to output
machine-readable json data for any errors.
2025-02-24 18:28:06 +08:00
^^^^^^^^^^^^^^^^^^^^^^^^^^
`` spack verify libraries ``
^^^^^^^^^^^^^^^^^^^^^^^^^^
The `` spack verify libraries `` command can be used to verify that packages
do not have accidental system dependencies. This command scans the install
prefixes of packages for executables and shared libraries, and resolves
their needed libraries in their RPATHs. When needed libraries cannot be
located, an error is reported. This typically indicates that a package
was linked against a system library, instead of a library provided by
a Spack package.
This verification can also be enabled as a post-install hook by setting
`` config:shared_linking:missing_library_policy `` to `` error `` or `` warn ``
in :ref: `config.yaml <config-yaml>` .
2016-08-24 06:03:29 +08:00
-----------------------
2016-05-11 02:19:17 +08:00
Filesystem requirements
2016-08-24 06:03:29 +08:00
-----------------------
2016-05-11 01:46:24 +08:00
2018-05-19 05:41:03 +08:00
By default, Spack needs to be run from a filesystem that supports
2016-05-11 02:19:17 +08:00
`` flock `` locking semantics. Nearly all local filesystems and recent
2018-05-19 05:41:03 +08:00
versions of NFS support this, but parallel filesystems or NFS volumes may
be configured without `` flock `` support enabled. You can determine how
your filesystems are mounted with `` mount `` . The output for a Lustre
2016-05-11 02:19:17 +08:00
filesystem might look like this:
2016-05-11 01:46:24 +08:00
2016-08-27 05:41:00 +08:00
.. code-block :: console
2016-05-11 02:19:17 +08:00
2018-05-19 05:41:03 +08:00
$ mount | grep lscratch
mds1-lnet0@o2ib100:/lsd on /p/lscratchd type lustre (rw,nosuid,lazystatfs,flock)
mds2-lnet0@o2ib100:/lse on /p/lscratche type lustre (rw,nosuid,lazystatfs,flock)
2016-05-11 02:19:17 +08:00
2018-05-19 05:41:03 +08:00
Note the `` flock `` option on both Lustre mounts.
If you do not see this or a similar option for your filesystem, you have
a few options. First, you can move your Spack installation to a
filesystem that supports locking. Second, you could ask your system
administrator to enable `` flock `` for your filesystem.
If none of those work, you can disable locking in one of two ways:
1. Run Spack with the `` -L `` or `` --disable-locks `` option to disable
locks on a call-by-call basis.
2. Edit :ref: `config.yaml <config-yaml>` and set the `` locks `` option
to `` false `` to always disable locking.
.. warning ::
If you disable locking, concurrent instances of Spack will have no way
to avoid stepping on each other. You must ensure that there is only
**one** instance of Spack running at a time. Otherwise, Spack may end
up with a corrupted database file, or you may not be able to see all
installed packages in commands like `` spack find `` .
If you are unfortunate enough to run into this situation, you may be
able to fix it by running `` spack reindex `` .
2016-05-11 02:19:17 +08:00
This issue typically manifests with the error below:
2016-08-27 05:41:00 +08:00
.. code-block :: console
2016-05-11 02:19:17 +08:00
2016-05-11 01:46:24 +08:00
$ ./spack find
Traceback (most recent call last):
File "./spack", line 176, in <module>
main()
2016-06-28 04:52:48 +08:00
File "./spack", line 154,' in main
2016-05-11 01:46:24 +08:00
return_val = command(parser, args)
File "./spack/lib/spack/spack/cmd/find.py", line 170, in find
2016-08-27 05:41:00 +08:00
specs = set(spack.installed_db.query(\**q_args))
2016-05-11 01:46:24 +08:00
File "./spack/lib/spack/spack/database.py", line 551, in query
with self.read_transaction():
File "./spack/lib/spack/spack/database.py", line 598, in __enter__
if self._enter() and self._acquire_fn:
File "./spack/lib/spack/spack/database.py", line 608, in _enter
return self._db.lock.acquire_read(self._timeout)
File "./spack/lib/spack/llnl/util/lock.py", line 103, in acquire_read
self._lock(fcntl.LOCK_SH, timeout) # can raise LockError.
File "./spack/lib/spack/llnl/util/lock.py", line 64, in _lock
fcntl.lockf(self._fd, op | fcntl.LOCK_NB)
IOError: [Errno 38] Function not implemented
2016-05-11 02:19:17 +08:00
A nicer error message is TBD in future versions of Spack.
2015-02-23 17:22:49 +08:00
2021-06-18 21:52:08 +08:00
---------------
Troubleshooting
---------------
The `` spack audit `` command:
.. command-output :: spack audit -h
can be used to detect a number of configuration issues. This command detects
configuration settings which might not be strictly wrong but are not likely
to be useful outside of special cases.
It can also be used to detect dependency issues with packages - for example
cases where a package constrains a dependency with a variant that doesn't
exist (in this case Spack could report the problem ahead of time but
automatically performing the check would slow down most runs of Spack).
A detailed list of the checks currently implemented for each subcommand can be
printed with:
.. command-output :: spack -v audit list
Depending on the use case, users might run the appropriate subcommands to obtain
diagnostics. Issues, if found, are reported to stdout:
.. code-block :: console
% spack audit packages lammps
PKG-DIRECTIVES: 1 issue found
1. lammps: wrong variant in "conflicts" directive
the variant 'adios' does not exist
2025-05-06 18:05:44 +08:00
in /home/spack/spack/var/spack/repos/spack_repo/builtin/packages/lammps/package.py
2021-06-18 21:52:08 +08:00
2016-06-28 04:52:48 +08:00
2016-08-24 06:03:29 +08:00
------------
2014-10-28 05:42:48 +08:00
Getting Help
2016-08-24 06:03:29 +08:00
------------
2014-10-28 05:42:48 +08:00
2016-10-06 17:49:44 +08:00
.. _cmd-spack-help:
2015-02-24 18:33:29 +08:00
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2014-10-28 05:42:48 +08:00
`` spack help ``
2016-08-24 06:03:29 +08:00
^^^^^^^^^^^^^^
2014-10-28 05:42:48 +08:00
If you don't find what you need here, the `` help `` subcommand will
2016-08-27 05:41:00 +08:00
print out out a list of *all* of spack's options and subcommands:
2014-10-28 05:42:48 +08:00
.. command-output :: spack help
Adding an argument, e.g. `` spack help <subcommand> `` , will print out
usage information for a particular subcommand:
.. command-output :: spack help install
2016-08-27 05:41:00 +08:00
Alternately, you can use `` spack --help `` in place of `` spack help `` , or
`` spack <subcommand> --help `` to get help on a particular subcommand.