#!/usr/bin/env sh set -o errexit set -o pipefail set -o nounset source ${CI_PROJECT_DIR}/ci/stack_env.sh mkdir -p ${STACK_LOCATION} cd ${STACK_LOCATION} echo "Setting up spack" if [ ! -d spack/.git ]; then git clone https://github.com/spack/spack.git else git -C spack fetch # git -C spack pull fi git -C spack checkout $SPACK_VERSION echo "Adding spack system config file" echo mkdir -p ${SPACK_SYSTEM_CONFIG_PATH} mkdir -p ${SPACK_SYSTEM_CONFIG_PATH} EXTERNAL_REPOS=$(jq -r '.spack.repos | keys[]' ${STACK_CONFIG}) for file in mirrors.yaml packages.yaml concretizer.yaml config.yaml spack.yaml do if [ -e "${STACK_CONFIG_PATH}/${file}" ]; then echo "Copying ${STACK_CONFIG_PATH}/${file} to ${SPACK_SYSTEM_CONFIG_PATH}" cp "${STACK_CONFIG_PATH}/${file}" ${SPACK_SYSTEM_CONFIG_PATH} fi done echo "Setting up extra repos" spack_external_repos=external_repos mkdir -p ${spack_external_repos} echo "repos:" > ${SPACK_SYSTEM_CONFIG_PATH}/repos.yaml for repo in ${EXTERNAL_REPOS} do repo_branch=$(jq -r ".spack.repos.\"${repo}\".branch" ${STACK_CONFIG}) echo " - ${spack_external_repos}/${repo}" echo " - ${STACK_LOCATION}/${spack_external_repos}/${repo}" >> ${SPACK_SYSTEM_CONFIG_PATH}/repos.yaml if [ ! -d ${spack_external_repos}/${repo} ]; then echo "Cloning repo: ${repo}" url_branch=$(jq -r ".spack.repos.\"${repo}\".url" ${STACK_CONFIG}) git clone -b ${repo_branch} ${url_branch} ${spack_external_repos}/${repo} else echo "Update repo: ${repo}" git -C ${spack_external_repos}/$repo fetch git -C ${spack_external_repos}/$repo checkout ${repo_branch} git -C ${spack_external_repos}/$repo pull fi done echo "Setting up buildcache" spack/bin/spack gpg trust \ $GPG_PRIVATE_KEY if [ ! -d /buildcache/build_cache ]; then spack/bin/spack gpg publish \ -d /buildcache fi if ! spack/bin/spack mirror list | grep buildcache; then echo "Add buildcache in mirrors" spack/bin/spack mirror add \ --type binary \ --scope system \ buildcache file:///buildcache fi spack/bin/spack buildcache keys \ --install \ --trust #spack/bin/spack buildcache update-index /buildcache target=$(jq -Mrc --arg env "${environment}" ' .environments | to_entries | map(select(.key==env.environment)) | .[].value.target ' ${STACK_CONFIG}) require=$(jq -Mrc --arg environment "${environment}" ' .environments | to_entries | map(select(.key==env.environment)) | .[].value | if has("require") then .require | map(" - spec: \(.spec)\n when: \(.when)") | .[] else "" end' ${STACK_CONFIG}) cat <<EOF > ${SPACK_SYSTEM_CONFIG_PATH}/packages_env.yaml packages: all: target: [$target] EOF if [ "x$require" != "x" ] then echo " require:" >> ${SPACK_SYSTEM_CONFIG_PATH}/packages_env.yaml echo "${require}" >> ${SPACK_SYSTEM_CONFIG_PATH}/packages_env.yaml fi