Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions reframe/core/buildsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,14 @@ class Spack(BuildSystem):
#: :default: ``[]``
install_opts = variable(typ.List[str], value=[])

def __init__(self):
# Set to True if the environment was auto-generated
self._auto_env = False

def emit_build_commands(self, environ):
ret = self._env_activate_cmds()

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

def _env_activate_cmds(self):
cmds = ['. "$(spack location --spack-root)/share/spack/setup-env.sh"']
if self.environment:
environment = self.environment
else:
environment = 'rfm_spack_env'
cmds.append(f'spack env create -d {environment}')
if not self.environment:
self.environment = 'rfm_spack_env'
cmds.append(f'spack env create -d {self.environment}')
self._auto_env = True

cmds.append(f'spack env activate -V -d {environment}')
cmds.append(f'spack env activate -V -d {self.environment}')
return cmds

def prepare_cmds(self):
Expand Down
3 changes: 3 additions & 0 deletions unittests/test_buildsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def test_spack_no_env(environ, tmp_path):
f'spack install'
]

assert build_system.environment == 'rfm_spack_env'


def test_easybuild(environ, tmp_path):
build_system = bs.EasyBuild()
build_system.easyconfigs = ['ec1.eb', 'ec2.eb']
Expand Down