Repository: easybuilders/easybuild-framework

Issue:
Environment variable change in module cray-libsci of CPE 23.12
Hi, I report a bug affecting EasyBuild on Cray systems (file [libsci.py](https://github.com/easybuilders/easybuild-framework/blob/develop/easybuild/toolchains/linalg/libsci.py)) with the Cray Programming Environment (CPE) 23.12. The bug should be fixed in CPE 24.03 according to HPE/Cray staff, therefore the impact is limited:
- The environment variable name referenced in [line 68](https://github.com/easybuilders/easybuild-framework/blob/e4524c1c70e496e5886de7d4848bb8147eea84bd/easybuild/toolchains/linalg/libsci.py#L68) changed from `CRAY_LIBSCI_PREFIX_DIR` to `CRAY_PE_LIBSCI_PREFIX_DIR`
- I have manually fixed [line 69](https://github.com/easybuilders/easybuild-framework/blob/e4524c1c70e496e5886de7d4848bb8147eea84bd/easybuild/toolchains/linalg/libsci.py#L69) using the workaround below:
  `root = os.getenv('CRAY_LIBSCI_PREFIX_DIR', None) or os.getenv('CRAY_PE_LIBSCI_PREFIX_DIR', None)`

The environment variable name should be fixed back to the original one in CPE 24.03 (I did not have the chance to test it yet, though). Since CPE variable names change sometimes, it might be useful to give the option to read the `prefix` of the external module `cray-libsci` from a [metadata file](https://docs.easybuild.io/using-external-modules/?h=metadata#using_external_modules_metadata) instead of having it hard coded.



Discussion:
@lucamar Do you think it's worth also considering `$CRAY_PE_LIBSCI_PREFIX_DIR` as a fallback in `libsci.py` to dance around this? That's a pretty easy change...
Thanks @boegel: yes, that's likely the quickest workaround, that I've also implemented manually. Hopefully this bug will only affect CPE 23.12, as reported by HPE staff

Resolving patch:
diff --git a/easybuild/toolchains/linalg/libsci.py b/easybuild/toolchains/linalg/libsci.py
--- a/easybuild/toolchains/linalg/libsci.py
+++ b/easybuild/toolchains/linalg/libsci.py
@@ -65,13 +65,20 @@ def _get_software_root(self, name, required=True):
         """Get install prefix for specified software name; special treatment for Cray modules."""
         if name == 'cray-libsci':
             # Cray-provided LibSci module
-            env_var = 'CRAY_LIBSCI_PREFIX_DIR'
-            root = os.getenv(env_var, None)
+            root = None
+            # consider both $CRAY_LIBSCI_PREFIX_DIR and $CRAY_PE_LIBSCI_PREFIX_DIR,
+            # cfr. https://github.com/easybuilders/easybuild-framework/issues/4536
+            env_vars = ('CRAY_LIBSCI_PREFIX_DIR', 'CRAY_PE_LIBSCI_PREFIX_DIR')
+            for env_var in env_vars:
+                root = os.getenv(env_var, None)
+                if root is not None:
+                    self.log.debug("Obtained install prefix for %s via $%s: %s", name, env_var, root)
+                    break
+
             if root is None:
                 if required:
-                    raise EasyBuildError("Failed to determine install prefix for %s via $%s", name, env_var)
-            else:
-                self.log.debug("Obtained install prefix for %s via $%s: %s", name, env_var, root)
+                    env_vars_str = ', '.join('$' + e for e in env_vars)
+                    raise EasyBuildError("Failed to determine install prefix for %s via $%s", name, env_vars_str)
         else:
             root = super(LibSci, self)._get_software_root(name, required=required)
 


Test patch: