From ee0a2666413b0769162ad0e91601042f63cee7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?= Date: Wed, 11 Aug 2021 19:10:26 +0100 Subject: [PATCH] Automatically detect location of Spack This removes the need to set the `SPACK_ROOT` environment variable. --- docs/tutorial_build_automation.rst | 4 ++-- reframe/core/buildsystems.py | 2 +- unittests/test_buildsystems.py | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/tutorial_build_automation.rst b/docs/tutorial_build_automation.rst index 568aa849e6..9aab28eb3b 100644 --- a/docs/tutorial_build_automation.rst +++ b/docs/tutorial_build_automation.rst @@ -135,7 +135,7 @@ Here is what ReFrame generates as a build script in this example: .. code:: bash - . $SPACK_ROOT/share/spack/setup-env.sh + . "$(spack location --spack-root)/share/spack/setup-env.sh" spack env activate -V -d myenv spack install @@ -171,7 +171,7 @@ Finally, here is the generated run script that ReFrame uses to run the test, onc .. code-block:: bash #!/bin/bash - . $SPACK_ROOT/share/spack/setup-env.sh + . "$(spack location --spack-root)/share/spack/setup-env.sh" spack env activate -V -d myenv bzip2 --help diff --git a/reframe/core/buildsystems.py b/reframe/core/buildsystems.py index 9f2ce2e357..e4100902fe 100644 --- a/reframe/core/buildsystems.py +++ b/reframe/core/buildsystems.py @@ -865,7 +865,7 @@ def emit_build_commands(self, environ): return ret def _env_activate_cmds(self): - cmds = ['. $SPACK_ROOT/share/spack/setup-env.sh'] + cmds = ['. "$(spack location --spack-root)/share/spack/setup-env.sh"'] if self.environment: environment = self.environment else: diff --git a/unittests/test_buildsystems.py b/unittests/test_buildsystems.py index 403fba66da..16b7abb5ba 100644 --- a/unittests/test_buildsystems.py +++ b/unittests/test_buildsystems.py @@ -249,12 +249,12 @@ 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_ROOT/share/spack/setup-env.sh', + f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', f'spack env activate -V -d {build_system.environment}', f'spack install -j 10' ] assert build_system.prepare_cmds() == [ - f'. $SPACK_ROOT/share/spack/setup-env.sh', + f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', f'spack env activate -V -d {build_system.environment}', ] @@ -266,13 +266,13 @@ 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_ROOT/share/spack/setup-env.sh', + 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' ] assert build_system.prepare_cmds() == [ - f'. $SPACK_ROOT/share/spack/setup-env.sh', + f'. "$(spack location --spack-root)/share/spack/setup-env.sh"', f'spack env activate -V -d {build_system.environment}', f'spack load {specs_str}', ] @@ -282,7 +282,7 @@ 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_ROOT/share/spack/setup-env.sh', + 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"',