#!/usr/bin/env sh set -o errexit set -o pipefail set -o nounset source ${CI_PROJECT_DIR}/ci/stack_env.sh echo "Getting system compiler" ${STACK_LOCATION}/spack/bin/spack compiler find --scope system /usr for c in "core_compilers" "compilers"; do echo "Installing $c" _specs=$(comp=$c jq -Mr ' .stack | .system_arch as $arch | with_entries(select(.key==env.comp)) | to_entries | .[].value | map(select((.constraint == null) or (.constraint? | match(env.environment)))) | map("\(.spec) \($arch)")[] ' ${STACK_CONFIG}) echo "Compilers to install:" echo "${_specs}" if [ "x${_specs}" != "x" ]; then ${STACK_LOCATION}/spack/bin/spack spec \ --install-status \ --namespaces \ --long \ --types \ ${_specs} ${STACK_LOCATION}/spack/bin/spack spec \ --install-status \ --namespaces \ --long \ --types \ --json \ ${_specs} > compilers_spec.json ${STACK_LOCATION}/spack/bin/spack install \ --log-file ${MOUNT_POINT}/spack-install-${c}.xml \ --log-format junit \ --fail-fast \ --show-log-on-error \ ${_specs} hashes=$(jq -Mr '.spec.nodes | map("/\(.hash)") | join(" ")' compilers_spec.json) echo "Adding packages to buildcache" ${STACK_LOCATION}/spack/bin/spack buildcache create \ --update-index \ --key EDC904DCE3D2E84E \ ${MOUNT_POINT}/buildcache ${hashes} for compiler_hash in $(echo ${hashes}); do location=$(${STACK_LOCATION}/spack/bin/spack location -i ${compiler_hash}) # echo "Checking for compiler" # echo " - ${location}" # echo " - ${location}/compiler/latest" # echo " - ${location}/compiler/latest/linux" # echo " - ${location}/Linux_x86_64/2024/compilers" ${STACK_LOCATION}/spack/bin/spack compiler find \ --scope system \ ${location} \ ${location}/compiler/latest \ ${location}/compiler/latest/linux \ ${location}/Linux_x86_64/2024/compilers done fi done compilers_specs=$(jq -Mr ' .stack | .system_arch as $arch | .core_compilers + .compilers | map(select(.constraint == null)) | map("\(.spec) \($arch)") ' ${STACK_CONFIG}) system_compiler=$(jq -Mrc ' .stack | .system_arch as $arch | .system_compiler | map("\(.compiler)@\(.version) \($arch)") ' ${STACK_CONFIG}) core_compilers=$(jq -Mrc '.stack | .system_arch as $arch | .system_compiler + .core_compilers | map("\(.compiler)@\(.version) \($arch)") ' ${STACK_CONFIG}) compilers=$(jq -Mrc '.stack | .compilers | map(select(.constraint == null)) | map("\(.compiler)@\(.version) target=\(env.target)") ' ${STACK_CONFIG}) echo "definitions:" > ${SPACK_SYSTEM_CONFIG_PATH}/compiler_definitions.yaml set +o nounset for c in "compilers_specs" "system_compiler" "core_compilers" "compilers"; do if [ "x${!c}" != "x" ]; then echo " - ${c}: ${!c}" >> ${SPACK_SYSTEM_CONFIG_PATH}/compiler_definitions.yaml fi done set -o nounset jq -Mrc ' .stack | .system_arch as $arch | .compilers | map(select(.constraint != null)) | map(" - when: \(.constraint)\n compilers_specs: [\(.spec) \($arch)]") | .[] ' ${STACK_CONFIG} >> ${SPACK_SYSTEM_CONFIG_PATH}/compiler_definitions.yaml jq -Mrc ' .stack | .system_arch as $arch | .compilers | to_entries | map(select(.value.constraint == null)) | map(" - compiler_\(.key): [\(.value.compiler)@\(.value.version) target=\(env.target)]") | .[] ' ${STACK_CONFIG} >> ${SPACK_SYSTEM_CONFIG_PATH}/compiler_definitions.yaml jq -Mrc ' .stack | .system_arch as $arch | .compilers | to_entries | map(select(.value.constraint != null)) | map(" - compiler_\(.key): []\n - when: \(.value.constraint)\n compiler_\(.key): [\(.value.compiler)@\(.value.version) target=\(env.target)]") | .[] ' ${STACK_CONFIG} >> ${SPACK_SYSTEM_CONFIG_PATH}/compiler_definitions.yaml cat ${SPACK_SYSTEM_CONFIG_PATH}/compiler_definitions.yaml #yq -y -s ".[0].spack.definitions = .[1].definitions + .[0].spack.definitions | .[0]" ${SPACK_SYSTEM_CONFIG_PATH}/spack.yaml ${SPACK_SYSTEM_CONFIG_PATH}/compiler_definitions.yaml > ${SPACK_SYSTEM_CONFIG_PATH}/spack.yaml.new #mv ${SPACK_SYSTEM_CONFIG_PATH}/spack.yaml.new ${SPACK_SYSTEM_CONFIG_PATH}/spack.yaml