@@ -17,6 +17,11 @@ display_help() {
1717 echo " --skip-cuda-install - disable installing a full CUDA SDK in the host_injections prefix (e.g. in CI)"
1818}
1919
20+ # Function to check if a command exists
21+ function command_exists() {
22+ command -v " $1 " > /dev/null 2>&1
23+ }
24+
2025function copy_build_log() {
2126 # copy specified build log to specified directory, with some context added
2227 build_log=${1}
@@ -147,6 +152,39 @@ else
147152 mkdir -p ${EESSI_PREFIX} /software/${EESSI_OS_TYPE} /${EESSI_SOFTWARE_SUBDIR_OVERRIDE}
148153fi
149154
155+ # We need to ensure that certain files are present or updated before we source
156+ # $TOPDIR/init/eessi_environment_variables
157+ # Particularly the files we need to have present/updated in
158+ # ${EESSI_PREFIX}/software/${EESSI_OS_TYPE}/${EESSI_SOFTWARE_SUBDIR_OVERRIDE}
159+ # are:
160+ # - .lmod/lmodrc.lua
161+ # - .lmod/SitePackage.lua
162+ # We run scripts to create them if they don't exist or if the scripts have been
163+ # changed in the PR.
164+
165+ # Set base directory for software and for Lmod config files
166+ _eessi_software_path=${EESSI_PREFIX} /software/${EESSI_OS_TYPE} /${EESSI_SOFTWARE_SUBDIR_OVERRIDE}
167+ _lmod_cfg_dir=${_eessi_software_path} /.lmod
168+
169+ # We assume there's only one diff file that corresponds to the PR patch file
170+ pr_diff=$( ls [0-9]* .diff | head -1)
171+
172+ # Create or update ${_eessi_software_path}/.lmod/lmodrc.lua
173+ _lmodrc_file=${_lmod_cfg_dir} /lmodrc.lua
174+ _lmodrc_changed=$( cat ${pr_diff} | grep ' ^+++' | cut -f2 -d' ' | sed ' s@^[a-z]/@@g' | grep ' ^create_lmodrc.py$' > /dev/null; echo $? )
175+ if [ ! -f " ${_lmodrc_file} " ] || [ " ${_lmodrc_changed} " == ' 0' ]; then
176+ python3 ${TOPDIR} /create_lmodrc.py ${_eessi_software_path}
177+ check_exit_code $? " ${_lmodrc_file} created/updated" " Failed to create/update ${_lmodrc_file} "
178+ fi
179+
180+ # Create or update ${_eessi_software_path}/.lmod/SitePackage.lua
181+ _lmod_sitepackage_file=${_lmod_cfg_dir} /SitePackage.lua
182+ _sitepackage_changed=$( cat ${pr_diff} | grep ' ^+++' | cut -f2 -d' ' | sed ' s@^[a-z]/@@g' | grep ' ^create_lmodsitepackage.py$' > /dev/null; echo $? )
183+ if [ ! -f " ${_lmod_sitepackage_file} " ] || [ " ${_sitepackage_changed} " == ' 0' ]; then
184+ python3 ${TOPDIR} /create_lmodsitepackage.py ${_eessi_software_path}
185+ check_exit_code $? " ${_lmod_sitepackage_file} created/updated" " Failed to create/update ${_lmod_sitepackage_file} "
186+ fi
187+
150188# Set all the EESSI environment variables (respecting $EESSI_SOFTWARE_SUBDIR_OVERRIDE)
151189# $EESSI_SILENT - don't print any messages
152190# $EESSI_BASIC_ENV - give a basic set of environment variables
@@ -212,13 +250,11 @@ else
212250 echo " Skipping installation of CUDA SDK and cu* libraries in host_injections, since the --skip-cuda-install flag was passed"
213251fi
214252
215- # Install drivers in host_injections
216- # TODO: this is commented out for now, because the script assumes that nvidia-smi is available and works;
217- # if not, an error is produced, and the bot flags the whole build as failed (even when not installing GPU software)
218- # ${EESSI_PREFIX}/scripts/gpu_support/nvidia/link_nvidia_host_libraries.sh
219-
220- # Don't run the Lmod GPU driver check when doing builds (may not have a GPU, and it's not relevant for vanilla builds anyway)
221- export EESSI_OVERRIDE_GPU_CHECK=1
253+ # Install NVIDIA drivers in host_injections (if they exist)
254+ if command_exists " nvidia-smi" ; then
255+ echo " Command 'nvidia-smi' found. Installing NVIDIA drivers for use in prefix shell..."
256+ ${EESSI_PREFIX} /scripts/gpu_support/nvidia/link_nvidia_host_libraries.sh
257+ fi
222258
223259# use PR patch file to determine in which easystack files stuff was added
224260changed_easystacks=$( cat ${pr_diff} | grep ' ^+++' | cut -f2 -d' ' | sed ' s@^[a-z]/@@g' | grep ' ^easystacks/.*yml$' | egrep -v ' known-issues|missing' )
@@ -268,25 +304,5 @@ else
268304 done
269305fi
270306
271- # ## add packages here
272-
273- echo " >> Creating/updating Lmod RC file..."
274- export LMOD_CONFIG_DIR=" ${EASYBUILD_INSTALLPATH} /.lmod"
275- lmod_rc_file=" $LMOD_CONFIG_DIR /lmodrc.lua"
276- lmodrc_changed=$( cat ${pr_diff} | grep ' ^+++' | cut -f2 -d' ' | sed ' s@^[a-z]/@@g' | grep ' ^create_lmodrc.py$' > /dev/null; echo $? )
277- if [ ! -f $lmod_rc_file ] || [ ${lmodrc_changed} == ' 0' ]; then
278- python3 $TOPDIR /create_lmodrc.py ${EASYBUILD_INSTALLPATH}
279- check_exit_code $? " $lmod_rc_file created" " Failed to create $lmod_rc_file "
280- fi
281-
282- echo " >> Creating/updating Lmod SitePackage.lua ..."
283- export LMOD_PACKAGE_PATH=" ${EASYBUILD_INSTALLPATH} /.lmod"
284- lmod_sitepackage_file=" $LMOD_PACKAGE_PATH /SitePackage.lua"
285- sitepackage_changed=$( cat ${pr_diff} | grep ' ^+++' | cut -f2 -d' ' | sed ' s@^[a-z]/@@g' | grep ' ^create_lmodsitepackage.py$' > /dev/null; echo $? )
286- if [ ! -f " $lmod_sitepackage_file " ] || [ " ${sitepackage_changed} " == ' 0' ]; then
287- python3 $TOPDIR /create_lmodsitepackage.py ${EASYBUILD_INSTALLPATH}
288- check_exit_code $? " $lmod_sitepackage_file created" " Failed to create $lmod_sitepackage_file "
289- fi
290-
291307echo " >> Cleaning up ${TMPDIR} ..."
292308rm -r ${TMPDIR}
0 commit comments