From 8ec098716b977544ed16eb45cfa78f74d19f51ff Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Sat, 20 Jul 2019 02:42:12 -0500 Subject: compilers: don't raise errors for duplicate compiler definitions (#11910) Summary: - Allow multiple definitions of compiler in compilers.yaml (use first instance) - Still print debug messages when there are duplicates, to assist users in finding this issue. Merging configs from different scopes can result in multiple compiler being present in the same configuration list. Instead of raising when there are duplicates, take the one with highest precedence. Print a debug message instead of raising, so that we can still diagnose this. We don't have a good way of warning the user about inconsistent configuration *in the same file* -- we'd need to dig into YAML file/line info for that. --- lib/spack/spack/compilers/__init__.py | 4 +++- lib/spack/spack/test/compilers.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py index 84f767d1dd..5adfd17b1a 100644 --- a/lib/spack/spack/compilers/__init__.py +++ b/lib/spack/spack/compilers/__init__.py @@ -383,7 +383,9 @@ def compiler_for_spec(compiler_spec, arch_spec): if len(compilers) < 1: raise NoCompilerForSpecError(compiler_spec, arch_spec.os) if len(compilers) > 1: - raise CompilerDuplicateError(compiler_spec, arch_spec) + msg = 'Multiple definitions of compiler %s' % compiler_spec + msg += 'for architecture %s:\n %s' % (arch_spec, compilers) + tty.debug(msg) return compilers[0] diff --git a/lib/spack/spack/test/compilers.py b/lib/spack/spack/test/compilers.py index 1b66b692e0..84233d604f 100644 --- a/lib/spack/spack/test/compilers.py +++ b/lib/spack/spack/test/compilers.py @@ -50,6 +50,32 @@ def make_args_for_version(monkeypatch): return _factory +def test_multiple_conflicting_compiler_definitions(mutable_config): + compiler_def = { + 'compiler': { + 'flags': {}, + 'modules': [], + 'paths': { + 'cc': 'cc', + 'cxx': 'cxx', + 'f77': 'null', + 'fc': 'null'}, + 'extra_rpaths': [], + 'operating_system': 'test', + 'target': 'test', + 'environment': {}, + 'spec': 'clang@0.0.0'}} + + compiler_config = [compiler_def, compiler_def] + compiler_config[0]['compiler']['paths']['f77'] = 'f77' + mutable_config.update_config('compilers', compiler_config) + + arch_spec = spack.spec.ArchSpec('test', 'test', 'test') + cspec = compiler_config[0]['compiler']['spec'] + cmp = compilers.compiler_for_spec(cspec, arch_spec) + assert cmp.f77 == 'f77' + + def test_get_compiler_duplicates(config): # In this case there is only one instance of the specified compiler in # the test configuration (so it is not actually a duplicate), but the -- cgit v1.2.3-60-g2f50