diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/environment.py | 41 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/env.py | 13 |
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') |