diff options
Diffstat (limited to 'lib/spack/docs/environments.rst')
-rw-r--r-- | lib/spack/docs/environments.rst | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/spack/docs/environments.rst b/lib/spack/docs/environments.rst index 5c8b6b2fb4..ac49f7a523 100644 --- a/lib/spack/docs/environments.rst +++ b/lib/spack/docs/environments.rst @@ -1089,4 +1089,52 @@ output (``spack install --verbose``) while its dependencies are installed silent $ make -j16 install-deps/python-3.11.0-<hash> SPACK_INSTALL_FLAGS=--show-log-on-error # Install the root spec with verbose output. - $ make -j16 install/python-3.11.0-<hash> SPACK_INSTALL_FLAGS=--verbose
\ No newline at end of file + $ make -j16 install/python-3.11.0-<hash> SPACK_INSTALL_FLAGS=--verbose + +^^^^^^^^^^^^^^^^^^^^^^^^^ +Adding post-install hooks +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Another advanced use-case of generated ``Makefile``\s is running a post-install +command for each package. These "hooks" could be anything from printing a +post-install message, running tests, or pushing just-built binaries to a buildcache. + +This can be accomplished through the generated ``[<prefix>/]SPACK_PACKAGE_IDS`` +variable. Assuming we have an active and concrete environment, we generate the +associated ``Makefile`` with a prefix ``example``: + +.. code:: console + + $ spack env depfile -o env.mk --make-target-prefix example + +And we now include it in a different ``Makefile``, in which we create a target +``example/push/%`` with ``%`` referring to a package identifier. This target +depends on the particular package installation. In this target we automatically +have the target-specific ``HASH`` and ``SPEC`` variables at our disposal. They +are respectively the spec hash (excluding leading ``/``), and a human-readable spec. +Finally, we have an entrypoint target ``push`` that will update the buildcache +index once every package is pushed. Note how this target uses the generated +``example/SPACK_PACKAGE_IDS`` variable to define its prerequisites. + +.. code:: Makefile + + SPACK ?= spack + BUILDCACHE_DIR = $(CURDIR)/tarballs + + .PHONY: all + + all: push + + include env.mk + + example/push/%: example/install/% + @mkdir -p $(dir $@) + $(info About to push $(SPEC) to a buildcache) + $(SPACK) -e . buildcache create --allow-root --only=package --directory $(BUILDCACHE_DIR) /$(HASH) + @touch $@ + + push: $(addprefix example/push/,$(example/SPACK_PACKAGE_IDS)) + $(info Updating the buildcache index) + $(SPACK) -e . buildcache update-index --directory $(BUILDCACHE_DIR) + $(info Done!) + @touch $@ |