summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2021-03-30 17:23:32 +0200
committerGitHub <noreply@github.com>2021-03-30 17:23:32 +0200
commitc3bab11ee1a26bb7074db8490e2155c598db18ea (patch)
tree434f4928e0b9a658acb6d304561d49ff6ea55948 /lib
parent220c0d9cfcdf273a8f15daea8eae7541f1a9245f (diff)
downloadspack-c3bab11ee1a26bb7074db8490e2155c598db18ea.tar.gz
spack-c3bab11ee1a26bb7074db8490e2155c598db18ea.tar.bz2
spack-c3bab11ee1a26bb7074db8490e2155c598db18ea.tar.xz
spack-c3bab11ee1a26bb7074db8490e2155c598db18ea.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 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