From f75555136b026cd65c49169936c4075f6a07514a Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 5 Feb 2025 11:55:30 +0100 Subject: [PATCH] No flag propagation when compilers are different Flag propagation is not activated on nodes with a compiler that is different from the propagation source --- lib/spack/spack/solver/concretize.lp | 13 ++++++++----- lib/spack/spack/test/concretization/flag_mixing.py | 13 +++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/spack/spack/solver/concretize.lp b/lib/spack/spack/solver/concretize.lp index 85e257443bd..7e9052af779 100644 --- a/lib/spack/spack/solver/concretize.lp +++ b/lib/spack/spack/solver/concretize.lp @@ -1244,15 +1244,18 @@ error(100, "Cannot propagate the variant '{0}' from the package: {1} because pac % A propagated flag implies: % 1. The same flag type is not set on this node -% 2. This node has the same compiler as the propagation source +% 2. This node has the same compilers as the propagation source + +node_compiler(node(X, Package), node(Y, Compiler)) :- + attr("virtual_on_edge", node(X, Package), node(Y, Compiler), Language), + attr("version", node(Y, Compiler), Version), + compiler(Compiler), language(Language). propagated_flag(node(PackageID, Package), node_flag(FlagType, Flag, FlagGroup, Source), SourceNode) :- propagate(node(PackageID, Package), node_flag(FlagType, Flag, FlagGroup, Source), _), not attr("node_flag_set", node(PackageID, Package), node_flag(FlagType, _, _, "literal")), - % FIXME (compiler as nodes): do we need to match the compiler? - % Same compiler as propagation source - % node_compiler(node(PackageID, Package), CompilerID), - % node_compiler(SourceNode, CompilerID), + % Same compilers as propagation source + node_compiler(node(PackageID, Package), CompilerNode) : node_compiler(SourceNode, CompilerNode); attr("propagate", SourceNode, node_flag(FlagType, Flag, FlagGroup, Source), _), node(PackageID, Package) != SourceNode, not runtime(Package). diff --git a/lib/spack/spack/test/concretization/flag_mixing.py b/lib/spack/spack/test/concretization/flag_mixing.py index 2b6e0dd9744..2859a7dd715 100644 --- a/lib/spack/spack/test/concretization/flag_mixing.py +++ b/lib/spack/spack/test/concretization/flag_mixing.py @@ -198,10 +198,6 @@ def test_propagate_and_compiler_cfg(concretize_scope, test_repo): assert root_spec["y"].satisfies("cflags='-f1 -f2'") -# Note: setting flags on a dependency overrides propagation, which -# is tested in test/concretize.py:test_compiler_flag_propagation - - def test_propagate_and_pkg_dep(concretize_scope, test_repo): root_spec1 = spack.concretize.concretize_one("x ~activatemultiflag cflags=='-f1'") assert root_spec1["y"].satisfies("cflags='-f1 -d1'") @@ -275,3 +271,12 @@ def test_diamond_dep_flag_mixing(concretize_scope, test_repo): spec1 = root_spec1["y"] assert spec1.satisfies('cflags="-c1 -c2 -d1 -d2 -e1 -e2"') assert spec1.compiler_flags["cflags"] == "-c1 -c2 -e1 -e2 -d1 -d2".split() + + +def test_flag_injection_different_compilers(mock_packages, mutable_config): + """Tests that flag propagation is not activated on nodes with a compiler that is different + from the propagation source. + """ + s = spack.concretize.concretize_one('mpileaks %gcc cflags=="-O2" ^callpath %llvm') + assert s.satisfies('cflags="-O2"') and s["c"].name == "gcc" + assert not s["callpath"].satisfies('cflags="-O2"') and s["callpath"]["c"].name == "llvm"