Cache compilers parsed from config files
- Spack ends up constructing compilers frequently from YAML data. - This caches the result of parsing the compiler config - The logic in compilers/__init__.py could use a bigger cleanup, but this makes concretization much faster for now. - on macOS, this also ensures that xcrun is called only twice, as opposed to every time a new compiler object is constructed.
This commit is contained in:
parent
2e1aa0a5e9
commit
55f85f2307
@ -45,6 +45,9 @@
|
||||
'extra_rpaths']
|
||||
_cache_config_file = []
|
||||
|
||||
#: cache of compilers constructed from config data, keyed by config entry id.
|
||||
_compiler_cache = {}
|
||||
|
||||
|
||||
def _auto_compiler_spec(function):
|
||||
def converter(cspec_like, *args, **kwargs):
|
||||
@ -251,35 +254,42 @@ def compilers_for_arch(arch_spec, scope=None):
|
||||
|
||||
|
||||
def compiler_from_config_entry(items):
|
||||
cspec = spack.spec.CompilerSpec(items['spec'])
|
||||
os = items.get('operating_system', None)
|
||||
target = items.get('target', None)
|
||||
config_id = id(items)
|
||||
compiler = _compiler_cache.get(config_id, None)
|
||||
|
||||
if not ('paths' in items and
|
||||
all(n in items['paths'] for n in _path_instance_vars)):
|
||||
raise InvalidCompilerConfigurationError(cspec)
|
||||
if compiler is None:
|
||||
cspec = spack.spec.CompilerSpec(items['spec'])
|
||||
os = items.get('operating_system', None)
|
||||
target = items.get('target', None)
|
||||
|
||||
cls = class_for_compiler_name(cspec.name)
|
||||
if not ('paths' in items and
|
||||
all(n in items['paths'] for n in _path_instance_vars)):
|
||||
raise InvalidCompilerConfigurationError(cspec)
|
||||
|
||||
compiler_paths = []
|
||||
for c in _path_instance_vars:
|
||||
compiler_path = items['paths'][c]
|
||||
if compiler_path != 'None':
|
||||
compiler_paths.append(compiler_path)
|
||||
else:
|
||||
compiler_paths.append(None)
|
||||
cls = class_for_compiler_name(cspec.name)
|
||||
|
||||
mods = items.get('modules')
|
||||
if mods == 'None':
|
||||
mods = []
|
||||
compiler_paths = []
|
||||
for c in _path_instance_vars:
|
||||
compiler_path = items['paths'][c]
|
||||
if compiler_path != 'None':
|
||||
compiler_paths.append(compiler_path)
|
||||
else:
|
||||
compiler_paths.append(None)
|
||||
|
||||
alias = items.get('alias', None)
|
||||
compiler_flags = items.get('flags', {})
|
||||
environment = items.get('environment', {})
|
||||
extra_rpaths = items.get('extra_rpaths', [])
|
||||
mods = items.get('modules')
|
||||
if mods == 'None':
|
||||
mods = []
|
||||
|
||||
return cls(cspec, os, target, compiler_paths, mods, alias,
|
||||
environment, extra_rpaths, **compiler_flags)
|
||||
alias = items.get('alias', None)
|
||||
compiler_flags = items.get('flags', {})
|
||||
environment = items.get('environment', {})
|
||||
extra_rpaths = items.get('extra_rpaths', [])
|
||||
|
||||
compiler = cls(cspec, os, target, compiler_paths, mods, alias,
|
||||
environment, extra_rpaths, **compiler_flags)
|
||||
_compiler_cache[id(items)] = compiler
|
||||
|
||||
return compiler
|
||||
|
||||
|
||||
def get_compilers(config, cspec=None, arch_spec=None):
|
||||
|
Loading…
Reference in New Issue
Block a user