@@ -79,11 +79,22 @@ def run(args, verbose=False):
79
79
raise RuntimeError (err )
80
80
sys .exit (err )
81
81
82
+ def stage0_data (rust_root ):
83
+ nightlies = os .path .join (rust_root , "src/stage0.txt" )
84
+ with open (nightlies , 'r' ) as nightlies :
85
+ data = {}
86
+ for line in nightlies .read ().split ("\n " ):
87
+ if line .startswith ("#" ) or line == '' :
88
+ continue
89
+ a , b = line .split (": " , 1 )
90
+ data [a ] = b
91
+ return data
92
+
82
93
class RustBuild :
83
- def download_rust_nightly (self ):
94
+ def download_stage0 (self ):
84
95
cache_dst = os .path .join (self .build_dir , "cache" )
85
- rustc_cache = os .path .join (cache_dst , self .snap_rustc_date ())
86
- cargo_cache = os .path .join (cache_dst , self .snap_cargo_date ())
96
+ rustc_cache = os .path .join (cache_dst , self .stage0_rustc_date ())
97
+ cargo_cache = os .path .join (cache_dst , self .stage0_cargo_date ())
87
98
if not os .path .exists (rustc_cache ):
88
99
os .makedirs (rustc_cache )
89
100
if not os .path .exists (cargo_cache ):
@@ -93,41 +104,49 @@ def download_rust_nightly(self):
93
104
(not os .path .exists (self .rustc ()) or self .rustc_out_of_date ()):
94
105
if os .path .exists (self .bin_root ()):
95
106
shutil .rmtree (self .bin_root ())
96
- filename = "rust-std-nightly-" + self .build + ".tar.gz"
97
- url = "https://static.rust-lang.org/dist/" + self .snap_rustc_date ()
107
+ channel = self .stage0_rustc_channel ()
108
+ filename = "rust-std-" + channel + "-" + self .build + ".tar.gz"
109
+ url = "https://static.rust-lang.org/dist/" + self .stage0_rustc_date ()
98
110
tarball = os .path .join (rustc_cache , filename )
99
111
if not os .path .exists (tarball ):
100
112
get (url + "/" + filename , tarball , verbose = self .verbose )
101
113
unpack (tarball , self .bin_root (),
102
114
match = "rust-std-" + self .build ,
103
115
verbose = self .verbose )
104
116
105
- filename = "rustc-nightly -" + self .build + ".tar.gz"
106
- url = "https://static.rust-lang.org/dist/" + self .snap_rustc_date ()
117
+ filename = "rustc-" + channel + " -" + self .build + ".tar.gz"
118
+ url = "https://static.rust-lang.org/dist/" + self .stage0_rustc_date ()
107
119
tarball = os .path .join (rustc_cache , filename )
108
120
if not os .path .exists (tarball ):
109
121
get (url + "/" + filename , tarball , verbose = self .verbose )
110
122
unpack (tarball , self .bin_root (), match = "rustc" , verbose = self .verbose )
111
123
with open (self .rustc_stamp (), 'w' ) as f :
112
- f .write (self .snap_rustc_date ())
124
+ f .write (self .stage0_rustc_date ())
113
125
114
126
if self .cargo ().startswith (self .bin_root ()) and \
115
127
(not os .path .exists (self .cargo ()) or self .cargo_out_of_date ()):
116
- filename = "cargo-nightly-" + self .build + ".tar.gz"
117
- url = "https://static.rust-lang.org/cargo-dist/" + self .snap_cargo_date ()
128
+ channel = self .stage0_cargo_channel ()
129
+ filename = "cargo-" + channel + "-" + self .build + ".tar.gz"
130
+ url = "https://static.rust-lang.org/cargo-dist/" + self .stage0_cargo_date ()
118
131
tarball = os .path .join (cargo_cache , filename )
119
132
if not os .path .exists (tarball ):
120
133
get (url + "/" + filename , tarball , verbose = self .verbose )
121
134
unpack (tarball , self .bin_root (), match = "cargo" , verbose = self .verbose )
122
135
with open (self .cargo_stamp (), 'w' ) as f :
123
- f .write (self .snap_cargo_date ())
136
+ f .write (self .stage0_cargo_date ())
124
137
125
- def snap_cargo_date (self ):
138
+ def stage0_cargo_date (self ):
126
139
return self ._cargo_date
127
140
128
- def snap_rustc_date (self ):
141
+ def stage0_cargo_channel (self ):
142
+ return self ._cargo_channel
143
+
144
+ def stage0_rustc_date (self ):
129
145
return self ._rustc_date
130
146
147
+ def stage0_rustc_channel (self ):
148
+ return self ._rustc_channel
149
+
131
150
def rustc_stamp (self ):
132
151
return os .path .join (self .bin_root (), '.rustc-stamp' )
133
152
@@ -138,13 +157,13 @@ def rustc_out_of_date(self):
138
157
if not os .path .exists (self .rustc_stamp ()):
139
158
return True
140
159
with open (self .rustc_stamp (), 'r' ) as f :
141
- return self .snap_rustc_date () != f .read ()
160
+ return self .stage0_rustc_date () != f .read ()
142
161
143
162
def cargo_out_of_date (self ):
144
163
if not os .path .exists (self .cargo_stamp ()):
145
164
return True
146
165
with open (self .cargo_stamp (), 'r' ) as f :
147
- return self .snap_cargo_date () != f .read ()
166
+ return self .stage0_cargo_date () != f .read ()
148
167
149
168
def bin_root (self ):
150
169
return os .path .join (self .build_dir , self .build , "stage0" )
@@ -187,15 +206,6 @@ def exe_suffix(self):
187
206
else :
188
207
return ''
189
208
190
- def parse_nightly_dates (self ):
191
- nightlies = os .path .join (self .rust_root , "src/nightlies.txt" )
192
- with open (nightlies , 'r' ) as nightlies :
193
- rustc , cargo = nightlies .read ().split ("\n " )[:2 ]
194
- assert rustc .startswith ("rustc: " )
195
- assert cargo .startswith ("cargo: " )
196
- self ._rustc_date = rustc [len ("rustc: " ):]
197
- self ._cargo_date = cargo [len ("cargo: " ):]
198
-
199
209
def build_bootstrap (self ):
200
210
env = os .environ .copy ()
201
211
env ["CARGO_TARGET_DIR" ] = os .path .join (self .build_dir , "bootstrap" )
@@ -300,46 +310,53 @@ def build_triple(self):
300
310
301
311
return cputype + '-' + ostype
302
312
303
- parser = argparse .ArgumentParser (description = 'Build rust' )
304
- parser .add_argument ('--config' )
305
- parser .add_argument ('-v' , '--verbose' , action = 'store_true' )
306
-
307
- args = [a for a in sys .argv if a != '-h' ]
308
- args , _ = parser .parse_known_args (args )
309
-
310
- # Configure initial bootstrap
311
- rb = RustBuild ()
312
- rb .config_toml = ''
313
- rb .config_mk = ''
314
- rb .rust_root = os .path .abspath (os .path .join (__file__ , '../../..' ))
315
- rb .build_dir = os .path .join (os .getcwd (), "build" )
316
- rb .verbose = args .verbose
317
-
318
- try :
319
- with open (args .config or 'config.toml' ) as config :
320
- rb .config_toml = config .read ()
321
- except :
322
- pass
323
- try :
324
- rb .config_mk = open ('config.mk' ).read ()
325
- except :
326
- pass
327
-
328
- # Fetch/build the bootstrap
329
- rb .build = rb .build_triple ()
330
- rb .parse_nightly_dates ()
331
- rb .download_rust_nightly ()
332
- sys .stdout .flush ()
333
- rb .build_bootstrap ()
334
- sys .stdout .flush ()
335
-
336
- # Run the bootstrap
337
- args = [os .path .join (rb .build_dir , "bootstrap/debug/bootstrap" )]
338
- args .append ('--src' )
339
- args .append (rb .rust_root )
340
- args .append ('--build' )
341
- args .append (rb .build )
342
- args .extend (sys .argv [1 :])
343
- env = os .environ .copy ()
344
- env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
345
- rb .run (args , env )
313
+ def main ():
314
+ parser = argparse .ArgumentParser (description = 'Build rust' )
315
+ parser .add_argument ('--config' )
316
+ parser .add_argument ('-v' , '--verbose' , action = 'store_true' )
317
+
318
+ args = [a for a in sys .argv if a != '-h' ]
319
+ args , _ = parser .parse_known_args (args )
320
+
321
+ # Configure initial bootstrap
322
+ rb = RustBuild ()
323
+ rb .config_toml = ''
324
+ rb .config_mk = ''
325
+ rb .rust_root = os .path .abspath (os .path .join (__file__ , '../../..' ))
326
+ rb .build_dir = os .path .join (os .getcwd (), "build" )
327
+ rb .verbose = args .verbose
328
+
329
+ try :
330
+ with open (args .config or 'config.toml' ) as config :
331
+ rb .config_toml = config .read ()
332
+ except :
333
+ pass
334
+ try :
335
+ rb .config_mk = open ('config.mk' ).read ()
336
+ except :
337
+ pass
338
+
339
+ data = stage0_data (rb .rust_root )
340
+ rb ._rustc_channel , rb ._rustc_date = data ['rustc' ].split ('-' , 1 )
341
+ rb ._cargo_channel , rb ._cargo_date = data ['cargo' ].split ('-' , 1 )
342
+
343
+ # Fetch/build the bootstrap
344
+ rb .build = rb .build_triple ()
345
+ rb .download_stage0 ()
346
+ sys .stdout .flush ()
347
+ rb .build_bootstrap ()
348
+ sys .stdout .flush ()
349
+
350
+ # Run the bootstrap
351
+ args = [os .path .join (rb .build_dir , "bootstrap/debug/bootstrap" )]
352
+ args .append ('--src' )
353
+ args .append (rb .rust_root )
354
+ args .append ('--build' )
355
+ args .append (rb .build )
356
+ args .extend (sys .argv [1 :])
357
+ env = os .environ .copy ()
358
+ env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
359
+ rb .run (args , env )
360
+
361
+ if __name__ == '__main__' :
362
+ main ()
0 commit comments