3535
3636from easybuild .base import fancylogger
3737from easybuild .tools .build_log import EasyBuildError , print_msg
38- from easybuild .tools .config import build_option , install_path , ConfigurationVariables
38+ from easybuild .tools .config import install_path , ConfigurationVariables
3939from easybuild .tools .filetools import copy_dir , mkdir , write_file
4040from easybuild .tools .utilities import trace_msg
4141
@@ -104,10 +104,10 @@ def prepare_bwrap(bwrap_installpath):
104104
105105 set_bwrap_info ('bwrap_installpath' , bwrap_installpath )
106106
107- installpath_software = install_path (typ = 'software' )
107+ installpath_software = os . path . realpath ( install_path (typ = 'software' ) )
108108 set_bwrap_info ('installpath_software' , installpath_software )
109109
110- installpath_modules = install_path (typ = 'modules' )
110+ installpath_modules = os . path . realpath ( install_path (typ = 'modules' ) )
111111 set_bwrap_info ('installpath_modules' , installpath_modules )
112112
113113 variables = ConfigurationVariables ()
@@ -116,54 +116,55 @@ def prepare_bwrap(bwrap_installpath):
116116 set_bwrap_info ('bwrap_installpath_software' , bwrap_installpath_software )
117117 set_bwrap_info ('bwrap_installpath_modules' , bwrap_installpath_modules )
118118
119- sufmodpath = build_option ('suffix_modules_path' )
120-
121119 bwrap_cmd = ['bwrap' , '--dev-bind' , '/' , '/' ]
122- # use a set to eliminate duplicate binds
120+ # store bwrap options in a set to avoid duplicate binds
123121 bwrap_opts = set ()
124122
123+ mkdir (bwrap_installpath_modules , parents = True )
124+
125+ try :
126+ mkdir (installpath_modules , parents = True )
127+ # copy installpath_modules to bwrap_installpath_moduleto ensure all installed modules are available
128+ # required for building multiple unrelated easyconfigs (e.g. easystacks)
129+ if os .path .exists (installpath_modules ):
130+ copy_dir (installpath_modules , bwrap_installpath_modules , dirs_exist_ok = True )
131+ # bind mount the modules installpath
132+ bwrap_opts .update ({
133+ f'--bind { bwrap_installpath_modules } { installpath_modules } ' ,
134+ })
135+ except EasyBuildError :
136+ # if we can't create the external modules directory, try to use overlayfs
137+ bwrap_workdir = os .path .join (bwrap_installpath , 'workdir' )
138+ mkdir (bwrap_workdir , parents = True )
139+ bwrap_opts .update ({
140+ f'--overlay-src { installpath_modules } --overlay { bwrap_installpath_modules } { bwrap_workdir } '
141+ f'{ installpath_modules } ' ,
142+ })
143+
125144 # bind mount all software directories
126145 for mod in sorted (get_bwrap_info ('modules_to_install' )):
127146 installdir = os .path .join (os .path .realpath (installpath_software ), mod )
128147 bwrap_installdir = os .path .join (bwrap_installpath_software , mod )
129148 mkdir (bwrap_installdir , parents = True )
130149
131- moddir = mod .split ('/' )[0 ]
132- bwrap_moduledir = os .path .join (bwrap_installpath_modules , sufmodpath , moddir )
133- mkdir (bwrap_moduledir , parents = True )
134- moduledir = os .path .join (os .path .realpath (installpath_modules ), sufmodpath , moddir )
135-
136150 use_overlayfs = False
137151 try :
138152 mkdir (installdir , parents = True )
139- mkdir (moduledir , parents = True )
140153 except EasyBuildError :
141154 # if we can't create the external installation directory, try to use overlayfs
142155 use_overlayfs = True
143156
144- # copy module files from moduledir to bwrap_moduledir to ensure all installed modules are available
145- # required for building multiple unrelated easyconfigs (e.g. easystacks)
146- if os .path .exists (moduledir ):
147- copy_dir (moduledir , bwrap_moduledir , dirs_exist_ok = True )
148-
149157 if use_overlayfs :
150- bwrap_workdir = os .path .join (bwrap_installpath , 'workdir' , mod )
151- mkdir (bwrap_workdir , parents = True )
152158 # go up the tree until we find a directory that exists
153159 while not os .path .exists (installdir ):
154160 installdir = os .path .dirname (installdir )
155161 bwrap_installdir = os .path .dirname (bwrap_installdir )
156- while not os .path .exists (moduledir ):
157- moduledir = os .path .dirname (moduledir )
158- bwrap_moduledir = os .path .dirname (bwrap_moduledir )
159162 bwrap_opts .update ({
160163 f'--overlay-src { installdir } --overlay { bwrap_installdir } { bwrap_workdir } { installdir } ' ,
161- f'--overlay-src { moduledir } --overlay { bwrap_moduledir } { bwrap_workdir } { moduledir } ' ,
162164 })
163165 else :
164166 bwrap_opts .update ({
165167 f'--bind { bwrap_installdir } { installdir } ' ,
166- f'--bind { bwrap_moduledir } { moduledir } ' ,
167168 })
168169
169170 for x in bwrap_opts :
0 commit comments