@@ -41,17 +41,6 @@ def __init__(
4141 self .mirrors = self ._load_mirrors (cmdline_cache )
4242 self ._check_mirrors ()
4343
44- # Always use the cache given on the command line
45- if self .CMDLINE_CACHE in self .mirrors :
46- self .build_cache_mirror = self .CMDLINE_CACHE
47- else :
48- # Otherwise, grab the configured cache (or None)
49- self .build_cache_mirror : Optional [str ] = (
50- [name for name , mirror in self .mirrors .items () if mirror .get ("cache" , False )] + [None ]
51- ).pop (0 )
52-
53- self .bootstrap_mirrors = [name for name , mirror in self .mirrors .items () if mirror .get ("bootstrap" , True )]
54-
5544 # Will hold a list of all the gpg keys (public and private)
5645 # self._keys: Optional[List[pathlib.Path]] = []
5746 self ._keys = self ._key_init ()
@@ -74,22 +63,37 @@ def _load_mirrors(self, cmdline_cache: Optional[pathlib.Path]) -> Dict[str, Dict
7463 except ValueError as err :
7564 raise MirrorError (f"Mirror config does not comply with schema.\n { err } " )
7665
77- caches = [name for name , mirror in mirrors .items () if mirror ["cache" ]]
78- if len (caches ) > 1 :
79- raise MirrorError (
80- "Mirror config has more than one mirror specified as the build cache destination.\n "
81- f"{ self ._pp_yaml (caches )} "
82- )
83- elif caches :
84- cache = mirrors [caches [0 ]]
85- if not cache .get ("private_key" ):
86- raise MirrorError (f"Mirror build cache config '{ caches [0 ]} ' missing a required 'private_key' path." )
66+ enabled_mirrors : Dict [str , Dict ] = {}
67+
68+ buildcache = mirrors .get ("buildcache" )
69+ if buildcache and buildcache .get ("enabled" , True ):
70+ if not buildcache .get ("private_key" ):
71+ raise MirrorError (
72+ "Mirror build cache config is missing a required 'private_key' path."
73+ )
74+ self .build_cache_mirror = "buildcache"
75+ enabled_mirrors ["buildcache" ] = buildcache
76+ else :
77+ self .build_cache_mirror = None
8778
8879 # Load the cache as defined by the deprecated 'cache.yaml' file.
8980 if cmdline_cache is not None :
90- mirrors [self .CMDLINE_CACHE ] = self ._load_cmdline_cache (cmdline_cache )
81+ enabled_mirrors ["buildcache" ] = self ._load_cmdline_cache (cmdline_cache )
82+ self .build_cache_mirror = self .CMDLINE_CACHE
83+
84+
85+ bootstrap = mirrors .get ("bootstrap" )
86+ if bootstrap and bootstrap .get ("enabled" , True ):
87+ self .bootstrap_mirror = bootstrap
88+ enabled_mirrors ["bootstrap" ] = bootstrap
89+ else :
90+ self .bootstrap_mirror = None
9191
92- return {name : mirror for name , mirror in mirrors .items () if mirror ["enabled" ]}
92+ for name , mirror in mirrors .get ("sourcecache" , {}).items ():
93+ if mirror .get ("enabled" , True ):
94+ enabled_mirrors [name ] = mirror
95+
96+ return enabled_mirrors
9397
9498 @staticmethod
9599 def _pp_yaml (object ):
@@ -121,11 +125,10 @@ def _load_cmdline_cache(self, cache_config_path: pathlib.Path) -> Dict:
121125 mirror_cfg = {
122126 "url" : raw ["root" ],
123127 "description" : "Buildcache dest loaded from legacy cache.yaml" ,
124- "cache" : True ,
125128 "enabled" : True ,
126- "bootstrap" : False ,
127129 "mount_specific" : True ,
128130 "private_key" : raw ["key" ],
131+ "cmdline" : True
129132 }
130133
131134 self ._logger .warning (
@@ -179,25 +182,44 @@ def _create_spack_mirrors_yaml(self, dest: pathlib.Path):
179182
180183 raw = {"mirrors" : {}}
181184
182- for name , mirror in self .mirrors .items ():
183- url = mirror ["url" ]
185+ if self .build_cache_mirror :
186+ url = self .mirrors .get ("buildcache" )["url" ]
187+ name = self .build_cache_mirror
184188
185- # Make the mirror path specific to the mount point
186- if mirror ["mount_specific" ] and self ._mount_point is not None :
189+ if self .build_cache_mirror .get ("mount_specific" , True ) and self ._mount_point is not None :
187190 url = url .rstrip ("/" ) + "/" + self ._mount_point .as_posix ().lstrip ("/" )
188191
189192 raw ["mirrors" ][name ] = {
190193 "fetch" : {"url" : url },
191194 "push" : {"url" : url },
192195 }
193196
197+ elif self .mirrors .get ("bootstrap" ):
198+ url = self .mirrors .get ("bootstrap" )["url" ]
199+
200+ raw ["mirrors" ]["bootstrap" ] = {
201+ "fetch" : {"url" : url },
202+ "push" : {"url" : url },
203+ }
204+
205+ elif self .mirrors .get ("sourcecache" ):
206+ source_mirrors = self .mirrors .get ("sourcecache" )
207+
208+ for name , mirror in source_mirrors .items ():
209+ url = mirror ["url" ]
210+
211+ raw ["mirrors" ][name ] = {
212+ "fetch" : {"url" : url },
213+ "push" : {"url" : url },
214+ }
215+
194216 with dest .open ("w" ) as file :
195217 yaml .dump (raw , file , default_flow_style = False )
196218
197219 def _create_bootstrap_configs (self , config_root : pathlib .Path ):
198220 """Create the bootstrap.yaml and bootstrap metadata dirs in our build dir."""
199221
200- if not self .bootstrap_mirrors :
222+ if not self .bootstrap_mirror :
201223 return
202224
203225 bootstrap_yaml = {
@@ -207,29 +229,28 @@ def _create_bootstrap_configs(self, config_root: pathlib.Path):
207229 }
208230 }
209231
210- for name in self .bootstrap_mirrors :
211- bs_mirror_path = config_root / f"bootstrap/{ name } "
212- mirror = self .mirrors [name ]
213- # Tell spack where to find the metadata for each bootstrap mirror.
214- bootstrap_yaml ["bootstrap" ]["sources" ].append (
215- {
216- "name" : name ,
217- "metadata" : str (bs_mirror_path ),
218- }
219- )
220- # And trust each one
221- bootstrap_yaml ["bootstrap" ]["trusted" ][name ] = True
222-
223- # Create the metadata dir and metadata.yaml
224- bs_mirror_path .mkdir (parents = True , exist_ok = True )
225- bs_mirror_yaml = {
226- "type" : "install" ,
227- "info" : {
228- "url" : mirror ["url" ],
229- }
230- }
231- with (bs_mirror_path / "metadata.yaml" ).open ("w" ) as file :
232- yaml .dump (bs_mirror_yaml , file , default_flow_style = False )
232+ bs_mirror_path = config_root / f"bootstrap/{ self .bootstrap_mirror } "
233+ mirror = self .mirrors .get ("bootstrap" )
234+ # Tell spack where to find the metadata for each bootstrap mirror.
235+ bootstrap_yaml ["bootstrap" ]["sources" ].append (
236+ {
237+ "name" : "bootstrap_mirror" ,
238+ "metadata" : str (bs_mirror_path ),
239+ }
240+ )
241+ # And trust each one
242+ bootstrap_yaml ["bootstrap" ]["trusted" ][bootstrap_mirror ] = True
243+
244+ # Create the metadata dir and metadata.yaml
245+ bs_mirror_path .mkdir (parents = True , exist_ok = True )
246+ bs_mirror_yaml = {
247+ "type" : "install" ,
248+ "info" : {
249+ "url" : mirror ["url" ],
250+ }
251+ }
252+ with (bs_mirror_path / "metadata.yaml" ).open ("w" ) as file :
253+ yaml .dump (bs_mirror_yaml , file , default_flow_style = False )
233254
234255 with (config_root / "bootstrap.yaml" ).open ("w" ) as file :
235256 yaml .dump (bootstrap_yaml , file , default_flow_style = False )
0 commit comments