'If the spec already has a compiler, we\'re done.  If not, then take
the compiler used for the nearest ancestor with a compiler
spec and use that.  If the ancestor\'s compiler is not
concrete, then used the preferred compiler as specified in
spackconfig.
Intuition: Use the spackconfig default if no package that depends on
this one has a strict compiler requirement.  Otherwise, try to
build with the compiler that will be used by libraries that
link to this one, to maximize compatibility.'

def concretize_compiler(self, spec):

    if (not (spec.architecture.platform_os and spec.architecture.target)):
        return True
    def _proper_compiler_style(cspec, aspec):
        return spack.compilers.compilers_for_spec(cspec, arch_spec=aspec)
    all_compiler_specs = spack.compilers.all_compiler_specs()
    if (not all_compiler_specs):
        raise spack.compilers.NoCompilersError()
    if (spec.compiler and spec.compiler.concrete and (spec.compiler in all_compiler_specs)):
        if (not _proper_compiler_style(spec.compiler, spec.architecture)):
            _compiler_concretization_failure(spec.compiler, spec.architecture)
        return False
    other_spec = (spec if spec.compiler else find_spec(spec, (lambda x: x.compiler), spec.root))
    other_compiler = other_spec.compiler
    assert other_spec
    if (other_compiler in all_compiler_specs):
        spec.compiler = other_compiler.copy()
        if (not _proper_compiler_style(spec.compiler, spec.architecture)):
            _compiler_concretization_failure(spec.compiler, spec.architecture)
        return True
    compiler_list = (all_compiler_specs if (not other_compiler) else spack.compilers.find(other_compiler))
    if (not compiler_list):
        raise UnavailableCompilerVersionError(other_compiler)
    ppk = PackagePrefs(other_spec.name, 'compiler')
    matches = sorted(compiler_list, key=ppk)
    try:
        spec.compiler = next((c for c in matches if _proper_compiler_style(c, spec.architecture))).copy()
    except StopIteration:
        _compiler_concretization_failure(other_compiler, spec.architecture)
    assert spec.compiler.concrete
    return True
