diff --git a/.github/workflows/tests_archdetect_nvidia_gpu.yml b/.github/workflows/tests_archdetect_nvidia_gpu.yml index d8b5adeb88..8ad5f4fb36 100644 --- a/.github/workflows/tests_archdetect_nvidia_gpu.yml +++ b/.github/workflows/tests_archdetect_nvidia_gpu.yml @@ -52,14 +52,6 @@ jobs: echo "Test for '${{matrix.fake_nvidia_smi_script}}' PASSED: '$out'" - # by default the 'errexit' option is enabled (set -e), - # which causes trouble when 'eessi_archdetect.sh accelpath' - # fails to detect an accelerator and produces a non-zero exit code, - # so we have to unset it using 'set +e' - echo "set flags: $-" - set +e - echo "set flags after unsetting errexit option: $-" - # run full EESSI init script, which pick up on the accelerator (if available) echo . init/bash 2>&1 | tee init.out @@ -95,7 +87,7 @@ jobs: else echo ">>> checking for 'accel/nvidia/cc80' in init output..." grep "archdetect found supported accelerator for CPU target x86_64/amd/zen2: accel/nvidia/cc80" init.out || (echo "FAILED 2" && exit 1) - grep "Prepending /cvmfs/software.eessi.io/versions/2023.06/software/linux x86_64/amd/zen2/accel/nvidia/cc80/modules/all to \$MODULEPATH" init.out || (echo "FAILED 3" && exit 1) + grep "Prepending /cvmfs/software.eessi.io/versions/2023.06/software/linux/x86_64/amd/zen2/accel/nvidia/cc80/modules/all to \$MODULEPATH" init.out || (echo "FAILED 3" && exit 1) fi echo ">>> checking last line of init output..." diff --git a/init/eessi_environment_variables b/init/eessi_environment_variables index fb1b731ee1..ab4894fb16 100644 --- a/init/eessi_environment_variables +++ b/init/eessi_environment_variables @@ -38,12 +38,27 @@ if [ -d $EESSI_PREFIX ]; then break fi done + + # we need to make sure that errexit shell option (set -e) is not enabled, + # since archdetect will produce non-zero exit code if no accelerator was found + if [[ "$-" =~ e ]]; then + errexit_shell_option_set='yes' + set +e + else + errexit_shell_option_set='no' + fi + # to be able to grab exit code of archdetect trying to detect accelerators, # we can not run it via $(...), so we have to redirect the output to a temporary file tmpout=$(mktemp) ${EESSI_INIT_DIR_PATH}/eessi_archdetect.sh accelpath 2>&1 > $tmpout - ec=$? - if [[ $ec -eq 0 ]]; then + accelpath_exit_code=$? + + if [[ "$errexit_shell_option_set" == "yes" ]]; then + set -e + fi + + if [[ $accelpath_exit_code -eq 0 ]]; then export EESSI_ACCEL_SUBDIR=$(tail -1 $tmpout && rm -f $tmpout) if [ -z ${EESSI_ACCEL_SUBDIR} ]; then error "accelerator detection with archdetect worked, but no result was returned?!"