summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/build_environment.py2
-rw-r--r--lib/spack/spack/test/build_environment.py39
2 files changed, 40 insertions, 1 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index d967b69911..ca5bdefa74 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -829,7 +829,7 @@ def setup_package(pkg, dirty, context='build'):
# PrgEnv modules on cray platform. Module unload does no damage when
# unnecessary
on_cray, _ = _on_cray()
- if on_cray:
+ if on_cray and not dirty:
for mod in ['cray-mpich', 'cray-libsci']:
module('unload', mod)
diff --git a/lib/spack/spack/test/build_environment.py b/lib/spack/spack/test/build_environment.py
index a816ac4ba9..e69b23815b 100644
--- a/lib/spack/spack/test/build_environment.py
+++ b/lib/spack/spack/test/build_environment.py
@@ -95,6 +95,25 @@ def ensure_env_variables(config, mock_packages, monkeypatch, working_env):
return _ensure
+@pytest.fixture
+def mock_module_cmd(monkeypatch):
+
+ class Logger(object):
+ def __init__(self, fn=None):
+ self.fn = fn
+ self.calls = []
+
+ def __call__(self, *args, **kwargs):
+ self.calls.append((args, kwargs))
+ if self.fn:
+ return self.fn(*args, **kwargs)
+
+ mock_module_cmd = Logger()
+ monkeypatch.setattr(spack.build_environment, 'module', mock_module_cmd)
+ monkeypatch.setattr(spack.build_environment, '_on_cray', lambda: (True, None))
+ return mock_module_cmd
+
+
@pytest.mark.skipif(sys.platform == 'win32',
reason="Static to Shared not supported on Win (yet)")
def test_static_to_shared_library(build_environment):
@@ -433,3 +452,23 @@ def test_build_jobs_defaults():
parallel=True, command_line=None, config_default=1, max_cpus=10) == 1
assert determine_number_of_jobs(
parallel=True, command_line=None, config_default=100, max_cpus=10) == 10
+
+
+def test_dirty_disable_module_unload(
+ config, mock_packages, working_env, mock_module_cmd
+):
+ """Test that on CRAY platform 'module unload' is not called if the 'dirty'
+ option is on.
+ """
+ s = spack.spec.Spec('a').concretized()
+
+ # If called with "dirty" we don't unload modules, so no calls to the
+ # `module` function on Cray
+ spack.build_environment.setup_package(s.package, dirty=True)
+ assert not mock_module_cmd.calls
+
+ # If called without "dirty" we unload modules on Cray
+ spack.build_environment.setup_package(s.package, dirty=False)
+ assert mock_module_cmd.calls
+ assert any(('unload', 'cray-libsci') == item[0] for item in mock_module_cmd.calls)
+ assert any(('unload', 'cray-mpich') == item[0] for item in mock_module_cmd.calls)