Skip to content

Commit

Permalink
Merge pull request #2919 from jack-morrison/jackm/spack-build-system
Browse files Browse the repository at this point in the history
[feat] Additional Spack build system options
  • Loading branch information
vkarak committed Jun 16, 2023
2 parents fa813d0 + b7bf09a commit a708b14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 26 additions & 2 deletions reframe/core/buildsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ class Spack(BuildSystem):
#: :default: :obj:`True`
emit_load_cmds = variable(bool, value=True)

#: Options to pass to ``spack install``
#: Options to pass to ``spack install``.
#:
#: :type: :class:`List[str]`
#: :default: ``[]``
Expand All @@ -877,6 +877,21 @@ class Spack(BuildSystem):
#: .. versionadded:: 4.2
config_opts = variable(typ.List[str], value=[])

#: Options to pass to ``spack env create``.
#:
#: :type: :class:`List[str]`
#: :default: ``[]``
env_create_opts = variable(typ.List[str], value=[])

#: A list of commands to run after a Spack environment
#: is created, but before it is installed.
#:
#: :type: :class:`List[str]`
#: :default: ``[]``
#:
preinstall_cmds = variable(typ.List[str], value=[])


def __init__(self):
# Set to True if the environment was auto-generated
self._auto_env = False
Expand All @@ -897,6 +912,10 @@ def emit_build_commands(self, environ):
specs_str = ' '.join(self.specs)
ret.append(f'spack -e {self.environment} add {specs_str}')

if self.preinstall_cmds:
for cmd in self.preinstall_cmds:
ret.append(cmd)

install_cmd = f'spack -e {self.environment} install'
if self.install_opts:
install_cmd += ' ' + ' '.join(self.install_opts)
Expand All @@ -910,7 +929,12 @@ def _create_env_cmds(self):

self.environment = 'rfm_spack_env'
self._auto_env = True
return [f'spack env create -d {self.environment}']

if self.env_create_opts:
env_create_opts = ' '.join(self.env_create_opts)
return [f'spack env create -d {self.environment} {env_create_opts}']
else:
return [f'spack env create -d {self.environment}']

def prepare_cmds(self):
cmds = self._create_env_cmds()
Expand Down
6 changes: 5 additions & 1 deletion unittests/test_buildsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,18 @@ def test_spack_no_env(environ, tmp_path):

def test_spack_env_config(environ, tmp_path):
build_system = bs.Spack()
build_system.env_create_opts = ['--without-view']
build_system.config_opts = ['section1:header1:value1',
'section2:header2:value2']
build_system.preinstall_cmds = ['echo hello', 'echo world']
with osext.change_dir(tmp_path):
assert build_system.emit_build_commands(environ) == [
'spack env create -d rfm_spack_env',
'spack env create -d rfm_spack_env --without-view',
'spack -e rfm_spack_env config add "config:install_tree:root:opt/spack"', # noqa: E501
'spack -e rfm_spack_env config add "section1:header1:value1"',
'spack -e rfm_spack_env config add "section2:header2:value2"',
'echo hello',
'echo world',
'spack -e rfm_spack_env install',
]

Expand Down

0 comments on commit a708b14

Please sign in to comment.