diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index 11340d61e5b..71ba84f2b74 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -862,11 +862,13 @@ def visit(node): self.control.load(os.path.join(parent_dir, "display.lp")) if not setup.concretize_everything: self.control.load(os.path.join(parent_dir, "when_possible.lp")) - flags = [] - for spec in specs: - flags.append(spec.compiler_flags) - if self._compiler_flag_has_propagation(flags): + + has_propagation = False + for spec in specs: + for dep in spec.traverse(root=True): + has_propagation |= self._compiler_flag_has_propagation(dep.compiler_flags) + if has_propagation: self.control.load(os.path.join(parent_dir, "propagation.lp")) timer.stop("load") @@ -978,10 +980,9 @@ def _model_has_cycles(self, models): return cycle_result.unsatisfiable def _compiler_flag_has_propagation(self, flags): - for flag in flags: - for flag_type, flag_vals in flag.items(): - if any(val.propagate for val in flag_vals): - return True + for _, flag_vals in flags.items(): + if any(val.propagate for val in flag_vals): + return True return False diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py index 9437416b3b9..d9662747dd2 100644 --- a/lib/spack/spack/test/concretize.py +++ b/lib/spack/spack/test/concretize.py @@ -349,6 +349,9 @@ def test_compiler_flags_differ_identical_compilers(self): spec.concretize() assert spec.satisfies("cflags=-O2") + @pytest.mark.only_clingo( + "Optional compiler propagation isn't deprecated for original concretizer" + ) def test_concretize_compiler_flag_propagate(self): spec = Spec("callpath cflags=='-g'") spec.concretize() @@ -356,6 +359,16 @@ def test_concretize_compiler_flag_propagate(self): for dep in spec.traverse(): assert dep.satisfies("cflags='-g'") + @pytest.mark.only_clingo( + "Optional compiler propagation isn't deprecated for original concretizer" + ) + def test_concretize_non_root_compiler_flag_propagate(self): + spec = Spec("callpath ^dyninst cflags=='-g'") + spec.concretize() + + assert spec.satisfies("^libdwarf cflags='-g'") + assert spec.satisfies("^libelf cflags='-g'") + @pytest.mark.only_clingo( "Optional compiler propagation isn't deprecated for original concretizer" )