Skip to content
Snippets Groups Projects
Commit b4f6543c authored by Ashwin Kumar Karnad's avatar Ashwin Kumar Karnad
Browse files

remove invoke wrappers

parent 0c0d5827
No related branches found
No related tags found
2 merge requests!19Move linux-debian11 into main,!1Resolve "First draft for user interface for top level install command"
#!/usr/bin/python3
#!/usr/bin/env python3
import os
import subprocess
import time
import invoke
import argparse
# Helper class to change directory via context manager
class os_chdir:
def __init__(self, new_dir):
self.new_dir = new_dir
self.saved_dir = os.getcwd()
def __enter__(self):
os.chdir(self.new_dir)
def __exit__(self, exc_type, exc_val, exc_tb):
os.chdir(self.saved_dir)
@invoke.task(
help={
"mpsd_spack_ver": "MPSD Software stack version (defaults to current branch name)",
"toolchain_list": "Comma separated list of toolchains to build (defaults to all toolchains)",
"toolchain_base_dir": "Base directory to install the toolchains (defaults to '/opt_mpsd/')",
"skip_build_cache": "Skip building the spack cache (defaults to False)",
"skip_dir_check": "Skip checking if toolchains exists ( usefull when restarting after an error)",
}
)
def build_toolchains(
c,
mpsd_spack_ver=None,
toolchain_list=None,
toolchain_base_dir="/opt_mpsd/",
......@@ -25,7 +28,7 @@ def build_toolchains(
"""
Build toolchains using Spack.
This task builds toolchains for toolchains at the appropriate directory for the current system architecture
This function builds toolchains for toolchains at the appropriate directory for the current system architecture
and MPSD software stack version.
The toolchains are built using the bash script spack_setup.sh, and the results are logged.
"""
......@@ -38,13 +41,18 @@ def build_toolchains(
.stdout.decode()
.strip()
)
current_commit_hash = (
subprocess.run(
["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE
)
)
current_dir = os.getcwd()
# Checks
## Check that some mpsd_spack_ver is passed.
if mpsd_spack_ver is None:
raise invoke.Exit(
raise ValueError(
"Error: MPSD_SPACK_VER not passed. Please pass the MPSD Software stack version."
)
## Check if toolchains directory exists
......@@ -54,14 +62,14 @@ def build_toolchains(
os.makedirs(toolchains_path)
else:
if not skip_dir_check:
raise invoke.Exit(
raise ValueError(
f"Error: Toolchains directory {toolchains_path} already exists. \n\
Please remove it and try again."
)
### Clone spack-env repo at spack_env_path
with c.cd(spack_env_path + "/spack-environments"):
c.run("git clone git@gitlab.gwdg.de:mpsd-cs/spack-environments.git .")
c.run(f"git checkout {mpsd_spack_ver}")
with os.chdir(spack_env_path + "/spack-environments"):
subprocess.run("git clone git@gitlab.gwdg.de:mpsd-cs/spack-environments.git .", shell=True, check=True)
subprocess.run(f"git checkout {mpsd_spack_ver}", shell=True, check=True)
## Check if TOOLCHAIN_LIST is valid
available_toolchains = os.listdir("toolchains")
......@@ -77,7 +85,7 @@ def build_toolchains(
# if not set(toolchains)<=set(available_toolchains):
for toolchain in toolchains:
if toolchain not in available_toolchains:
raise invoke.Exit(
raise ValueError(
f"Error: Toolchain '{toolchain}' not found in toolchains directory. \n\
Please check the toolchain argument and try again."
)
......@@ -87,10 +95,11 @@ def build_toolchains(
log_file = f"build_toolchains_{mpsd_spack_ver}_{time.strftime('%Y%m%d-%H%M%S')}.log"
print(f"Building at {toolchains_path}...")
for toolchain in toolchains:
with c.cd(toolchains_path):
c.run(f"echo '>>>> Building {toolchain}...' | tee -a {log_file}")
c.run(
f" bash {spack_env_path}/spack-environments/spack_setup.sh {flags} {toolchain}|tee -a {log_file} 2>&1"
with os_chdir(toolchains_path):
print(f">>>> Building {toolchain}...")
subprocess.run(
f" bash {spack_env_path}/spack-environments/spack_setup.sh {flags} {toolchain}|tee -a {log_file} 2>&1",
shell=True, check=True
)
# copy the octopus configs to the toolchain directory
# c.run(f"cp -r {current_dir}/octopus {toolchains_path}")
# subprocess.run(f"cp -r {current_dir}/octopus
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment