From 2f2d9ae30dad64cc654c48154e1c4ef65c03eba4 Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Tue, 31 Oct 2023 13:19:12 -0700 Subject: [PATCH] Fix cflags requirements (#40639) --- lib/spack/spack/solver/concretize.lp | 19 +++++++++++-------- .../spack/test/concretize_requirements.py | 14 ++++++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/spack/spack/solver/concretize.lp b/lib/spack/spack/solver/concretize.lp index 92ba77ad82..26c7907759 100644 --- a/lib/spack/spack/solver/concretize.lp +++ b/lib/spack/spack/solver/concretize.lp @@ -696,15 +696,18 @@ requirement_group_satisfied(node(ID, Package), X) :- % flags if their only source is from a requirement. This is overly-specific % and should use a more-generic approach like in https://github.com/spack/spack/pull/37180 -{ attr("node_flag", node(ID, A1), A2, A3) } :- - requirement_group_member(Y, Package, X), - activate_requirement(node(ID, Package), X), - imposed_constraint(Y,"node_flag_set", A1, A2, A3). +{ attr("node_flag", node(ID, Package), FlagType, FlagValue) } :- + requirement_group_member(ConditionID, Package, RequirementID), + activate_requirement(node(ID, Package), RequirementID), + pkg_fact(Package, condition_effect(ConditionID, EffectID)), + imposed_constraint(EffectID, "node_flag_set", Package, FlagType, FlagValue). -{ attr("node_flag_source", node(ID, A1), A2, node(ID, A3)) } :- - requirement_group_member(Y, Package, X), - activate_requirement(node(ID, Package), X), - imposed_constraint(Y,"node_flag_source", A1, A2, A3). +{ attr("node_flag_source", node(NodeID1, Package1), FlagType, node(NodeID2, Package2)) } :- + requirement_group_member(ConditionID, Package1, RequirementID), + activate_requirement(node(NodeID1, Package1), RequirementID), + pkg_fact(Package1, condition_effect(ConditionID, EffectID)), + imposed_constraint(EffectID, "node_flag_source", Package1, FlagType, Package2), + imposed_packages(NodeID2, Package2). requirement_weight(node(ID, Package), Group, W) :- W = #min { diff --git a/lib/spack/spack/test/concretize_requirements.py b/lib/spack/spack/test/concretize_requirements.py index cd51006088..d5295691ce 100644 --- a/lib/spack/spack/test/concretize_requirements.py +++ b/lib/spack/spack/test/concretize_requirements.py @@ -469,16 +469,22 @@ def test_one_package_multiple_oneof_groups(concretize_scope, test_repo): @pytest.mark.regression("34241") -def test_require_cflags(concretize_scope, test_repo): +def test_require_cflags(concretize_scope, mock_packages): """Ensures that flags can be required from configuration.""" conf_str = """\ packages: - y: + mpich2: require: cflags="-g" + mpi: + require: mpich cflags="-O1" """ update_packages_config(conf_str) - spec = Spec("y").concretized() - assert spec.satisfies("cflags=-g") + + spec_mpich2 = Spec("mpich2").concretized() + assert spec_mpich2.satisfies("cflags=-g") + + spec_mpi = Spec("mpi").concretized() + assert spec_mpi.satisfies("mpich cflags=-O1") def test_requirements_for_package_that_is_not_needed(concretize_scope, test_repo):