compiler flags: fix mixed flags from cli and yaml (#34218)

This commit is contained in:
Greg Becker 2022-12-06 16:32:08 -08:00 committed by GitHub
parent a72021fd63
commit 194f9a9ca9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 35 deletions

View File

@ -2269,48 +2269,41 @@ def reorder_flags(self):
The solver determines wihch flags are on nodes; this routine The solver determines wihch flags are on nodes; this routine
imposes order afterwards. imposes order afterwards.
""" """
# nodes with no flags get flag order from compiler
compilers = dict((c.spec, c) for c in all_compilers_in_config()) 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()) 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 spec in self._specs.values():
for key, sources in self._flag_sources.items(): # if bootstrapping, compiler is not in config and has no flags
pkg, flag_type = key flagmap_from_compiler = {}
spec = self._specs[pkg] if spec.compiler in compilers:
compiler_flags = spec.compiler_flags.get(flag_type, []) flagmap_from_compiler = compilers[spec.compiler].flags
# order is determined by the DAG. A spec's flags come after for flag_type in spec.compiler_flags.valid_compiler_flags():
# any from its ancestors on the compile line. from_compiler = flagmap_from_compiler.get(flag_type, [])
order = [s.name for s in spec.traverse(order="post", direction="parents")] from_sources = []
# sort the sources in our DAG order # order is determined by the DAG. A spec's flags come after any of its ancestors
sorted_sources = sorted(sources, key=lambda s: order.index(s)) # 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")]
sorted_sources = sorted(
self._flag_sources[source_key], key=lambda s: order.index(s)
)
# add flags from each source, lowest to highest precedence # add flags from each source, lowest to highest precedence
flags = [] for source_name in sorted_sources:
for source_name in sorted_sources: source = cmd_specs[source_name]
source = cmd_specs[source_name] extend_flag_list(from_sources, source.compiler_flags.get(flag_type, []))
extend_flag_list(flags, source.compiler_flags.get(flag_type, []))
assert set(compiler_flags) == set(flags), "%s does not equal %s" % ( # compiler flags from compilers config are lowest precedence
set(compiler_flags), ordered_compiler_flags = from_compiler + from_sources
set(flags), compiler_flags = spec.compiler_flags.get(flag_type, [])
)
spec.compiler_flags.update({flag_type: source.compiler_flags[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): def deprecated(self, pkg, version):
msg = 'using "{0}@{1}" which is a deprecated version' msg = 'using "{0}@{1}" which is a deprecated version'

View File

@ -325,6 +325,13 @@ def test_different_compilers_get_different_flags(self):
assert set(client.compiler_flags["fflags"]) == set(["-O0", "-g"]) assert set(client.compiler_flags["fflags"]) == set(["-O0", "-g"])
assert not set(cmake.compiler_flags["fflags"]) 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): def test_concretize_compiler_flag_propagate(self):
spec = Spec("hypre cflags=='-g' ^openblas") spec = Spec("hypre cflags=='-g' ^openblas")
spec.concretize() spec.concretize()