From 45a1e86e0ea2a5f76449ebb0864ad7c1a4474e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Thu, 10 Feb 2022 17:05:44 +0000 Subject: [PATCH 1/2] [bugfix] Do not set up Spack shell support --- docs/tutorial_build_automation.rst | 12 ++++-------- reframe/core/buildsystems.py | 27 +++++++++++++-------------- unittests/test_buildsystems.py | 23 +++++++---------------- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/docs/tutorial_build_automation.rst b/docs/tutorial_build_automation.rst index 702243a82f..356f83e231 100644 --- a/docs/tutorial_build_automation.rst +++ b/docs/tutorial_build_automation.rst @@ -120,12 +120,10 @@ Here is what ReFrame generates as a build script for this example: .. code:: bash - . "$(spack location --spack-root)/share/spack/setup-env.sh" spack env create -d rfm_spack_env - spack env activate -V -d rfm_spack_env - spack config add "config:install_tree:root:opt/spack" - spack add bzip2@1.0.6 - spack install + spack -e rfm_spack_env config add "config:install_tree:root:opt/spack" + spack -e rfm_spack_env add bzip2@1.0.6 + spack -e rfm_spack_env install As you might have noticed ReFrame expects that Spack is already installed on the system. The packages specified in the environment and the tests will be installed in the test's stage directory, where the environment is copied before building. @@ -155,10 +153,8 @@ Finally, here is the generated run script that ReFrame uses to run the test, onc .. code-block:: bash #!/bin/bash - . "$(spack location --spack-root)/share/spack/setup-env.sh" spack env create -d rfm_spack_env - spack env activate -V -d rfm_spack_env - spack load bzip2@1.0.6 + eval `spack -e rfm_spack_env load --sh bzip2@1.0.6` bzip2 --help From this point on, sanity and performance checking are exactly identical to any other ReFrame test. diff --git a/reframe/core/buildsystems.py b/reframe/core/buildsystems.py index 43fc9b53be..1d571e7d1a 100644 --- a/reframe/core/buildsystems.py +++ b/reframe/core/buildsystems.py @@ -850,38 +850,37 @@ def __init__(self): self._auto_env = False def emit_build_commands(self, environ): - ret = self._env_activate_cmds() + ret = self._create_env_cmds() if self._auto_env: install_tree = self.install_tree or 'opt/spack' - ret.append(f'spack config add ' + ret.append(f'spack -e {self.environment} config add ' f'"config:install_tree:root:{install_tree}"') if self.specs: specs_str = ' '.join(self.specs) - ret.append(f'spack add {specs_str}') + ret.append(f'spack -e {self.environment} add {specs_str}') - install_cmd = 'spack install' + install_cmd = f'spack -e {self.environment} install' if self.install_opts: install_cmd += ' ' + ' '.join(self.install_opts) ret.append(install_cmd) return ret - def _env_activate_cmds(self): - cmds = ['. "$(spack location --spack-root)/share/spack/setup-env.sh"'] - if not self.environment: - self.environment = 'rfm_spack_env' - cmds.append(f'spack env create -d {self.environment}') - self._auto_env = True + def _create_env_cmds(self): + if self.environment: + return [] - cmds.append(f'spack env activate -V -d {self.environment}') - return cmds + self.environment = 'rfm_spack_env' + self._auto_env = True + return [f'spack env create -d {self.environment}'] def prepare_cmds(self): - cmds = self._env_activate_cmds() + cmds = self._create_env_cmds() if self.specs and self.emit_load_cmds: - cmds.append('spack load ' + ' '.join(s for s in self.specs)) + cmds.append(f'eval `spack -e {self.environment} load --sh ' + + ' '.join(s for s in self.specs) + '`') return cmds diff --git a/unittests/test_buildsystems.py b/unittests/test_buildsystems.py index d5136f8f3d..d0ce6a7bd2 100644 --- a/unittests/test_buildsystems.py +++ b/unittests/test_buildsystems.py @@ -249,13 +249,9 @@ def test_spack(environ, tmp_path): build_system.install_opts = ['-j 10'] with osext.change_dir(tmp_path): assert build_system.emit_build_commands(environ) == [ - f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', - f'spack env activate -V -d {build_system.environment}', - f'spack install -j 10' + f'spack -e {build_system.environment} install -j 10' ] assert build_system.prepare_cmds() == [ - f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', - f'spack env activate -V -d {build_system.environment}', ] @@ -266,15 +262,11 @@ def test_spack_with_spec(environ, tmp_path): specs_str = ' '.join(build_system.specs) with osext.change_dir(tmp_path): assert build_system.emit_build_commands(environ) == [ - f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', - f'spack env activate -V -d {build_system.environment}', - f'spack add {specs_str}', - f'spack install' + f'spack -e {build_system.environment} add {specs_str}', + f'spack -e {build_system.environment} install' ] assert build_system.prepare_cmds() == [ - f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', - f'spack env activate -V -d {build_system.environment}', - f'spack load {specs_str}', + f'eval `spack -e {build_system.environment} load --sh {specs_str}`' ] @@ -282,11 +274,10 @@ def test_spack_no_env(environ, tmp_path): build_system = bs.Spack() with osext.change_dir(tmp_path): assert build_system.emit_build_commands(environ) == [ - f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', f'spack env create -d rfm_spack_env', - f'spack env activate -V -d rfm_spack_env', - f'spack config add "config:install_tree:root:opt/spack"', - f'spack install' + f'spack -e rfm_spack_env config add ' + '"config:install_tree:root:opt/spack"', + f'spack -e rfm_spack_env install' ] assert build_system.environment == 'rfm_spack_env' From ae1d5ade714399a93e457b0f1e58bd362c166648 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Thu, 17 Feb 2022 13:38:59 +0100 Subject: [PATCH 2/2] Code style fix --- reframe/core/buildsystems.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reframe/core/buildsystems.py b/reframe/core/buildsystems.py index 1d571e7d1a..cee1502baf 100644 --- a/reframe/core/buildsystems.py +++ b/reframe/core/buildsystems.py @@ -879,8 +879,10 @@ def _create_env_cmds(self): def prepare_cmds(self): cmds = self._create_env_cmds() if self.specs and self.emit_load_cmds: - cmds.append(f'eval `spack -e {self.environment} load --sh ' + - ' '.join(s for s in self.specs) + '`') + cmds.append( + f'eval `spack -e {self.environment} load ' + f'--sh {" ".join(self.specs)}`' + ) return cmds