From 2447d16e55d800e6a9cb82a645ab9edfd24f08ac Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Tue, 14 Jan 2025 10:15:57 -0800 Subject: [PATCH] bugfix: associate nodes directly with specs for compiler flag reordering (#48496) --- lib/spack/spack/solver/asp.py | 4 +--- lib/spack/spack/test/concretization/flag_mixing.py | 13 +++++++++++++ .../repos/builtin.mock/packages/cmake/package.py | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index cca1ad4262fb1f..88d69725b057c3 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -3540,15 +3540,13 @@ def reorder_flags(self): ) cmd_specs = dict((s.name, s) for spec in self._command_line_specs for s in spec.traverse()) - for spec in self._specs.values(): + for node, spec in self._specs.items(): # if bootstrapping, compiler is not in config and has no flags flagmap_from_compiler = {} if spec.compiler in compilers: flagmap_from_compiler = compilers[spec.compiler].flags for flag_type in spec.compiler_flags.valid_compiler_flags(): - node = SpecBuilder.make_node(pkg=spec.name) - ordered_flags = [] # 1. Put compiler flags first diff --git a/lib/spack/spack/test/concretization/flag_mixing.py b/lib/spack/spack/test/concretization/flag_mixing.py index 906dd5d84fa2fc..62187dd39f93c7 100644 --- a/lib/spack/spack/test/concretization/flag_mixing.py +++ b/lib/spack/spack/test/concretization/flag_mixing.py @@ -5,6 +5,7 @@ import pytest +import spack.concretize import spack.config import spack.environment as ev import spack.paths @@ -96,6 +97,18 @@ def test_mix_spec_and_compiler_cfg(concretize_scope, test_repo): assert s1.satisfies('cflags="-Wall -O2"') +def test_pkg_flags_from_compiler_and_none(concretize_scope, mock_packages): + conf_str = _compiler_cfg_one_entry_with_cflags("-Wall") + update_concretize_scope(conf_str, "compilers") + + s1 = Spec("cmake%gcc@12.100.100") + s2 = Spec("cmake-client^cmake%clang") + concrete = dict(spack.concretize.concretize_together([(s1, None), (s2, None)])) + + assert concrete[s1].compiler_flags["cflags"] == ["-Wall"] + assert concrete[s2].compiler_flags["cflags"] == [] + + @pytest.mark.parametrize( "cmd_flags,req_flags,cmp_flags,dflags,expected_order", [ diff --git a/var/spack/repos/builtin.mock/packages/cmake/package.py b/var/spack/repos/builtin.mock/packages/cmake/package.py index 203b6815ad318e..12d229b1beebfd 100644 --- a/var/spack/repos/builtin.mock/packages/cmake/package.py +++ b/var/spack/repos/builtin.mock/packages/cmake/package.py @@ -20,6 +20,8 @@ class Cmake(Package): homepage = "https://www.cmake.org" url = "https://cmake.org/files/v3.4/cmake-3.4.3.tar.gz" + tags = ["build-tools"] + version( "3.23.1", md5="4cb3ff35b2472aae70f542116d616e63",