22import pathlib
33import urllib .request
44import urllib .error
5- from typing import Optional , List , Dict
5+ from typing import ByteString , Optional , List , Dict
66import magic
77
88import yaml
@@ -22,8 +22,10 @@ def __init__(self, system_config_root: pathlib.Path, cmdline_cache: Optional[str
2222
2323 self .mirrors = self ._load_mirrors (cmdline_cache )
2424 self ._check_mirrors ()
25-
26- self .build_cache_mirrors = [mirror for mirror in self .mirrors if mirror .get ('buildcache' , False )]
25+
26+ self .build_cache_mirror = ([mirror for mirror in self .mirrors if mirror .get ('buildcache' , False )]
27+ + [None ]).pop (0 )
28+ self .bootstrap_mirrors = [mirror for mirror in self .mirrors if mirror .get ('bootstrap' , False )]
2729 self .keys = [mirror ['key' ] for mirror in self .mirrors if mirror .get ('key' ) is not None ]
2830
2931 def _load_mirrors (self , cmdline_cache : Optional [str ]) -> List [Dict ]:
@@ -107,12 +109,43 @@ def create_spack_mirrors_yaml(self, dest: pathlib.Path):
107109 with dest .open ("w" ) as file :
108110 yaml .dump (raw , file , default_flow_style = False )
109111
110- def bootstrap_setup (self , config_root : pathlib .Path ):
112+ def create_bootstrap_configs (self , config_root : pathlib .Path ):
111113 """Create the bootstrap.yaml and bootstrap metadata dirs in our build dir."""
112114
115+ if not self .bootstrap_mirrors :
116+ return
117+
118+ bootstrap_yaml = {
119+ 'sources' : [],
120+ 'trusted' : {},
121+ }
122+
123+ for mirror in self .bootstrap_mirrors :
124+ name = mirror ['name' ]
125+ bs_mirror_path = config_root / f'bootstrap/{ name } '
126+ # Tell spack where to find the metadata for each bootstrap mirror.
127+ bootstrap_yaml ['sources' ].append (
128+ {
129+ 'name' : name ,
130+ 'metadata' : bs_mirror_path ,
131+ }
132+ )
133+ # And trust each one
134+ bootstrap_yaml ['trusted' ][name ] = True
135+
136+ # Create the metadata dir and metadata.yaml
137+ bs_mirror_path .mkdir (parents = True )
138+ bs_mirror_yaml = {
139+ 'type' : 'install' ,
140+ 'info' : mirror ['url' ],
141+ }
142+ with (bs_mirror_path / 'metadata.yaml' ).open ('w' ) as file :
143+ yaml .dump (bs_mirror_yaml , file , default_flow_style = False )
144+
145+ with (config_root / 'bootstrap.yaml' ).open ('w' ) as file :
146+ yaml .dump (bootstrap_yaml , file , default_flow_style = False )
113147
114-
115- def key_setup (self , key_store : pathlib .Path ):
148+ def key_setup (self , config_root : pathlib .Path ):
116149 """Validate mirror keys, relocate to key_store, and update mirror config with new key paths."""
117150
118151 for mirror in self .mirrors :
0 commit comments