From 2129eca951048c9eaee2a1c348fbcd8c16cf734f Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Wed, 13 Mar 2024 10:21:27 -0700 Subject: [PATCH] fix compilers init_config --- lib/spack/spack/bootstrap/config.py | 2 +- lib/spack/spack/cmd/compiler.py | 2 +- lib/spack/spack/compilers/__init__.py | 15 ++++++++++----- lib/spack/spack/cray_manifest.py | 2 +- lib/spack/spack/environment/environment.py | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/spack/spack/bootstrap/config.py b/lib/spack/spack/bootstrap/config.py index 6786bc0d3ea..48e0dc7041e 100644 --- a/lib/spack/spack/bootstrap/config.py +++ b/lib/spack/spack/bootstrap/config.py @@ -147,7 +147,7 @@ def _add_compilers_if_missing() -> None: mixed_toolchain=sys.platform == "darwin" ) if new_compilers: - spack.compilers.add_compilers_to_config(new_compilers, init_config=False) + spack.compilers.add_compilers_to_config(new_compilers) @contextlib.contextmanager diff --git a/lib/spack/spack/cmd/compiler.py b/lib/spack/spack/cmd/compiler.py index 76eb8d31508..2871a1caa5f 100644 --- a/lib/spack/spack/cmd/compiler.py +++ b/lib/spack/spack/cmd/compiler.py @@ -103,7 +103,7 @@ def compiler_find(args): paths, scope=None, mixed_toolchain=args.mixed_toolchain ) if new_compilers: - spack.compilers.add_compilers_to_config(new_compilers, scope=args.scope, init_config=False) + spack.compilers.add_compilers_to_config(new_compilers, scope=args.scope) n = len(new_compilers) s = "s" if n > 1 else "" diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py index c089164aade..63afcda01ae 100644 --- a/lib/spack/spack/compilers/__init__.py +++ b/lib/spack/spack/compilers/__init__.py @@ -109,7 +109,7 @@ def _to_dict(compiler): return {"compiler": d} -def get_compiler_config(scope=None, init_config=True): +def get_compiler_config(scope=None, init_config=False): """Return the compiler configuration for the specified architecture.""" config = spack.config.get("compilers", scope=scope) or [] @@ -118,6 +118,8 @@ def get_compiler_config(scope=None, init_config=True): merged_config = spack.config.get("compilers") if merged_config: + # Config is empty for this scope + # Do not init config because there is a non-empty scope return config _init_compiler_config(scope=scope) @@ -234,14 +236,14 @@ def compiler_config_files(): return config_files -def add_compilers_to_config(compilers, scope=None, init_config=True): +def add_compilers_to_config(compilers, scope=None): """Add compilers to the config for the specified architecture. Arguments: compilers: a list of Compiler objects. scope: configuration scope to modify. """ - compiler_config = get_compiler_config(scope, init_config) + compiler_config = get_compiler_config(scope, init_config=False) for compiler in compilers: if not compiler.cc: tty.debug(f"{compiler.spec} does not have a C compiler") @@ -290,7 +292,7 @@ def _remove_compiler_from_scope(compiler_spec, scope): True if one or more compiler entries were actually removed, False otherwise """ assert scope is not None, "a specific scope is needed when calling this function" - compiler_config = get_compiler_config(scope) + compiler_config = get_compiler_config(scope, init_config=False) filtered_compiler_config = [ compiler_entry for compiler_entry in compiler_config @@ -313,8 +315,11 @@ def all_compilers_config(scope=None, init_config=True): """Return a set of specs for all the compiler versions currently available to build with. These are instances of CompilerSpec. """ - from_compilers_yaml = get_compiler_config(scope, init_config) from_packages_yaml = get_compiler_config_from_packages(scope) + if from_packages_yaml: + init_config = False + from_compilers_yaml = get_compiler_config(scope, init_config) + result = from_compilers_yaml + from_packages_yaml key = lambda c: _compiler_from_config_entry(c["compiler"]) return list(llnl.util.lang.dedupe(result, key=key)) diff --git a/lib/spack/spack/cray_manifest.py b/lib/spack/spack/cray_manifest.py index 48ec52d782d..bd4a1c8bf55 100644 --- a/lib/spack/spack/cray_manifest.py +++ b/lib/spack/spack/cray_manifest.py @@ -227,7 +227,7 @@ def read(path, apply_updates): if apply_updates and compilers: for compiler in compilers: try: - spack.compilers.add_compilers_to_config([compiler], init_config=False) + spack.compilers.add_compilers_to_config([compiler]) except Exception: warnings.warn( f"Could not add compiler {str(compiler.spec)}: " diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 5d6273506ec..638d87e80ec 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -1554,7 +1554,7 @@ def _concretize_separately(self, tests=False): # Ensure we have compilers in compilers.yaml to avoid that # processes try to write the config file in parallel - _ = spack.compilers.get_compiler_config() + _ = spack.compilers.get_compiler_config(init_config=True) # Early return if there is nothing to do if len(args) == 0: