@@ -40,7 +40,8 @@ def get(url, path, verbose=False):
40
40
return
41
41
else :
42
42
if verbose :
43
- print ("ignoring already-download file " + path + " due to failed verification" )
43
+ print ("ignoring already-download file " +
44
+ path + " due to failed verification" )
44
45
os .unlink (path )
45
46
download (temp_path , url , True , verbose )
46
47
if not verify (temp_path , sha_path , verbose ):
@@ -100,8 +101,8 @@ def verify(path, sha_path, verbose):
100
101
verified = found == expected
101
102
if not verified :
102
103
print ("invalid checksum:\n "
103
- " found: {}\n "
104
- " expected: {}" .format (found , expected ))
104
+ " found: {}\n "
105
+ " expected: {}" .format (found , expected ))
105
106
return verified
106
107
107
108
@@ -141,6 +142,7 @@ def run(args, verbose=False, exception=False, **kwargs):
141
142
raise RuntimeError (err )
142
143
sys .exit (err )
143
144
145
+
144
146
def stage0_data (rust_root ):
145
147
nightlies = os .path .join (rust_root , "src/stage0.txt" )
146
148
data = {}
@@ -153,11 +155,13 @@ def stage0_data(rust_root):
153
155
data [a ] = b
154
156
return data
155
157
158
+
156
159
def format_build_time (duration ):
157
160
return str (datetime .timedelta (seconds = int (duration )))
158
161
159
162
160
163
class RustBuild (object ):
164
+
161
165
def download_stage0 (self ):
162
166
cache_dst = os .path .join (self .build_dir , "cache" )
163
167
rustc_cache = os .path .join (cache_dst , self .stage0_date ())
@@ -172,11 +176,13 @@ def download_stage0(self):
172
176
self .print_what_it_means_to_bootstrap ()
173
177
if os .path .exists (self .bin_root ()):
174
178
shutil .rmtree (self .bin_root ())
175
- filename = "rust-std-{}-{}.tar.gz" .format (rustc_channel , self .build )
179
+ filename = "rust-std-{}-{}.tar.gz" .format (
180
+ rustc_channel , self .build )
176
181
url = self ._download_url + "/dist/" + self .stage0_date ()
177
182
tarball = os .path .join (rustc_cache , filename )
178
183
if not os .path .exists (tarball ):
179
- get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
184
+ get ("{}/{}" .format (url , filename ),
185
+ tarball , verbose = self .verbose )
180
186
unpack (tarball , self .bin_root (),
181
187
match = "rust-std-" + self .build ,
182
188
verbose = self .verbose )
@@ -185,20 +191,25 @@ def download_stage0(self):
185
191
url = self ._download_url + "/dist/" + self .stage0_date ()
186
192
tarball = os .path .join (rustc_cache , filename )
187
193
if not os .path .exists (tarball ):
188
- get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
189
- unpack (tarball , self .bin_root (), match = "rustc" , verbose = self .verbose )
194
+ get ("{}/{}" .format (url , filename ),
195
+ tarball , verbose = self .verbose )
196
+ unpack (tarball , self .bin_root (),
197
+ match = "rustc" , verbose = self .verbose )
190
198
self .fix_executable (self .bin_root () + "/bin/rustc" )
191
199
self .fix_executable (self .bin_root () + "/bin/rustdoc" )
192
200
with open (self .rustc_stamp (), 'w' ) as f :
193
201
f .write (self .stage0_date ())
194
202
195
203
if "pc-windows-gnu" in self .build :
196
- filename = "rust-mingw-{}-{}.tar.gz" .format (rustc_channel , self .build )
204
+ filename = "rust-mingw-{}-{}.tar.gz" .format (
205
+ rustc_channel , self .build )
197
206
url = self ._download_url + "/dist/" + self .stage0_date ()
198
207
tarball = os .path .join (rustc_cache , filename )
199
208
if not os .path .exists (tarball ):
200
- get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
201
- unpack (tarball , self .bin_root (), match = "rust-mingw" , verbose = self .verbose )
209
+ get ("{}/{}" .format (url , filename ),
210
+ tarball , verbose = self .verbose )
211
+ unpack (tarball , self .bin_root (),
212
+ match = "rust-mingw" , verbose = self .verbose )
202
213
203
214
if self .cargo ().startswith (self .bin_root ()) and \
204
215
(not os .path .exists (self .cargo ()) or self .cargo_out_of_date ()):
@@ -207,8 +218,10 @@ def download_stage0(self):
207
218
url = self ._download_url + "/dist/" + self .stage0_date ()
208
219
tarball = os .path .join (rustc_cache , filename )
209
220
if not os .path .exists (tarball ):
210
- get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
211
- unpack (tarball , self .bin_root (), match = "cargo" , verbose = self .verbose )
221
+ get ("{}/{}" .format (url , filename ),
222
+ tarball , verbose = self .verbose )
223
+ unpack (tarball , self .bin_root (),
224
+ match = "cargo" , verbose = self .verbose )
212
225
self .fix_executable (self .bin_root () + "/bin/cargo" )
213
226
with open (self .cargo_stamp (), 'w' ) as f :
214
227
f .write (self .stage0_date ())
@@ -218,7 +231,8 @@ def fix_executable(self, fname):
218
231
219
232
default_encoding = sys .getdefaultencoding ()
220
233
try :
221
- ostype = subprocess .check_output (['uname' , '-s' ]).strip ().decode (default_encoding )
234
+ ostype = subprocess .check_output (
235
+ ['uname' , '-s' ]).strip ().decode (default_encoding )
222
236
except (subprocess .CalledProcessError , WindowsError ):
223
237
return
224
238
@@ -234,7 +248,8 @@ def fix_executable(self, fname):
234
248
print ("info: you seem to be running NixOS. Attempting to patch " + fname )
235
249
236
250
try :
237
- interpreter = subprocess .check_output (["patchelf" , "--print-interpreter" , fname ])
251
+ interpreter = subprocess .check_output (
252
+ ["patchelf" , "--print-interpreter" , fname ])
238
253
interpreter = interpreter .strip ().decode (default_encoding )
239
254
except subprocess .CalledProcessError as e :
240
255
print ("warning: failed to call patchelf: %s" % e )
@@ -243,7 +258,8 @@ def fix_executable(self, fname):
243
258
loader = interpreter .split ("/" )[- 1 ]
244
259
245
260
try :
246
- ldd_output = subprocess .check_output (['ldd' , '/run/current-system/sw/bin/sh' ])
261
+ ldd_output = subprocess .check_output (
262
+ ['ldd' , '/run/current-system/sw/bin/sh' ])
247
263
ldd_output = ldd_output .strip ().decode (default_encoding )
248
264
except subprocess .CalledProcessError as e :
249
265
print ("warning: unable to call ldd: %s" % e )
@@ -261,7 +277,8 @@ def fix_executable(self, fname):
261
277
correct_interpreter = loader_path + loader
262
278
263
279
try :
264
- subprocess .check_output (["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
280
+ subprocess .check_output (
281
+ ["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
265
282
except subprocess .CalledProcessError as e :
266
283
print ("warning: failed to call patchelf: %s" % e )
267
284
return
@@ -371,16 +388,16 @@ def build_bootstrap(self):
371
388
env ["CARGO_TARGET_DIR" ] = build_dir
372
389
env ["RUSTC" ] = self .rustc ()
373
390
env ["LD_LIBRARY_PATH" ] = os .path .join (self .bin_root (), "lib" ) + \
374
- (os .pathsep + env ["LD_LIBRARY_PATH" ]) \
375
- if "LD_LIBRARY_PATH" in env else ""
391
+ (os .pathsep + env ["LD_LIBRARY_PATH" ]) \
392
+ if "LD_LIBRARY_PATH" in env else ""
376
393
env ["DYLD_LIBRARY_PATH" ] = os .path .join (self .bin_root (), "lib" ) + \
377
- (os .pathsep + env ["DYLD_LIBRARY_PATH" ]) \
378
- if "DYLD_LIBRARY_PATH" in env else ""
394
+ (os .pathsep + env ["DYLD_LIBRARY_PATH" ]) \
395
+ if "DYLD_LIBRARY_PATH" in env else ""
379
396
env ["LIBRARY_PATH" ] = os .path .join (self .bin_root (), "lib" ) + \
380
- (os .pathsep + env ["LIBRARY_PATH" ]) \
381
- if "LIBRARY_PATH" in env else ""
397
+ (os .pathsep + env ["LIBRARY_PATH" ]) \
398
+ if "LIBRARY_PATH" in env else ""
382
399
env ["PATH" ] = os .path .join (self .bin_root (), "bin" ) + \
383
- os .pathsep + env ["PATH" ]
400
+ os .pathsep + env ["PATH" ]
384
401
if not os .path .isfile (self .cargo ()):
385
402
raise Exception ("no cargo executable found at `%s`" % self .cargo ())
386
403
args = [self .cargo (), "build" , "--manifest-path" ,
@@ -404,8 +421,10 @@ def build_triple(self):
404
421
if config :
405
422
return config
406
423
try :
407
- ostype = subprocess .check_output (['uname' , '-s' ]).strip ().decode (default_encoding )
408
- cputype = subprocess .check_output (['uname' , '-m' ]).strip ().decode (default_encoding )
424
+ ostype = subprocess .check_output (
425
+ ['uname' , '-s' ]).strip ().decode (default_encoding )
426
+ cputype = subprocess .check_output (
427
+ ['uname' , '-m' ]).strip ().decode (default_encoding )
409
428
except (subprocess .CalledProcessError , OSError ):
410
429
if sys .platform == 'win32' :
411
430
return 'x86_64-pc-windows-msvc'
@@ -417,7 +436,8 @@ def build_triple(self):
417
436
# The goal here is to come up with the same triple as LLVM would,
418
437
# at least for the subset of platforms we're willing to target.
419
438
if ostype == 'Linux' :
420
- os_from_sp = subprocess .check_output (['uname' , '-o' ]).strip ().decode (default_encoding )
439
+ os_from_sp = subprocess .check_output (
440
+ ['uname' , '-o' ]).strip ().decode (default_encoding )
421
441
if os_from_sp == 'Android' :
422
442
ostype = 'linux-android'
423
443
else :
@@ -441,7 +461,7 @@ def build_triple(self):
441
461
# must be used instead.
442
462
try :
443
463
cputype = subprocess .check_output (['isainfo' ,
444
- '-k' ]).strip ().decode (default_encoding )
464
+ '-k' ]).strip ().decode (default_encoding )
445
465
except (subprocess .CalledProcessError , OSError ):
446
466
err = "isainfo not found"
447
467
if self .verbose :
@@ -534,8 +554,8 @@ def build_triple(self):
534
554
535
555
def update_submodules (self ):
536
556
if (not os .path .exists (os .path .join (self .rust_root , ".git" ))) or \
537
- self .get_toml ('submodules' ) == "false" or \
538
- self .get_mk ('CFG_DISABLE_MANAGE_SUBMODULES' ) == "1" :
557
+ self .get_toml ('submodules' ) == "false" or \
558
+ self .get_mk ('CFG_DISABLE_MANAGE_SUBMODULES' ) == "1" :
539
559
return
540
560
541
561
print ('Updating submodules' )
@@ -547,10 +567,10 @@ def update_submodules(self):
547
567
self .rust_root , ".gitmodules" ), "--get-regexp" , "path" ]).splitlines ()]
548
568
for module in submodules :
549
569
if module .endswith (b"llvm" ) and \
550
- (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
570
+ (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
551
571
continue
552
572
if module .endswith (b"jemalloc" ) and \
553
- (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
573
+ (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
554
574
continue
555
575
run (["git" , "submodule" , "update" ,
556
576
"--init" , module ], cwd = self .rust_root )
@@ -611,7 +631,7 @@ def bootstrap():
611
631
if rb .use_vendored_sources :
612
632
if not os .path .exists ('.cargo' ):
613
633
os .makedirs ('.cargo' )
614
- with open ('.cargo/config' ,'w' ) as f :
634
+ with open ('.cargo/config' , 'w' ) as f :
615
635
f .write ("""
616
636
[source.crates-io]
617
637
replace-with = 'vendored-sources'
@@ -651,21 +671,25 @@ def bootstrap():
651
671
env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
652
672
run (args , env = env , verbose = rb .verbose )
653
673
674
+
654
675
def main ():
655
676
start_time = time ()
656
- help_triggered = ('-h' in sys .argv ) or ('--help' in sys .argv ) or (len (sys .argv ) == 1 )
677
+ help_triggered = (
678
+ '-h' in sys .argv ) or ('--help' in sys .argv ) or (len (sys .argv ) == 1 )
657
679
try :
658
680
bootstrap ()
659
681
if not help_triggered :
660
- print ("Build completed successfully in %s" % format_build_time (time () - start_time ))
682
+ print ("Build completed successfully in %s" %
683
+ format_build_time (time () - start_time ))
661
684
except (SystemExit , KeyboardInterrupt ) as e :
662
685
if hasattr (e , 'code' ) and isinstance (e .code , int ):
663
686
exit_code = e .code
664
687
else :
665
688
exit_code = 1
666
689
print (e )
667
690
if not help_triggered :
668
- print ("Build completed unsuccessfully in %s" % format_build_time (time () - start_time ))
691
+ print ("Build completed unsuccessfully in %s" %
692
+ format_build_time (time () - start_time ))
669
693
sys .exit (exit_code )
670
694
671
695
if __name__ == '__main__' :
0 commit comments