environment modifications for externals (#41723)

* allow externals to configure environment modifications

* docs for external env modification

---------

Co-authored-by: becker33 <becker33@users.noreply.github.com>
This commit is contained in:
Greg Becker 2023-12-18 20:24:15 -08:00 committed by GitHub
parent 6a19cf1b42
commit 56761649a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 1 deletions

View File

@ -97,6 +97,35 @@ Each package version and compiler listed in an external should
have entries in Spack's packages and compiler configuration, even
though the package and compiler may not ever be built.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Extra attributes for external packages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sometimes external packages require additional attributes to be used
effectively. This information can be defined on a per-package basis
and stored in the ``extra_attributes`` section of the external package
configuration. In addition to per-package information, this section
can be used to define environment modifications to be performed
whenever the package is used. For example, if an external package is
built without ``rpath`` support, it may require ``LD_LIBRARY_PATH``
settings to find its dependencies. This could be configured as
follows:
.. code-block:: yaml
packages:
mpich:
externals:
- spec: mpich@3.3 %clang@12.0.0 +hwloc
prefix: /path/to/mpich
extra_attributes:
environment:
prepend_path:
LD_LIBRARY_PATH: /path/to/hwloc/lib64
See :ref:`configuration_environment_variables` for more information on
how to configure environment modifications in Spack config files.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Prevent packages from being built from sources
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -1032,6 +1032,11 @@ def get_env_modifications(self) -> EnvironmentModifications:
if id(spec) in self.nodes_in_subdag:
pkg.setup_dependent_run_environment(run_env_mods, spec)
pkg.setup_run_environment(run_env_mods)
external_env = (dspec.extra_attributes or {}).get("environment", {})
if external_env:
run_env_mods.extend(spack.schema.environment.parse(external_env))
if self.context == Context.BUILD:
# Don't let the runtime environment of comiler like dependencies leak into the
# build env

View File

@ -7,6 +7,7 @@
.. literalinclude:: _spack_root/lib/spack/spack/schema/packages.py
:lines: 13-
"""
import spack.schema.environment
permissions = {
"type": "object",
@ -155,7 +156,13 @@
"spec": {"type": "string"},
"prefix": {"type": "string"},
"modules": {"type": "array", "items": {"type": "string"}},
"extra_attributes": {"type": "object"},
"extra_attributes": {
"type": "object",
"additionalProperties": True,
"properties": {
"environment": spack.schema.environment.definition
},
},
},
"additionalProperties": True,
"required": ["spec"],

View File

@ -285,6 +285,24 @@ def platform_pathsep(pathlist):
assert name not in os.environ
def test_external_config_env(mock_packages, mutable_config, working_env):
cmake_config = {
"externals": [
{
"spec": "cmake@1.0",
"prefix": "/fake/path",
"extra_attributes": {"environment": {"set": {"TEST_ENV_VAR_SET": "yes it's set"}}},
}
]
}
spack.config.set("packages:cmake", cmake_config)
cmake_client = spack.spec.Spec("cmake-client").concretized()
spack.build_environment.setup_package(cmake_client.package, False)
assert os.environ["TEST_ENV_VAR_SET"] == "yes it's set"
@pytest.mark.regression("9107")
def test_spack_paths_before_module_paths(config, mock_packages, monkeypatch, working_env):
s = spack.spec.Spec("cmake")