summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2021-05-11 14:30:57 -0700
committerGitHub <noreply@github.com>2021-05-11 14:30:57 -0700
commit52307309410bf2f076df78f40ca3aa762b8897fc (patch)
treea1bac239d79d804b05ff99b70b7fbb19d2e46bec /lib
parent57ce5f390b57574372d10434891bed0048b63096 (diff)
downloadspack-52307309410bf2f076df78f40ca3aa762b8897fc.tar.gz
spack-52307309410bf2f076df78f40ca3aa762b8897fc.tar.bz2
spack-52307309410bf2f076df78f40ca3aa762b8897fc.tar.xz
spack-52307309410bf2f076df78f40ca3aa762b8897fc.zip
Environments: add run deps to shell modifications (#23485)
When adding an Environment to a user's shell, Spack was only adding root specs. This now includes run dependencies of root specs.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/environment.py41
-rw-r--r--lib/spack/spack/test/cmd/env.py13
2 files changed, 42 insertions, 12 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 46541fb32a..14e349ff11 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -1276,19 +1276,36 @@ class Environment(object):
def _env_modifications_for_default_view(self, reverse=False):
all_mods = spack.util.environment.EnvironmentModifications()
+ visited = set()
+
errors = []
- for _, spec in self.concretized_specs():
- if spec in self.default_view and spec.package.installed:
- try:
- mods = uenv.environment_modifications_for_spec(
- spec, self.default_view)
- except Exception as e:
- msg = ("couldn't get environment settings for %s"
- % spec.format("{name}@{version} /{hash:7}"))
- errors.append((msg, str(e)))
- continue
-
- all_mods.extend(mods.reversed() if reverse else mods)
+ for _, root_spec in self.concretized_specs():
+ if root_spec in self.default_view and root_spec.package.installed:
+ for spec in root_spec.traverse(deptype='run', root=True):
+ if spec.name in visited:
+ # It is expected that only one instance of the package
+ # can be added to the environment - do not attempt to
+ # add multiple.
+ tty.debug(
+ "Not adding {0} to shell modifications: "
+ "this package has already been added".format(
+ spec.format("{name}/{hash:7}")
+ )
+ )
+ continue
+ else:
+ visited.add(spec.name)
+
+ try:
+ mods = uenv.environment_modifications_for_spec(
+ spec, self.default_view)
+ except Exception as e:
+ msg = ("couldn't get environment settings for %s"
+ % spec.format("{name}@{version} /{hash:7}"))
+ errors.append((msg, str(e)))
+ continue
+
+ all_mods.extend(mods.reversed() if reverse else mods)
return all_mods, errors
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 5ff0f0de9f..9358d0a3a9 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -200,6 +200,19 @@ def test_env_modifications_error_on_activate(
assert "Warning: couldn't get environment settings" in err
+def test_activate_adds_transitive_run_deps_to_path(
+ install_mockery, mock_fetch, monkeypatch):
+ env('create', 'test')
+ install = SpackCommand('install')
+
+ e = ev.read('test')
+ with e:
+ install('depends-on-run-env')
+
+ cmds = spack.environment.activate(e)
+ assert 'DEPENDENCY_ENV_VAR=1' in cmds
+
+
def test_env_install_same_spec_twice(install_mockery, mock_fetch):
env('create', 'test')