From 32fc8c351db0b4532e9cd68b0259947f67ee7a3f Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Fri, 15 Nov 2024 08:09:26 +0100 Subject: [PATCH] Fix setting SPACK_TARGET_ARGS for concrete specs --- lib/spack/spack/test/build_environment.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/spack/spack/test/build_environment.py b/lib/spack/spack/test/build_environment.py index 5b036b5a4f9..e35b67ea197 100644 --- a/lib/spack/spack/test/build_environment.py +++ b/lib/spack/spack/test/build_environment.py @@ -13,12 +13,14 @@ from llnl.util.filesystem import HeaderList, LibraryList import spack.build_environment +import spack.build_systems.compiler import spack.concretize import spack.config import spack.deptypes as dt import spack.package_base import spack.paths import spack.spec +import spack.util.environment import spack.util.spack_yaml as syaml from spack.build_environment import UseMode, _static_to_shared_library, dso_suffix from spack.context import Context @@ -779,3 +781,23 @@ def test_optimization_flags(compiler_spec, target_name, expected_flags, compiler compiler = spack.spec.parse_with_version_concrete(compiler_spec) opt_flags = spack.build_environment.optimization_flags(compiler, target) assert opt_flags == expected_flags + + +@pytest.mark.skipif( + str(archspec.cpu.host().family) != "x86_64", reason="tests check specific x86_64 uarch flags" +) +@pytest.mark.not_on_windows("Windows doesn't support the compiler wrapper") +def test_optimization_flags_are_using_node_target(default_mock_concretization, monkeypatch): + """Tests that we are using the target on the node to be compiled to retrieve the uarch + specific flags, and not the target of the compiler. + """ + monkeypatch.setattr(spack.build_systems.compiler, "_implicit_rpaths", lambda pkg: []) + gcc = default_mock_concretization("gcc target=core2") + mpileaks = default_mock_concretization("gcc target=x86_64") + + env = EnvironmentModifications() + gcc.package.setup_dependent_build_environment(env, mpileaks) + actions = env.group_by_name()["SPACK_TARGET_ARGS"] + + assert len(actions) == 1 and isinstance(actions[0], spack.util.environment.SetEnv) + assert actions[0].value == "-march=x86-64 -mtune=generic"