diff options
author | Greg Becker <becker33@llnl.gov> | 2022-12-06 16:32:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-06 16:32:08 -0800 |
commit | 194f9a9ca97063c302a6fb0e4456b653a876315a (patch) | |
tree | 938b7aece4d8d129a34389e0570394334c71fe0c | |
parent | a72021fd63c753a52c1f37ae628e0a0a24214299 (diff) | |
download | spack-194f9a9ca97063c302a6fb0e4456b653a876315a.tar.gz spack-194f9a9ca97063c302a6fb0e4456b653a876315a.tar.bz2 spack-194f9a9ca97063c302a6fb0e4456b653a876315a.tar.xz spack-194f9a9ca97063c302a6fb0e4456b653a876315a.zip |
compiler flags: fix mixed flags from cli and yaml (#34218)
-rw-r--r-- | lib/spack/spack/solver/asp.py | 63 | ||||
-rw-r--r-- | lib/spack/spack/test/concretize.py | 7 |
2 files changed, 35 insertions, 35 deletions
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index c15793a230..d5b1e7d759 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -2269,48 +2269,41 @@ class SpecBuilder(object): 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 + + 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")] + sorted_sources = sorted( + self._flag_sources[source_key], key=lambda s: order.index(s) + ) - # order is determined by the DAG. A spec's flags come after - # any from its ancestors on the compile line. - order = [s.name for s in spec.traverse(order="post", direction="parents")] + # add flags from each source, lowest to highest precedence + for source_name in sorted_sources: + source = cmd_specs[source_name] + extend_flag_list(from_sources, source.compiler_flags.get(flag_type, [])) - # sort the sources in our DAG order - sorted_sources = sorted(sources, key=lambda s: order.index(s)) + # compiler flags from compilers config are lowest precedence + ordered_compiler_flags = from_compiler + from_sources + compiler_flags = spec.compiler_flags.get(flag_type, []) - # 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, [])) + msg = "%s does not equal %s" % (set(compiler_flags), set(ordered_compiler_flags)) + assert set(compiler_flags) == set(ordered_compiler_flags), msg - 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]}) + spec.compiler_flags.update({flag_type: ordered_compiler_flags}) def deprecated(self, pkg, version): msg = 'using "{0}@{1}" which is a deprecated version' diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py index 55ad6a1b20..0ddc93b5f6 100644 --- a/lib/spack/spack/test/concretize.py +++ b/lib/spack/spack/test/concretize.py @@ -325,6 +325,13 @@ class TestConcretize(object): 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() |