From a450dd31faa38268a5975a8d9c505d3e5cffa086 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Mon, 22 Apr 2024 09:15:22 +0200 Subject: [PATCH] Fix a bug preventing to set platform= on externals (#43758) closes #43406 --- lib/spack/spack/solver/asp.py | 1 + lib/spack/spack/solver/concretize.lp | 13 ++++++------- lib/spack/spack/test/concretize.py | 13 +++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index 9e1e86bfe4..22d6994e4c 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -1610,6 +1610,7 @@ def external_imposition(input_spec, requirements): self.gen.newline() self.trigger_rules() + self.effect_rules() def preferred_variants(self, pkg_name): """Facts on concretization preferences, as read from packages.yaml""" diff --git a/lib/spack/spack/solver/concretize.lp b/lib/spack/spack/solver/concretize.lp index 022c6abe78..70b3645810 100644 --- a/lib/spack/spack/solver/concretize.lp +++ b/lib/spack/spack/solver/concretize.lp @@ -993,14 +993,13 @@ pkg_fact(Package, variant_single_value("dev_path")) % Platform semantics %----------------------------------------------------------------------------- -% if no platform is set, fall back to the default -error(100, "platform '{0}' is not allowed on the current host", Platform) - :- attr("node_platform", _, Platform), not allowed_platform(Platform). +% NOTE: Currently we have a single allowed platform per DAG, therefore there is no +% need to have additional optimization criteria. If we ever add cross-platform dags, +% this needs to be changed. +:- 2 { allowed_platform(Platform) }, internal_error("More than one allowed platform detected"). -attr("node_platform", PackageNode, Platform) - :- attr("node", PackageNode), - not attr("node_platform_set", PackageNode), - node_platform_default(Platform). +1 { attr("node_platform", PackageNode, Platform) : allowed_platform(Platform) } 1 + :- attr("node", PackageNode). % setting platform on a node is a hard constraint attr("node_platform", PackageNode, Platform) diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py index f897230088..db67523150 100644 --- a/lib/spack/spack/test/concretize.py +++ b/lib/spack/spack/test/concretize.py @@ -2398,6 +2398,19 @@ def test_reuse_specs_from_non_available_compilers(self, mutable_config, mutable_ for s in root.traverse(root=False): assert s.satisfies("%gcc@10.2.1") + @pytest.mark.regression("43406") + def test_externals_with_platform_explicitly_set(self, tmp_path): + """Tests that users can specify platform=xxx in an external spec""" + external_conf = { + "mpich": { + "buildable": False, + "externals": [{"spec": "mpich@=2.0.0 platform=test", "prefix": str(tmp_path)}], + } + } + spack.config.set("packages", external_conf) + s = Spec("mpich").concretized() + assert s.external + @pytest.fixture() def duplicates_test_repository():