summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-03-30 17:23:32 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2021-05-22 11:51:20 -0700
commit43cea1b35444f596d75aaad1a1a0bf02a2ba347a (patch)
tree923642cf6a270af90bbc02278d64b181f725547e /lib
parentcbd55332e37ccc21bc2399bb638cfe87f9d897b2 (diff)
downloadspack-43cea1b35444f596d75aaad1a1a0bf02a2ba347a.tar.gz
spack-43cea1b35444f596d75aaad1a1a0bf02a2ba347a.tar.bz2
spack-43cea1b35444f596d75aaad1a1a0bf02a2ba347a.tar.xz
spack-43cea1b35444f596d75aaad1a1a0bf02a2ba347a.zip
Bootstrapping: swap store before configuration (#22631)
fixes #22294 A combination of the swapping order for global variables and the fact that most of them are lazily evaluated resulted in custom install tree not being taken into account if clingo had to be bootstrapped. This commit fixes that particular issue, but a broader refactor may be needed to ensure that similar situations won't affect us in the future.
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 7b77768a37..6dbd2befb9 100644
--- a/lib/spack/spack/store.py
+++ b/lib/spack/spack/store.py
@@ -216,6 +216,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..56083b327f
--- /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 str(spack.store.root) == spack.paths.user_bootstrap_store
+ assert str(spack.store.root) == user_path