Dont propagate flags between different compilers (#3379)
* Dont propagate flags between different compilers Fixes #2786 Previously when a spec had no parents with an equivalent compiler, Spack would default to adding the compiler flags associated with the root of the DAG. This eliminates that default. * added test for compiler flag propagation * simplify compiler flag propagation logic
This commit is contained in:
parent
328b2142f5
commit
5936ad2ca7
@ -377,41 +377,26 @@ def concretize_compiler_flags(self, spec):
|
|||||||
# running.
|
# running.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
compiler_match = lambda other: (
|
||||||
|
spec.compiler == other.compiler and
|
||||||
|
spec.architecture == other.architecture)
|
||||||
|
|
||||||
ret = False
|
ret = False
|
||||||
for flag in spack.spec.FlagMap.valid_compiler_flags():
|
for flag in spack.spec.FlagMap.valid_compiler_flags():
|
||||||
|
if flag not in spec.compiler_flags:
|
||||||
|
spec.compiler_flags[flag] = list()
|
||||||
try:
|
try:
|
||||||
nearest = next(p for p in spec.traverse(direction='parents')
|
nearest = next(p for p in spec.traverse(direction='parents')
|
||||||
if ((p.compiler == spec.compiler and
|
if (compiler_match(p) and
|
||||||
p is not spec) and
|
(p is not spec) and
|
||||||
flag in p.compiler_flags))
|
flag in p.compiler_flags))
|
||||||
if flag not in spec.compiler_flags or \
|
nearest_flags = set(nearest.compiler_flags.get(flag, []))
|
||||||
not (sorted(spec.compiler_flags[flag]) >=
|
flags = set(spec.compiler_flags.get(flag, []))
|
||||||
sorted(nearest.compiler_flags[flag])):
|
if (nearest_flags - flags):
|
||||||
if flag in spec.compiler_flags:
|
spec.compiler_flags[flag] = list(nearest_flags | flags)
|
||||||
spec.compiler_flags[flag] = list(
|
|
||||||
set(spec.compiler_flags[flag]) |
|
|
||||||
set(nearest.compiler_flags[flag]))
|
|
||||||
else:
|
|
||||||
spec.compiler_flags[
|
|
||||||
flag] = nearest.compiler_flags[flag]
|
|
||||||
ret = True
|
ret = True
|
||||||
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
if (flag in spec.root.compiler_flags and
|
pass
|
||||||
((flag not in spec.compiler_flags) or
|
|
||||||
sorted(spec.compiler_flags[flag]) !=
|
|
||||||
sorted(spec.root.compiler_flags[flag]))):
|
|
||||||
if flag in spec.compiler_flags:
|
|
||||||
spec.compiler_flags[flag] = list(
|
|
||||||
set(spec.compiler_flags[flag]) |
|
|
||||||
set(spec.root.compiler_flags[flag]))
|
|
||||||
else:
|
|
||||||
spec.compiler_flags[
|
|
||||||
flag] = spec.root.compiler_flags[flag]
|
|
||||||
ret = True
|
|
||||||
else:
|
|
||||||
if flag not in spec.compiler_flags:
|
|
||||||
spec.compiler_flags[flag] = []
|
|
||||||
|
|
||||||
# Include the compiler flag defaults from the config files
|
# Include the compiler flag defaults from the config files
|
||||||
# This ensures that spack will detect conflicts that stem from a change
|
# This ensures that spack will detect conflicts that stem from a change
|
||||||
@ -419,19 +404,11 @@ def concretize_compiler_flags(self, spec):
|
|||||||
compiler = spack.compilers.compiler_for_spec(
|
compiler = spack.compilers.compiler_for_spec(
|
||||||
spec.compiler, spec.architecture)
|
spec.compiler, spec.architecture)
|
||||||
for flag in compiler.flags:
|
for flag in compiler.flags:
|
||||||
if flag not in spec.compiler_flags:
|
config_flags = set(compiler.flags.get(flag, []))
|
||||||
spec.compiler_flags[flag] = compiler.flags[flag]
|
flags = set(spec.compiler_flags.get(flag, []))
|
||||||
if compiler.flags[flag] != []:
|
spec.compiler_flags[flag] = list(config_flags | flags)
|
||||||
|
if (config_flags - flags):
|
||||||
ret = True
|
ret = True
|
||||||
else:
|
|
||||||
if ((sorted(spec.compiler_flags[flag]) !=
|
|
||||||
sorted(compiler.flags[flag])) and
|
|
||||||
(not set(spec.compiler_flags[flag]) >=
|
|
||||||
set(compiler.flags[flag]))):
|
|
||||||
ret = True
|
|
||||||
spec.compiler_flags[flag] = list(
|
|
||||||
set(spec.compiler_flags[flag]) |
|
|
||||||
set(compiler.flags[flag]))
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -175,6 +175,16 @@ def test_provides_handles_multiple_providers_of_same_vesrion(self):
|
|||||||
assert Spec('builtin.mock.multi-provider-mpi@1.10.0') in providers
|
assert Spec('builtin.mock.multi-provider-mpi@1.10.0') in providers
|
||||||
assert Spec('builtin.mock.multi-provider-mpi@1.8.8') in providers
|
assert Spec('builtin.mock.multi-provider-mpi@1.8.8') in providers
|
||||||
|
|
||||||
|
def test_different_compilers_get_different_flags(self):
|
||||||
|
client = Spec('cmake-client %gcc@4.7.2 platform=test os=fe target=fe' +
|
||||||
|
' ^cmake %clang@3.5 platform=test os=fe target=fe')
|
||||||
|
client.concretize()
|
||||||
|
cmake = client['cmake']
|
||||||
|
assert set(client.compiler_flags['cflags']) == set(['-O0'])
|
||||||
|
assert set(cmake.compiler_flags['cflags']) == set(['-O3'])
|
||||||
|
assert set(client.compiler_flags['fflags']) == set(['-O0'])
|
||||||
|
assert not set(cmake.compiler_flags['fflags'])
|
||||||
|
|
||||||
def concretize_multi_provider(self):
|
def concretize_multi_provider(self):
|
||||||
s = Spec('mpileaks ^multi-provider-mpi@3.0')
|
s = Spec('mpileaks ^multi-provider-mpi@3.0')
|
||||||
s.concretize()
|
s.concretize()
|
||||||
|
Loading…
Reference in New Issue
Block a user