From 8da43f41b66b5f38a2b99be846ed9c4197162e43 Mon Sep 17 00:00:00 2001
From: Philipp Spilger <philipp.spilger@kip.uni-heidelberg.de>
Date: Fri, 10 Sep 2021 11:16:23 +0200
Subject: [PATCH] Make spack folder location configurable and available via env
 var

Change-Id: I8d17a81df6ccd47d3bb956b50131a1aba16babf4
---
 .ci/Jenkinsfile                |  1 +
 .ci/Jenkinsfile_asic           |  1 +
 .ci/build_image.sh             |  2 +-
 .ci/dump_meta_info.sh          |  2 +-
 .ci/fetch.sh                   | 10 +++++-----
 .ci/visionary_create_recipe.sh |  2 +-
 6 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile
index 49946ce4..b50c89d4 100755
--- a/.ci/Jenkinsfile
+++ b/.ci/Jenkinsfile
@@ -36,6 +36,7 @@ pipeline {
 			environment {
 				DOCKER_BASE_IMAGE = "debian:bullseye"
 				DEPENDENCY_PYTHON = "python@3.8.2"
+				YASHCHIKI_SPACK_PATH = "${env.WORKSPACE}/spack"
 				YASHCHIKI_IMAGE_NAME = "singularity_visionary_temp.img"
 				YASHCHIKI_SANDBOXES = "sandboxes"
 				YASHCHIKI_PROXY_HTTP = "http://proxy.kip.uni-heidelberg.de:8080"
diff --git a/.ci/Jenkinsfile_asic b/.ci/Jenkinsfile_asic
index 8b75e143..d1f25437 100755
--- a/.ci/Jenkinsfile_asic
+++ b/.ci/Jenkinsfile_asic
@@ -38,6 +38,7 @@ pipeline {
 				DOCKER_BASE_IMAGE = "centos:7"
 				// versions from system packages
 				DEPENDENCY_PYTHON = "python@3.8.3"
+				YASHCHIKI_SPACK_PATH = "${env.WORKSPACE}/spack"
 				YASHCHIKI_IMAGE_NAME = "singularity_asic_temp.img"
 				YASHCHIKI_SANDBOXES = "sandboxes"
 				YASHCHIKI_PROXY_HTTP = "http://proxy.kip.uni-heidelberg.de:8080"
diff --git a/.ci/build_image.sh b/.ci/build_image.sh
index 6da77f06..45cffc6b 100755
--- a/.ci/build_image.sh
+++ b/.ci/build_image.sh
@@ -12,7 +12,7 @@ TARGET_FOLDER="$(find ${YASHCHIKI_SANDBOXES} -mindepth 1 -maxdepth 1)"
 
 # We want the spack folder to be available inside the container image
 # -> it needs to be bind mounted to the sandbox folder
-sudo mount --bind "${PWD}/spack" "${TARGET_FOLDER}/opt/spack"
+sudo mount --bind "${YASHCHIKI_SPACK_PATH}" "${TARGET_FOLDER}/opt/spack"
 
 # TODO: singularity 3.1 produces SIF w/o setuid flags on files, using a newer
 # singularity for the image build
diff --git a/.ci/dump_meta_info.sh b/.ci/dump_meta_info.sh
index c41047d2..04ee6e91 100755
--- a/.ci/dump_meta_info.sh
+++ b/.ci/dump_meta_info.sh
@@ -21,7 +21,7 @@ mkdir -p "${META_DIR_OUTSIDE}"
 )
 
 (
-    cd "${WORKSPACE}/spack"
+    cd ${YASHCHIKI_SPACK_PATH}
     git log > "${META_DIR_OUTSIDE}/spack_git.log"
     if [ "${CONTAINER_BUILD_TYPE}" = "testing" ]; then
         gerrit_get_current_change_commits \
diff --git a/.ci/fetch.sh b/.ci/fetch.sh
index 9da04e52..5e9c6ca5 100755
--- a/.ci/fetch.sh
+++ b/.ci/fetch.sh
@@ -9,15 +9,15 @@ source "${SOURCE_DIR}/commons.sh"
 # hard-link source cache into spack folder to avoid duplication.
 # https://github.com/spack/spack/pull/12940 introduced a new format for the
 # cache, so we switch from $HOME/download_cache to $HOME/source_cache
-mkdir -p "${PWD}/spack/var/spack/cache/"
+mkdir -p "${YASHCHIKI_SPACK_PATH}/var/spack/cache/"
 find "${SOURCE_CACHE_DIR}" -mindepth 1 -maxdepth 1 -print0 \
-    | xargs -r -n 1 "-I{}" -0 cp -vrl '{}' "${PWD}/spack/var/spack/cache/"
+    | xargs -r -n 1 "-I{}" -0 cp -vrl '{}' "${YASHCHIKI_SPACK_PATH}/var/spack/cache/"
 
 # set download mirror stuff to prefill outside of container
-export MY_SPACK_FOLDER="$PWD/spack"
+export MY_SPACK_FOLDER="${YASHCHIKI_SPACK_PATH}"
 export MY_SPACK_BIN="${MY_SPACK_FOLDER}/bin/spack"
 
-PATH_COMPILERS="${PWD}/spack/etc/spack/compilers.yaml"
+PATH_COMPILERS="${MY_SPACK_FOLDER}/etc/spack/compilers.yaml"
 
 # Add fake system compiler (needed for fetching)
 # This is NOT the correct version but we need to concretize with the same
@@ -165,7 +165,7 @@ else
 fi
 
 # update cache in any case to store successfully loaded files
-rsync -av "${PWD}/spack/var/spack/cache/" "${SOURCE_CACHE_DIR}/"
+rsync -av "${MY_SPACK_FOLDER}/var/spack/cache/" "${SOURCE_CACHE_DIR}/"
 
 if (( fetch_failed != 0 )); then
     # propagate error
diff --git a/.ci/visionary_create_recipe.sh b/.ci/visionary_create_recipe.sh
index f2f02936..9e7f6233 100755
--- a/.ci/visionary_create_recipe.sh
+++ b/.ci/visionary_create_recipe.sh
@@ -20,7 +20,7 @@ From: ${DOCKER_BASE_IMAGE}
 %setup
     # bind-mount spack-folder as moving involves copying the complete download cache
     mkdir \${SINGULARITY_ROOTFS}/opt/spack
-    mount --no-mtab --bind "${WORKSPACE}/spack" "\${SINGULARITY_ROOTFS}/opt/spack"
+    mount --no-mtab --bind "${YASHCHIKI_SPACK_PATH}" "\${SINGULARITY_ROOTFS}/opt/spack"
     # bind-mount ccache
     mkdir \${SINGULARITY_ROOTFS}/opt/ccache
     mount --no-mtab --bind "${HOME}/spack_ccache" "\${SINGULARITY_ROOTFS}/opt/ccache"
-- 
GitLab