summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/compilers/__init__.py2
-rw-r--r--lib/spack/spack/solver/asp.py8
-rw-r--r--lib/spack/spack/test/concretize.py19
3 files changed, 27 insertions, 2 deletions
diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py
index 9b48ee847c..0027f156c0 100644
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -84,7 +84,7 @@ def _to_dict(compiler):
d = {}
d["spec"] = str(compiler.spec)
d["paths"] = dict((attr, getattr(compiler, attr, None)) for attr in _path_instance_vars)
- d["flags"] = dict((fname, fvals) for fname, fvals in compiler.flags)
+ d["flags"] = dict((fname, " ".join(fvals)) for fname, fvals in compiler.flags.items())
d["flags"].update(
dict(
(attr, getattr(compiler, attr, None))
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index 673e202afa..c808a183c6 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -1402,7 +1402,12 @@ class SpackSolverSetup(object):
# flags from compilers.yaml
compilers = all_compilers_in_config()
+ seen = set()
for compiler in compilers:
+ # if there are multiple with the same spec, only use the first
+ if compiler.spec in seen:
+ continue
+ seen.add(compiler.spec)
for name, flags in compiler.flags.items():
for flag in flags:
self.gen.fact(
@@ -2287,7 +2292,8 @@ class SpecBuilder(object):
The solver determines wihch flags are on nodes; this routine
imposes order afterwards.
"""
- compilers = dict((c.spec, c) for c in all_compilers_in_config())
+ # reverse compilers so we get highest priority compilers that share a spec
+ compilers = dict((c.spec, c) for c in reversed(all_compilers_in_config()))
cmd_specs = dict((s.name, s) for spec in self._command_line_specs for s in spec.traverse())
for spec in self._specs.values():
diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py
index 80b179d178..785b7ca166 100644
--- a/lib/spack/spack/test/concretize.py
+++ b/lib/spack/spack/test/concretize.py
@@ -2,6 +2,7 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import copy
import os
import sys
@@ -330,6 +331,24 @@ class TestConcretize(object):
for spec in [client, cmake]:
assert spec.compiler_flags["cflags"] == ["-O3", "-g"]
+ def test_compiler_flags_differ_identical_compilers(self):
+ # Correct arch to use test compiler that has flags
+ spec = Spec("a %clang@12.2.0 platform=test os=fe target=fe")
+
+ # Get the compiler that matches the spec (
+ compiler = spack.compilers.compiler_for_spec("clang@12.2.0", spec.architecture)
+ # Clear cache for compiler config since it has its own cache mechanism outside of config
+ spack.compilers._cache_config_file = []
+
+ # Configure spack to have two identical compilers with different flags
+ default_dict = spack.compilers._to_dict(compiler)
+ different_dict = copy.deepcopy(default_dict)
+ different_dict["compiler"]["flags"] = {"cflags": "-O2"}
+
+ with spack.config.override("compilers", [different_dict]):
+ spec.concretize()
+ assert spec.satisfies("cflags=-O2")
+
def test_concretize_compiler_flag_propagate(self):
spec = Spec("hypre cflags=='-g' ^openblas")
spec.concretize()