summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2023-05-31 00:11:33 +0200
committerGitHub <noreply@github.com>2023-05-30 15:11:33 -0700
commit8e9efa86c8c14c1c9172d3dd85a6dca7ec5b8883 (patch)
tree49a9343fc40aade3ef41c93dc3dbf994c72e2e02 /lib
parent84faf5a6cf342efddb976b7432e44aff12f1c985 (diff)
downloadspack-8e9efa86c8c14c1c9172d3dd85a6dca7ec5b8883.tar.gz
spack-8e9efa86c8c14c1c9172d3dd85a6dca7ec5b8883.tar.bz2
spack-8e9efa86c8c14c1c9172d3dd85a6dca7ec5b8883.tar.xz
spack-8e9efa86c8c14c1c9172d3dd85a6dca7ec5b8883.zip
Simplify implementation of "get_compiler_config" (#37989)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/compilers/__init__.py46
1 files changed, 18 insertions, 28 deletions
diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py
index 5d013b1344..c867f927c0 100644
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -112,36 +112,26 @@ def _to_dict(compiler):
def get_compiler_config(scope=None, init_config=True):
"""Return the compiler configuration for the specified architecture."""
- def init_compiler_config():
- """Compiler search used when Spack has no compilers."""
- compilers = find_compilers()
- compilers_dict = []
- for compiler in compilers:
- compilers_dict.append(_to_dict(compiler))
- spack.config.set("compilers", compilers_dict, scope=scope)
-
- config = spack.config.get("compilers", scope=scope)
- # Update the configuration if there are currently no compilers
- # configured. Avoid updating automatically if there ARE site
- # compilers configured but no user ones.
- if not config and init_config:
- if scope is None:
- # We know no compilers were configured in any scope.
- init_compiler_config()
- config = spack.config.get("compilers", scope=scope)
- elif scope == "user":
- # Check the site config and update the user config if
- # 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)
+ config = spack.config.get("compilers", scope=scope) or []
+ if config or not init_config:
return config
- elif config:
+
+ merged_config = spack.config.get("compilers")
+ if merged_config:
return config
- else:
- return [] # Return empty list which we will later append to.
+
+ _init_compiler_config(scope=scope)
+ config = spack.config.get("compilers", scope=scope)
+ return config
+
+
+def _init_compiler_config(*, scope):
+ """Compiler search used when Spack has no compilers."""
+ compilers = find_compilers()
+ compilers_dict = []
+ for compiler in compilers:
+ compilers_dict.append(_to_dict(compiler))
+ spack.config.set("compilers", compilers_dict, scope=scope)
def compiler_config_files():