diff options
author | Mark W. Krentel <krentel@rice.edu> | 2022-04-26 09:53:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 16:53:10 +0200 |
commit | c81affa551055a7fe7eac743a4e57f6f69675ba1 (patch) | |
tree | 8ed4b60a75872e821d9fd1795861ba3eae728fa0 /lib | |
parent | 3e51304b68724a89c5048a293d926a55925b8aef (diff) | |
download | spack-c81affa551055a7fe7eac743a4e57f6f69675ba1.tar.gz spack-c81affa551055a7fe7eac743a4e57f6f69675ba1.tar.bz2 spack-c81affa551055a7fe7eac743a4e57f6f69675ba1.tar.xz spack-c81affa551055a7fe7eac743a4e57f6f69675ba1.zip |
setup_package: don't unload modules on Cray when run with --dirty (#30261)
Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/build_environment.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/test/build_environment.py | 39 |
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) |