From a035fa11e7e21953f661b13cd1d71411606e86fe Mon Sep 17 00:00:00 2001
From: Gregory Becker <becker33@llnl.gov>
Date: Fri, 4 Sep 2020 18:10:58 +0000
Subject: [PATCH] shasta PrgEnv module unloaded by unloading component

---
 lib/spack/spack/build_environment.py |  3 ++-
 lib/spack/spack/util/module_cmd.py   | 19 +++++++++++--------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 7d4bbad595..d4ed0d93b5 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -755,7 +755,8 @@ def setup_package(pkg, dirty):
         # kludge to handle cray libsci being automatically loaded by PrgEnv
         # modules on cray platform. Module unload does no damage when
         # unnecessary
-        module('unload', 'cray-libsci')
+        if False:
+            module('unload', 'cray-libsci')
 
         if pkg.architecture.target.module_name:
             load_module(pkg.architecture.target.module_name)
diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py
index bc994fd4b4..1ee25f79be 100644
--- a/lib/spack/spack/util/module_cmd.py
+++ b/lib/spack/spack/util/module_cmd.py
@@ -99,14 +99,17 @@ def load_module(mod):
     # We do this without checking that they are already installed
     # for ease of programming because unloading a module that is not
     # loaded does nothing.
-    text = module('show', mod).split()
-    for i, word in enumerate(text):
-        if word == 'conflict':
-            module('unload', text[i + 1])
-
-    # Load the module now that there are no conflicts
-    # Some module systems use stdout and some use stderr
-    module('load', mod)
+    if 'PrgEnv' not in mod:
+        module('swap', mod)
+    else:
+        text = module('show', mod).split()
+        for i, word in enumerate(text):
+            if word == 'conflict':
+                module('unload', text[i + 1])
+
+        # Load the module now that there are no conflicts
+        # Some module systems use stdout and some use stderr
+        module('load', mod)
 
 
 def get_path_args_from_module_line(line):
-- 
GitLab