Skip to content

Commit

Permalink
Allow specifying compiler version for 'spack stack create env' (#1294)
Browse files Browse the repository at this point in the history
This PR borrows the logic from #1213 that allows a compiler version to be specified in spack stack create env. It's a couple of tweaks to stack_env.py. This isn't strictly urgent, but I'm hoping to put this in the 1.8.0 release in anticipation of supporting installations by NCO (plus maybe others will find it useful; I know it will be useful for Acorn, and maybe also for NRL?).
  • Loading branch information
AlexanderRichert-NOAA authored Sep 11, 2024
1 parent f3f0ac1 commit 4614f87
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions spack-ext/lib/jcsda-emc/spack-stack/stack/stack_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self, **kwargs):

if not self.name:
# site = self.site if self.site else 'default'
self.name = "{}.{}.{}".format(self.template, self.site, self.compiler)
self.name = "{}.{}.{}".format(self.template, self.site, self.compiler.replace("@", "-"))

def env_dir(self):
"""env_dir is <dir>/<name>"""
Expand Down Expand Up @@ -170,7 +170,7 @@ def _copy_common_includes(self):
self._copy_or_merge_includes("modules", modules_yaml_path, modules_yaml_modulesys_path, destination)
# Merge or copy common package config(s)
packages_yaml_path = os.path.join(common_path, "packages.yaml")
packages_compiler_yaml_path = os.path.join(common_path, f"packages_{self.compiler}.yaml")
packages_compiler_yaml_path = os.path.join(common_path, f"packages_{self.compiler.split('@')[0]}.yaml")
destination = os.path.join(env_common_dir, "packages.yaml")
self._copy_or_merge_includes("packages", packages_yaml_path, packages_compiler_yaml_path, destination)

Expand Down Expand Up @@ -203,7 +203,7 @@ def _copy_site_includes(self):
self._copy_or_merge_includes("modules", modules_yaml_path, modules_yaml_modulesys_path, destination)
# Merge or copy site package config(s)
packages_yaml_path = os.path.join(env_path, "packages.yaml")
packages_compiler_yaml_path = os.path.join(env_path, f"packages_{self.compiler}.yaml")
packages_compiler_yaml_path = os.path.join(env_path, f"packages_{self.compiler.split('@')[0]}.yaml")
destination = os.path.join(env_site_dir, "packages.yaml")
self._copy_or_merge_includes("packages", packages_yaml_path, packages_compiler_yaml_path, destination)

Expand Down Expand Up @@ -263,11 +263,7 @@ def write(self):
target_compiler = f"%{self.compiler}"
for i in range(len(definitions)):
if "compilers" in definitions[i]:
j = len(definitions[i]["compilers"])-1
while j>=0:
if not definitions[i]["compilers"][j] == target_compiler:
definitions[i]["compilers"].pop(j)
j -= 1
definitions[i] = {"compilers": [target_compiler]}
spack.config.set("definitions", definitions, scope=env_scope)

if self.install_prefix:
Expand Down

0 comments on commit 4614f87

Please sign in to comment.