summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2020-04-03 13:26:33 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2020-04-15 12:37:37 -0700
commitb9688a8c35cd2b64a6ad2d2e3157267cda71fc6c (patch)
tree1fe9f5552e995313050f8f75f052b28c3c78d320
parented2781973cfe60c2d3187133684b39e7a752e738 (diff)
downloadspack-b9688a8c35cd2b64a6ad2d2e3157267cda71fc6c.tar.gz
spack-b9688a8c35cd2b64a6ad2d2e3157267cda71fc6c.tar.bz2
spack-b9688a8c35cd2b64a6ad2d2e3157267cda71fc6c.tar.xz
spack-b9688a8c35cd2b64a6ad2d2e3157267cda71fc6c.zip
Environments/views: only override spec prefix for non-external packages (#15475)
* only override spec prefix for non-external packages * add test that environment shell modifications respect explicitly-specified prefixes for external packages * add clarifying comment
-rw-r--r--lib/spack/spack/test/cmd/env.py48
-rw-r--r--lib/spack/spack/user_environment.py2
2 files changed, 49 insertions, 1 deletions
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 841e6e20c8..4f3abb4438 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -370,6 +370,54 @@ env:
assert not e2.specs_by_hash
+@pytest.mark.usefixtures('config')
+def test_env_view_external_prefix(tmpdir_factory, mutable_database,
+ mock_packages):
+ fake_prefix = tmpdir_factory.mktemp('a-prefix')
+ fake_bin = fake_prefix.join('bin')
+ fake_bin.ensure(dir=True)
+
+ initial_yaml = StringIO("""\
+env:
+ specs:
+ - a
+ view: true
+""")
+
+ external_config = StringIO("""\
+packages:
+ a:
+ paths:
+ a: {a_prefix}
+ buildable: false
+""".format(a_prefix=str(fake_prefix)))
+ external_config_dict = spack.util.spack_yaml.load_config(external_config)
+
+ test_scope = spack.config.InternalConfigScope(
+ 'env-external-test', data=external_config_dict)
+ with spack.config.override(test_scope):
+
+ e = ev.create('test', initial_yaml)
+ e.concretize()
+ # Note: normally installing specs in a test environment requires doing
+ # a fake install, but not for external specs since no actions are
+ # taken to install them. The installation commands also include
+ # post-installation functions like DB-registration, so are important
+ # to do (otherwise the package is not considered installed).
+ e.install_all()
+ e.write()
+
+ env_modifications = e.add_default_view_to_shell('sh')
+ individual_modifications = env_modifications.split('\n')
+
+ def path_includes_fake_prefix(cmd):
+ return 'export PATH' in cmd and str(fake_bin) in cmd
+
+ assert any(
+ path_includes_fake_prefix(cmd) for cmd in individual_modifications
+ )
+
+
def test_init_with_file_and_remove(tmpdir):
"""Ensure a user can remove from any position in the spack.yaml file."""
path = tmpdir.join('spack.yaml')
diff --git a/lib/spack/spack/user_environment.py b/lib/spack/spack/user_environment.py
index 4c9fdc3d67..5f2c1c6f50 100644
--- a/lib/spack/spack/user_environment.py
+++ b/lib/spack/spack/user_environment.py
@@ -65,7 +65,7 @@ def environment_modifications_for_spec(spec, view=None):
This list is specific to the location of the spec or its projection in
the view."""
spec = spec.copy()
- if view:
+ if view and not spec.external:
spec.prefix = prefix.Prefix(view.view().get_projection_for_spec(spec))
# generic environment modifications determined by inspecting the spec