Simplify implementation of "get_compiler_config" (#37989)

This commit is contained in:
Massimiliano Culpo 2023-05-31 00:11:33 +02:00
parent 5821746258
commit 16cb6ac1ed

View File

@ -112,36 +112,26 @@ def _to_dict(compiler):
def get_compiler_config(scope=None, init_config=True): def get_compiler_config(scope=None, init_config=True):
"""Return the compiler configuration for the specified architecture.""" """Return the compiler configuration for the specified architecture."""
def init_compiler_config(): config = spack.config.get("compilers", scope=scope) or []
"""Compiler search used when Spack has no compilers.""" if config or not init_config:
compilers = find_compilers() return config
compilers_dict = []
for compiler in compilers:
compilers_dict.append(_to_dict(compiler))
spack.config.set("compilers", compilers_dict, scope=scope)
merged_config = spack.config.get("compilers")
if merged_config:
return config
_init_compiler_config(scope=scope)
config = spack.config.get("compilers", scope=scope) config = spack.config.get("compilers", scope=scope)
# Update the configuration if there are currently no compilers return config
# configured. Avoid updating automatically if there ARE site
# compilers configured but no user ones.
if not config and init_config: def _init_compiler_config(*, scope):
if scope is None: """Compiler search used when Spack has no compilers."""
# We know no compilers were configured in any scope. compilers = find_compilers()
init_compiler_config() compilers_dict = []
config = spack.config.get("compilers", scope=scope) for compiler in compilers:
elif scope == "user": compilers_dict.append(_to_dict(compiler))
# Check the site config and update the user config if spack.config.set("compilers", compilers_dict, scope=scope)
# nothing is configured at the site level.
site_config = spack.config.get("compilers", scope="site")
sys_config = spack.config.get("compilers", scope="system")
if not site_config and not sys_config:
init_compiler_config()
config = spack.config.get("compilers", scope=scope)
return config
elif config:
return config
else:
return [] # Return empty list which we will later append to.
def compiler_config_files(): def compiler_config_files():