summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/bootstrap.py12
-rw-r--r--lib/spack/spack/store.py13
-rw-r--r--lib/spack/spack/test/bootstrap.py26
3 files changed, 45 insertions, 6 deletions
diff --git a/lib/spack/spack/bootstrap.py b/lib/spack/spack/bootstrap.py
index ff4ddedef5..ce9b720163 100644
--- a/lib/spack/spack/bootstrap.py
+++ b/lib/spack/spack/bootstrap.py
@@ -216,12 +216,12 @@ def _bootstrap_config_scopes():
@contextlib.contextmanager
def ensure_bootstrap_configuration():
with spack.architecture.use_platform(spack.architecture.real_platform()):
- # Default configuration scopes excluding command line and builtin
- # but accounting for platform specific scopes
- config_scopes = _bootstrap_config_scopes()
- with spack.config.use_configuration(*config_scopes):
- with spack.repo.use_repositories(spack.paths.packages_path):
- with spack.store.use_store(spack.paths.user_bootstrap_store):
+ with spack.repo.use_repositories(spack.paths.packages_path):
+ with spack.store.use_store(spack.paths.user_bootstrap_store):
+ # Default configuration scopes excluding command line
+ # and builtin but accounting for platform specific scopes
+ config_scopes = _bootstrap_config_scopes()
+ with spack.config.use_configuration(*config_scopes):
with spack_python_interpreter():
yield
diff --git a/lib/spack/spack/store.py b/lib/spack/spack/store.py
index 2378ff98d8..5d05349b2d 100644
--- a/lib/spack/spack/store.py
+++ b/lib/spack/spack/store.py
@@ -239,6 +239,19 @@ db = llnl.util.lang.LazyReference(_store_db)
layout = llnl.util.lang.LazyReference(_store_layout)
+def reinitialize():
+ """Restore globals to the same state they would have at start-up"""
+ global store
+ global root, unpadded_root, db, layout
+
+ store = llnl.util.lang.Singleton(_store)
+
+ root = llnl.util.lang.LazyReference(_store_root)
+ unpadded_root = llnl.util.lang.LazyReference(_store_unpadded_root)
+ db = llnl.util.lang.LazyReference(_store_db)
+ layout = llnl.util.lang.LazyReference(_store_layout)
+
+
def retrieve_upstream_dbs():
other_spack_instances = spack.config.get('upstreams', {})
diff --git a/lib/spack/spack/test/bootstrap.py b/lib/spack/spack/test/bootstrap.py
new file mode 100644
index 0000000000..97687ddb4d
--- /dev/null
+++ b/lib/spack/spack/test/bootstrap.py
@@ -0,0 +1,26 @@
+# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import pytest
+
+import spack.bootstrap
+import spack.store
+
+
+@pytest.mark.regression('22294')
+def test_store_is_restored_correctly_after_bootstrap(mutable_config, tmpdir):
+ # Prepare a custom store path. This should be in a writeable location
+ # since Spack needs to initialize the DB.
+ user_path = str(tmpdir.join('store'))
+ # Reassign global variables in spack.store to the value
+ # they would have at Spack startup.
+ spack.store.reinitialize()
+ # Set the custom user path
+ spack.config.set('config:install_tree:root', user_path)
+
+ # Test that within the context manager we use the bootstrap store
+ # and that outside we restore the correct location
+ with spack.bootstrap.ensure_bootstrap_configuration():
+ assert spack.store.root == spack.paths.user_bootstrap_store
+ assert spack.store.root == user_path