compiler flags: fix mixed flags from cli and yaml (#34218)
This commit is contained in:
parent
a72021fd63
commit
194f9a9ca9
@ -2269,48 +2269,41 @@ def reorder_flags(self):
|
||||
The solver determines wihch flags are on nodes; this routine
|
||||
imposes order afterwards.
|
||||
"""
|
||||
# nodes with no flags get flag order from compiler
|
||||
compilers = dict((c.spec, c) for c in all_compilers_in_config())
|
||||
for pkg in self._flag_compiler_defaults:
|
||||
spec = self._specs[pkg]
|
||||
compiler_flags = compilers[spec.compiler].flags
|
||||
for key in spec.compiler_flags:
|
||||
spec_compiler_flags_set = set(spec.compiler_flags.get(key, []))
|
||||
compiler_flags_set = set(compiler_flags.get(key, []))
|
||||
|
||||
assert spec_compiler_flags_set == compiler_flags_set, "%s does not equal %s" % (
|
||||
spec_compiler_flags_set,
|
||||
compiler_flags_set,
|
||||
)
|
||||
|
||||
spec.compiler_flags[key] = compiler_flags.get(key, [])
|
||||
# index of all specs (and deps) from the command line by name
|
||||
cmd_specs = dict((s.name, s) for spec in self._command_line_specs for s in spec.traverse())
|
||||
|
||||
# iterate through specs with specified flags
|
||||
for key, sources in self._flag_sources.items():
|
||||
pkg, flag_type = key
|
||||
spec = self._specs[pkg]
|
||||
compiler_flags = spec.compiler_flags.get(flag_type, [])
|
||||
for spec in self._specs.values():
|
||||
# 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
|
||||
|
||||
# order is determined by the DAG. A spec's flags come after
|
||||
# any from its ancestors on the compile line.
|
||||
for flag_type in spec.compiler_flags.valid_compiler_flags():
|
||||
from_compiler = flagmap_from_compiler.get(flag_type, [])
|
||||
from_sources = []
|
||||
|
||||
# order is determined by the DAG. A spec's flags come after any of its ancestors
|
||||
# on the compile line
|
||||
source_key = (spec.name, flag_type)
|
||||
if source_key in self._flag_sources:
|
||||
order = [s.name for s in spec.traverse(order="post", direction="parents")]
|
||||
|
||||
# sort the sources in our DAG order
|
||||
sorted_sources = sorted(sources, key=lambda s: order.index(s))
|
||||
sorted_sources = sorted(
|
||||
self._flag_sources[source_key], key=lambda s: order.index(s)
|
||||
)
|
||||
|
||||
# add flags from each source, lowest to highest precedence
|
||||
flags = []
|
||||
for source_name in sorted_sources:
|
||||
source = cmd_specs[source_name]
|
||||
extend_flag_list(flags, source.compiler_flags.get(flag_type, []))
|
||||
extend_flag_list(from_sources, source.compiler_flags.get(flag_type, []))
|
||||
|
||||
assert set(compiler_flags) == set(flags), "%s does not equal %s" % (
|
||||
set(compiler_flags),
|
||||
set(flags),
|
||||
)
|
||||
spec.compiler_flags.update({flag_type: source.compiler_flags[flag_type]})
|
||||
# compiler flags from compilers config are lowest precedence
|
||||
ordered_compiler_flags = from_compiler + from_sources
|
||||
compiler_flags = spec.compiler_flags.get(flag_type, [])
|
||||
|
||||
msg = "%s does not equal %s" % (set(compiler_flags), set(ordered_compiler_flags))
|
||||
assert set(compiler_flags) == set(ordered_compiler_flags), msg
|
||||
|
||||
spec.compiler_flags.update({flag_type: ordered_compiler_flags})
|
||||
|
||||
def deprecated(self, pkg, version):
|
||||
msg = 'using "{0}@{1}" which is a deprecated version'
|
||||
|
@ -325,6 +325,13 @@ def test_different_compilers_get_different_flags(self):
|
||||
assert set(client.compiler_flags["fflags"]) == set(["-O0", "-g"])
|
||||
assert not set(cmake.compiler_flags["fflags"])
|
||||
|
||||
def test_compiler_flags_from_compiler_and_dependent(self):
|
||||
client = Spec("cmake-client %clang@12.2.0 platform=test os=fe target=fe cflags==-g")
|
||||
client.concretize()
|
||||
cmake = client["cmake"]
|
||||
for spec in [client, cmake]:
|
||||
assert spec.compiler_flags["cflags"] == ["-O3", "-g"]
|
||||
|
||||
def test_concretize_compiler_flag_propagate(self):
|
||||
spec = Spec("hypre cflags=='-g' ^openblas")
|
||||
spec.concretize()
|
||||
|
Loading…
Reference in New Issue
Block a user