Skip to content

Commit aacf20f

Browse files
author
Vasileios Karakasis
authored
Merge pull request #2195 from rsarm/spack-default-env
[feat] Store the default Spack environment in the `build_system` instance
2 parents 1d33ac0 + 45b1f5e commit aacf20f

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

reframe/core/buildsystems.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -845,10 +845,14 @@ class Spack(BuildSystem):
845845
#: :default: ``[]``
846846
install_opts = variable(typ.List[str], value=[])
847847

848+
def __init__(self):
849+
# Set to True if the environment was auto-generated
850+
self._auto_env = False
851+
848852
def emit_build_commands(self, environ):
849853
ret = self._env_activate_cmds()
850854

851-
if not self.environment:
855+
if self._auto_env:
852856
install_tree = self.install_tree or 'opt/spack'
853857
ret.append(f'spack config add '
854858
f'"config:install_tree:root:{install_tree}"')
@@ -866,13 +870,12 @@ def emit_build_commands(self, environ):
866870

867871
def _env_activate_cmds(self):
868872
cmds = ['. "$(spack location --spack-root)/share/spack/setup-env.sh"']
869-
if self.environment:
870-
environment = self.environment
871-
else:
872-
environment = 'rfm_spack_env'
873-
cmds.append(f'spack env create -d {environment}')
873+
if not self.environment:
874+
self.environment = 'rfm_spack_env'
875+
cmds.append(f'spack env create -d {self.environment}')
876+
self._auto_env = True
874877

875-
cmds.append(f'spack env activate -V -d {environment}')
878+
cmds.append(f'spack env activate -V -d {self.environment}')
876879
return cmds
877880

878881
def prepare_cmds(self):

unittests/test_buildsystems.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ def test_spack_no_env(environ, tmp_path):
289289
f'spack install'
290290
]
291291

292+
assert build_system.environment == 'rfm_spack_env'
293+
294+
292295
def test_easybuild(environ, tmp_path):
293296
build_system = bs.EasyBuild()
294297
build_system.easyconfigs = ['ec1.eb', 'ec2.eb']

0 commit comments

Comments
 (0)