Skip to content

Commit 3154793

Browse files
author
Vasileios Karakasis
committed
Add more options to the Spack build system backend
- An option to disable the generation of `spack load`s before running. - An option to specify additional options to be passed to `spack install`.
1 parent 19e49a9 commit 3154793

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

reframe/core/buildsystems.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ class Spack(BuildSystem):
817817
specs = fields.TypedField(typ.List[str])
818818

819819
#: Spack environment.
820-
#: This field is required.
821820
#:
822821
#: ReFrame activates this environment to build and install the specified
823822
#: packages:
@@ -826,14 +825,30 @@ class Spack(BuildSystem):
826825
#:
827826
#: spack env activate -d <environment directory>
828827
#:
828+
#: This field is required.
829+
#:
829830
#: :type: :class:`str` or :class:`None`
830831
#: :default: :class:`None`
831832
environment = fields.TypedField(str, type(None))
832833

834+
#: Emit the necessary ``spack load`` commands before running the test.
835+
#:
836+
#: :type: :class:`bool`
837+
#: :default: :obj:`True`
838+
emit_load_cmds = fields.TypedField(bool)
839+
840+
#: Options to pass to ``spack install``
841+
#:
842+
#: :type: :class:`List[str]`
843+
#: :default: ``[]``
844+
install_opts = fields.TypedField(typ.List[str])
845+
833846
def __init__(self):
834847
super().__init__()
835848
self.specs = []
836849
self.environment = None
850+
self.emit_load_cmds = True
851+
self.install_opts = []
837852
self._prefix_save = None
838853

839854
def emit_build_commands(self, environ):
@@ -846,7 +861,11 @@ def emit_build_commands(self, environ):
846861
specs_str = ' '.join(self.specs)
847862
ret.append(f'spack add {specs_str}')
848863

849-
ret.append('spack install')
864+
install_cmd = 'spack install'
865+
if self.install_opts:
866+
install_cmd += ' ' + ' '.join(self.install_opts)
867+
868+
ret.append(install_cmd)
850869
return ret
851870

852871
def _env_activate_cmds(self):
@@ -855,7 +874,7 @@ def _env_activate_cmds(self):
855874

856875
def prepare_cmds(self):
857876
cmds = self._env_activate_cmds()
858-
if self.specs:
877+
if self.specs and self.emit_load_cmds:
859878
cmds.append('spack load ' + ' '.join(s for s in self.specs))
860879

861880
return cmds

unittests/test_buildsystems.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,12 @@ def test_singlesource_unknown_language():
246246
def test_spack(environ, tmp_path):
247247
build_system = bs.Spack()
248248
build_system.environment = 'spack_env'
249+
build_system.install_opts = ['-j 10']
249250
with osext.change_dir(tmp_path):
250251
assert build_system.emit_build_commands(environ) == [
251252
f'. $SPACK_ROOT/share/spack/setup-env.sh',
252253
f'spack env activate -d {build_system.environment}',
253-
f'spack install'
254+
f'spack install -j 10'
254255
]
255256
assert build_system.prepare_cmds() == [
256257
f'. $SPACK_ROOT/share/spack/setup-env.sh',

0 commit comments

Comments
 (0)