diff --git a/conf/real-from-ideal/proj.yaml b/conf/real-from-ideal/proj.yaml index 8e23cfdc2764796f31dce135b86cea53a9b91b63..c6d79d68ca4fe91f751d96eb977705de3781b5a6 100644 --- a/conf/real-from-ideal/proj.yaml +++ b/conf/real-from-ideal/proj.yaml @@ -2,10 +2,11 @@ spack: #url: git@gitlab.physik.uni-muenchen.de:LDAP_rbg/spack.git #branch: lmu/ubuntu20.04-icon #compiler: gcc@11.3.0 - url: https://github.com/spack/spack.git - branch: develop - compiler: gcc@12.2.0 - root: "%HPCROOTDIR%/spack" # path to a spack install, will be cloned with git if not present + init: # command to load spack environment, e.g. module load spack, use spack/setup-env.sh if empty + url: https://github.com/spack/spack.git # url to download spack if necessary + branch: develop # if downloaded, branch name to use + compiler: gcc@12.2.0 # desired compiler for spack + root: "%HPCROOTDIR%/spack" # path to a spack install, will be downloaded to if not present user_cache_path: "%HPCROOTDIR%/spack_user_cache_path" # spack puts data here when bootstrapping, leave empty to use home folder disable_local_config: true # if false, spack install into home folder diff --git a/platforms/common/spack_utils.sh b/platforms/common/spack_utils.sh index fab55d4d6ec77329be5874e34e532cfb71e4f35d..aec1794f74f4b0a0257fd6c60faddba49d65ead0 100644 --- a/platforms/common/spack_utils.sh +++ b/platforms/common/spack_utils.sh @@ -1,16 +1,10 @@ -# static settings when using spack -function spack_env() { -export SPACK_SETUP_ENV=$SPACK_ROOT/share/spack/setup-env.sh -} - function _install_spack() { -spack_env - -if [ ! -f ${SPACK_ROOT} ]; then +if [ ! -e ${SPACK_ROOT} ]; then + echo "Cloning to ${SPACK_ROOT}" git clone ${SPACK_URL} -b ${SPACK_BRANCH} ${SPACK_ROOT} fi -. ${SPACK_SETUP_ENV} +_init_spack if [[ $(spack compiler info ${SPACK_COMPILER}) ]]; then echo "Found Compiler $(spack compiler info ${SPACK_COMPILER})" @@ -21,18 +15,44 @@ else fi } +function _init_spack() { +SPACK_INIT_CMD=$1 +SPACK_ROOT=$2 +if [ -z "$SPACK_INIT_CMD" ] && [ ! -z "${SPACK_ROOT}" ]; then + echo "Empty SPACK_INIT_CMD -> trying to source config file of spack root: $SPACK_ROOT/share/spack/setup-env.sh" + . $SPACK_ROOT/share/spack/setup-env.sh +else + echo "Executing SPACK_INIT_CMD: $SPACK_INIT_CMD" + $SPACK_INIT_CMD +fi +} + function load_spack() { -export SPACK_ROOT=$1 -export SPACK_URL=$2 -export SPACK_BRANCH=$3 -export SPACK_COMPILER=$4 -export SPACK_DISABLE_LOCAL_CONFIG=$5 -export SPACK_USER_CACHE_PATH=$6 -if [ ! -z "$SPACK_USER_CACHE_PATH" ]; then - echo "setting SPACK_USER_CACHE_PATH=$SPACK_USER_CACHE_PATH" +export SPACK_INIT_CMD=$1 +export SPACK_ROOT=${2:-spack} +export SPACK_URL=${3:-https://github.com/spack/spack.git} +export SPACK_BRANCH=${4:-develop} +export SPACK_COMPILER=${5:-gcc@12.2.0} +export SPACK_DISABLE_LOCAL_CONFIG=${6:-true} +export SPACK_USER_CACHE_PATH=${7:-${SPACK_ROOT}/spack_user_cache_path} + +echo "SPACK_INIT_CMD = $SPACK_INIT_CMD" +echo "SPACK_ROOT = $SPACK_ROOT" +echo "SPACK_URL = $SPACK_URL" +echo "SPACK_BRANCH = $SPACK_BRANCH" +echo "SPACK_COMPILER = $SPACK_COMPILER" +echo "SPACK_DISABLE_LOCAL_CONFIG = $SPACK_DISABLE_LOCAL_CONFIG" +echo "SPACK_USER_CACHE_PATH = $SPACK_USER_CACHE_PATH" + +if [ -z "$SPACK_USER_CACHE_PATH" ]; then + unset SPACK_USER_CACHE_PATH fi -spack_env -if [ ! -f ${SPACK_ROOT} ]; then _install_spack; fi -. ${SPACK_SETUP_ENV} + + +if [ ! -e ${SPACK_ROOT} ] && [ ! -z "${SPACK_ROOT}" ] ; then _install_spack; fi + +_init_spack "$SPACK_INIT_CMD" "$SPACK_ROOT" + +echo "Using spack from $(which spack)" } diff --git a/templates/common/build_icon.sh b/templates/common/build_icon.sh index 75789e773dca35fb0ee9fd76e165929342037627..40052bffab81e95f580c0dacfd8d9f51a9a32bc1 100644 --- a/templates/common/build_icon.sh +++ b/templates/common/build_icon.sh @@ -12,7 +12,7 @@ fi cd ${WORKDIR} . ${WORKDIR}/proj/platforms/common/spack_utils.sh -load_spack "%spack.root%" "%spack.url%" "%spack.branch%" "%spack.compiler%" "%spack.disable_local_config%" "%spack.user_cache_path%" +load_spack "%spack.init%" "%spack.root%" "%spack.url%" "%spack.branch%" "%spack.compiler%" "%spack.disable_local_config%" "%spack.user_cache_path%" SPACK_BUILD_ICON=%icon.spack_cmd% if [ ! -z $SPACK_BUILD_ICON ]; then