summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/environment.py24
-rw-r--r--lib/spack/spack/test/cmd/env.py14
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 2507d1a254..4ab01cb250 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -1055,8 +1055,24 @@ class Environment(object):
'': ['CMAKE_PREFIX_PATH']
}
+ def unconditional_environment_modifications(self, view):
+ """List of environment (shell) modifications to be processed for view.
+
+ This list does not depend on the specs in this environment"""
+ env = spack.util.environment.EnvironmentModifications()
+
+ for subdir, vars in self.prefix_inspections.items():
+ full_subdir = os.path.join(view.root, subdir)
+ for var in vars:
+ env.prepend_path(var, full_subdir)
+
+ return env
+
def environment_modifications_for_spec(self, spec, view=None):
- """List of environment modifications to be processed."""
+ """List of environment (shell) modifications to be processed for spec.
+
+ This list is specific to the location of the spec or its projection in
+ the view."""
spec = spec.copy()
if view:
spec.prefix = Prefix(view.view().get_projection_for_spec(spec))
@@ -1089,6 +1105,9 @@ class Environment(object):
# No default view to add to shell
return env_mod.shell_modifications(shell)
+ env_mod.extend(self.unconditional_environment_modifications(
+ self.default_view))
+
for _, spec in self.concretized_specs():
if spec in self.default_view:
env_mod.extend(self.environment_modifications_for_spec(
@@ -1107,6 +1126,9 @@ class Environment(object):
# No default view to add to shell
return env_mod.shell_modifications(shell)
+ env_mod.extend(self.unconditional_environment_modifications(
+ self.default_view).reversed())
+
for _, spec in self.concretized_specs():
if spec in self.default_view:
env_mod.extend(
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 4e544ef757..b1e9e579ae 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -1703,6 +1703,20 @@ def test_env_activate_csh_prints_shell_output(
assert "alias despacktivate" in out
+@pytest.mark.regression('12719')
+def test_env_activate_default_view_root_unconditional(env_deactivate,
+ mutable_mock_env_path):
+ """Check that the root of the default view in the environment is added
+ to the shell unconditionally."""
+ env('create', 'test', add_view=True)
+
+ with ev.read('test') as e:
+ viewdir = e.default_view.root
+
+ out = env('activate', '--sh', 'test')
+ assert 'PATH=%s' % os.path.join(viewdir, 'bin') in out
+
+
def test_concretize_user_specs_together():
e = ev.create('coconcretization')
e.concretization = 'together'