From d8a92c0a54115a066a7a249e3e2103616046ecaf Mon Sep 17 00:00:00 2001
From: Jakob Kaiser <jakob.kaiser@kip.uni-heidelberg.de>
Date: Tue, 25 Jun 2024 10:47:09 +0000
Subject: [PATCH] chore: make yashchiki dependencies more clear

Previously, we called the step where we installed packages needed by
yashchiki "bootstrapping". This is misleading since spack does also a
bootstrapping step which is different from this one.

Change-Id: I7a5ed4849324da8fb755d23c62df6eb67e308b76
---
 lib/yashchiki/commons.sh                      | 10 ++----
 ..._install_routine_called_in_post_as_root.sh |  2 +-
 lib/yashchiki/fetch.sh                        |  2 +-
 ...strap_spack.sh => install_dependencies.sh} | 36 ++++++-------------
 4 files changed, 16 insertions(+), 34 deletions(-)
 rename lib/yashchiki/{bootstrap_spack.sh => install_dependencies.sh} (65%)

diff --git a/lib/yashchiki/commons.sh b/lib/yashchiki/commons.sh
index 4cefda69..6529a50a 100755
--- a/lib/yashchiki/commons.sh
+++ b/lib/yashchiki/commons.sh
@@ -129,13 +129,9 @@ if [ -n "${YASHCHIKI_SPACK_VERBOSE:-}" ]; then
     SPACK_ARGS_REINDEX+=("--verbose")
 fi
 
-# TODO: Keep in sync with <spack-repo>/lib/spack/spack/cmd/bootstrap.py since
-# there is no straight-forward way to extract bootstrap dependencies
-# automatically. If bootstrap dependencies should change we will notice because
-# they won't be able to be fetched inside the container because of missing
-# permissions.
-spack_bootstrap_dependencies=(
-    "environment-modules~X"
+# Dependencies needed by yashchiki
+yashchiki_dependencies=(
+    "environment-modules~X"  # needed for module generation
 )
 
 #########
diff --git a/lib/yashchiki/complete_spack_install_routine_called_in_post_as_root.sh b/lib/yashchiki/complete_spack_install_routine_called_in_post_as_root.sh
index b39dde97..0c36b377 100755
--- a/lib/yashchiki/complete_spack_install_routine_called_in_post_as_root.sh
+++ b/lib/yashchiki/complete_spack_install_routine_called_in_post_as_root.sh
@@ -12,7 +12,7 @@ SOURCE_DIR="$(dirname "$(readlink -m "${BASH_SOURCE[0]}")")"
 source "${SOURCE_DIR}/commons.sh"
 
 "${SPACK_INSTALL_SCRIPTS}/prepare_spack_as_root.sh"
-sudo -Eu spack "${SPACK_INSTALL_SCRIPTS}/bootstrap_spack.sh"
+sudo -Eu spack "${SPACK_INSTALL_SCRIPTS}/install_dependencies.sh"
 
 sudo -Eu spack "${SPACK_INSTALL_SCRIPTS}/install_spack.sh" && \
 sudo -Eu spack ${MY_SPACK_CMD} compiler add --scope site /usr/bin && \
diff --git a/lib/yashchiki/fetch.sh b/lib/yashchiki/fetch.sh
index 362dce95..bba3071c 100755
--- a/lib/yashchiki/fetch.sh
+++ b/lib/yashchiki/fetch.sh
@@ -51,7 +51,7 @@ echo "FETCHING..."
 # concretize all spack packages in parallel
 packages_to_fetch=(
     "${YASHCHIKI_SPACK_GCC}"
-    "${spack_bootstrap_dependencies[@]}"
+    "${yashchiki_dependencies[@]}"
     "${spack_packages[@]}"
 )
 # verify that all concretizations were successful
diff --git a/lib/yashchiki/bootstrap_spack.sh b/lib/yashchiki/install_dependencies.sh
similarity index 65%
rename from lib/yashchiki/bootstrap_spack.sh
rename to lib/yashchiki/install_dependencies.sh
index 18bfa9de..d2a48626 100755
--- a/lib/yashchiki/bootstrap_spack.sh
+++ b/lib/yashchiki/install_dependencies.sh
@@ -1,6 +1,7 @@
 #!/bin/bash
 #
-# Prepare spack by bootstrapping and installing the compiler via spack
+# Install dependencies needed during the spack install
+# process and the container creation.
 #
 set -euo pipefail
 shopt -s inherit_errexit 2>/dev/null || true
@@ -25,33 +26,9 @@ ccache -s
 # add system compiler
 ${MY_SPACK_CMD} compiler add --scope site /usr/bin
 
-# provide spack support for environment modules
-echo "BOOTSTRAPPING"
-
 # add build_cache
 ${MY_SPACK_CMD} mirror add --scope site build_mirror file://${BUILD_CACHE_DIR}
 
-install_from_buildcache "${spack_bootstrap_dependencies[@]}"
-
-# We install all packages needed by boostrap here
-for bootstrap_spec in "${spack_bootstrap_dependencies[@]}"; do
-    ${MY_SPACK_CMD} "${SPACK_ARGS_INSTALL[@]+"${SPACK_ARGS_INSTALL[@]}"}" install --no-cache --show-log-on-error "${bootstrap_spec}"
-done
-
-num_packages_pre_boostrap="$(${MY_SPACK_CMD} find 2>&1 | head -n 1 | awk '/installed packages/ { print $2 }')"
-
-
-num_packages_post_boostrap="$(${MY_SPACK_CMD} find 2>&1 | head -n 1 | awk '/installed packages/ { print $2 }')"
-
-if (( num_packages_pre_boostrap < num_packages_post_boostrap )); then
-cat <<EOF | tr '\n' ' ' >&2
-ERROR: spack bootstrap command did install some packages on its own, this
-should not happen, aborting..!
-EOF
-echo ""
-    exit 1
-fi
-
 if [ ${YASHCHIKI_BUILD_SPACK_GCC} -eq 1 ]; then
     # check if it can be specialized
     spec_compiler="${YASHCHIKI_SPACK_GCC}"
@@ -74,3 +51,12 @@ if [ ${YASHCHIKI_BUILD_SPACK_GCC} -eq 1 ]; then
     # add fresh compiler to spack
     ${MY_SPACK_CMD} compiler add --scope site ${MY_SPACK_FOLDER}/opt/spack/linux-*/*/gcc-${YASHCHIKI_SPACK_GCC_VERSION}-*
 fi
+
+echo "INSTALL YASHCHIKI DEPENDENCIES"
+
+install_from_buildcache "${yashchiki_dependencies[@]}"
+
+# We install all packages needed by yashchiki here
+for dep_spec in "${yashchiki_dependencies[@]}"; do
+    ${MY_SPACK_CMD} "${SPACK_ARGS_INSTALL[@]+"${SPACK_ARGS_INSTALL[@]}"}" install --no-cache --show-log-on-error "${dep_spec}"
+done
-- 
GitLab