From 95c9a031ee3f425a16b37bd7ca8d3b03b49ebf76 Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Sat, 12 Jun 2021 01:23:13 -0700 Subject: Ensure all roots of an installed environment are marked explicit in db (#24277) --- lib/spack/spack/environment.py | 7 +++++++ lib/spack/spack/test/cmd/env.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index bbb4298667..15921c5389 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -1574,6 +1574,13 @@ class Environment(object): specs_to_install = [s for s in specs_to_install if s not in self.roots() or s in uninstalled_roots] + # ensure specs already installed are marked explicit + all_specs = specs or [cs for _, cs in self.concretized_specs()] + specs_installed = [s for s in all_specs if s.package.installed] + with spack.store.db.write_transaction(): # do all in one transaction + for spec in specs_installed: + spack.store.db.update_explicit(spec, True) + if not specs_to_install: tty.msg('All of the packages are already installed') return diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index 0c7dea4c3e..6c2ce34438 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -179,6 +179,27 @@ def test_env_install_single_spec(install_mockery, mock_fetch): assert e.specs_by_hash[e.concretized_order[0]].name == 'cmake-client' +def test_env_roots_marked_explicit(install_mockery, mock_fetch): + install = SpackCommand('install') + install('dependent-install') + + # Check one explicit, one implicit install + dependent = spack.store.db.query(explicit=True) + dependency = spack.store.db.query(explicit=False) + assert len(dependent) == 1 + assert len(dependency) == 1 + + env('create', 'test') + with ev.read('test') as e: + # make implicit install a root of the env + e.add(dependency[0].name) + e.concretize() + e.install_all() + + explicit = spack.store.db.query(explicit=True) + assert len(explicit) == 2 + + def test_env_modifications_error_on_activate( install_mockery, mock_fetch, monkeypatch, capfd): env('create', 'test') -- cgit v1.2.3-70-g09d2