1212from reframe .core .exceptions import BuildSystemError
1313
1414
15+ class _UndefinedType :
16+ '''Used as an initial value for undefined values instead of None.'''
17+
18+
19+ _Undefined = _UndefinedType ()
20+
21+
1522class BuildSystem (abc .ABC ):
1623 '''The abstract base class of any build system.
1724
@@ -810,7 +817,7 @@ class Spack(BuildSystem):
810817 #:
811818 #: .. code-block:: bash
812819 #:
813- #: spack env activate -d <environment directory>
820+ #: spack env activate -V - d <environment directory>
814821 #:
815822 #: ReFrame looks for environments in the test's
816823 #: :attr:`~reframe.core.pipeline.RegressionTest.sourcesdir`.
@@ -819,7 +826,7 @@ class Spack(BuildSystem):
819826 #:
820827 #: :type: :class:`str` or :class:`None`
821828 #: :default: :class:`None`
822- environment = fields .TypedField (str , type ( None ) )
829+ environment = fields .TypedField (typ . Str [ r'\S+' ], _UndefinedType )
823830
824831 #: The list of specs to build and install within the given environment.
825832 #:
@@ -852,15 +859,15 @@ class Spack(BuildSystem):
852859 def __init__ (self ):
853860 super ().__init__ ()
854861 self .specs = []
855- self .environment = None
862+ self .environment = _Undefined
856863 self .emit_load_cmds = True
857864 self .install_opts = []
858865 self ._prefix_save = None
859866
860867 def emit_build_commands (self , environ ):
861868 self ._prefix_save = os .getcwd ()
862- if not self .environment :
863- raise BuildSystemError (f"'environment' must not be empty" )
869+ if self .environment is _Undefined :
870+ raise BuildSystemError (f'no Spack environment is defined' )
864871
865872 ret = self ._env_activate_cmds ()
866873 if self .specs :
@@ -876,7 +883,7 @@ def emit_build_commands(self, environ):
876883
877884 def _env_activate_cmds (self ):
878885 return [f'. $SPACK_ROOT/share/spack/setup-env.sh' ,
879- f'spack env activate -d { self .environment } ' ]
886+ f'spack env activate -V - d { self .environment } ' ]
880887
881888 def prepare_cmds (self ):
882889 cmds = self ._env_activate_cmds ()
0 commit comments