diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2023-11-29 09:09:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-29 09:09:16 +0100 |
commit | 29b75a7ace4aafd9550ff98fbf3ffe9f14d99450 (patch) | |
tree | a362e28416a7586da8baf156870d9a57456cbd76 /lib | |
parent | 4b41b11c30bd5c40cd9bcb11c1a629df50705141 (diff) | |
download | spack-29b75a7ace4aafd9550ff98fbf3ffe9f14d99450.tar.gz spack-29b75a7ace4aafd9550ff98fbf3ffe9f14d99450.tar.bz2 spack-29b75a7ace4aafd9550ff98fbf3ffe9f14d99450.tar.xz spack-29b75a7ace4aafd9550ff98fbf3ffe9f14d99450.zip |
Fix an issue with deconcretization/reconcretization of environments (#41294)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/solver/asp.py | 12 | ||||
-rw-r--r-- | lib/spack/spack/test/env.py | 29 |
2 files changed, 34 insertions, 7 deletions
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index d33b47eeb2..8ad8d5c5c0 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -2699,15 +2699,13 @@ class SpackSolverSetup: self.gen.fact(fn.pkg_fact(spec.name, fn.condition_trigger(condition_id, trigger_id))) self.gen.fact(fn.condition_reason(condition_id, f"{spec} requested from CLI")) - # Effect imposes the spec imposed_spec_key = str(spec), None cache = self._effect_cache[spec.name] - msg = ( - "literal specs have different requirements. clear cache before computing literals" - ) - assert imposed_spec_key not in cache, msg - effect_id = next(self._id_counter) - requirements = self.spec_clauses(spec) + if imposed_spec_key in cache: + effect_id, requirements = cache[imposed_spec_key] + else: + effect_id = next(self._id_counter) + requirements = self.spec_clauses(spec) root_name = spec.name for clause in requirements: clause_name = clause.args[0] diff --git a/lib/spack/spack/test/env.py b/lib/spack/spack/test/env.py index 7490a6e0b2..6ab05a603f 100644 --- a/lib/spack/spack/test/env.py +++ b/lib/spack/spack/test/env.py @@ -778,3 +778,32 @@ def test_env_with_include_def_missing(mutable_mock_env_path, mock_packages): with e: with pytest.raises(UndefinedReferenceError, match=r"which does not appear"): e.concretize() + + +@pytest.mark.regression("41292") +def test_deconcretize_then_concretize_does_not_error(mutable_mock_env_path, mock_packages): + """Tests that, after having deconcretized a spec, we can reconcretize an environment which + has 2 or more user specs mapping to the same concrete spec. + """ + mutable_mock_env_path.mkdir() + spack_yaml = mutable_mock_env_path / ev.manifest_name + spack_yaml.write_text( + """spack: + specs: + # These two specs concretize to the same hash + - c + - c@1.0 + # Spec used to trigger the bug + - a + concretizer: + unify: true + """ + ) + e = ev.Environment(mutable_mock_env_path) + with e: + e.concretize() + e.deconcretize(spack.spec.Spec("a"), concrete=False) + e.concretize() + assert len(e.concrete_roots()) == 3 + all_root_hashes = set(x.dag_hash() for x in e.concrete_roots()) + assert len(all_root_hashes) == 2 |