25
25
26
26
27
27
def get (url , path , verbose = False ):
28
- sha_url = url + ".sha256"
28
+ suffix = '.sha256'
29
+ sha_url = url + suffix
29
30
with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
30
31
temp_path = temp_file .name
31
- with tempfile .NamedTemporaryFile (suffix = ".sha256" , delete = False ) as sha_file :
32
+ with tempfile .NamedTemporaryFile (suffix = suffix , delete = False ) as sha_file :
32
33
sha_path = sha_file .name
33
34
34
35
try :
@@ -55,6 +56,7 @@ def get(url, path, verbose=False):
55
56
56
57
57
58
def delete_if_present (path , verbose ):
59
+ """Remove the given file if present"""
58
60
if os .path .isfile (path ):
59
61
if verbose :
60
62
print ("removing " + path )
@@ -92,12 +94,13 @@ def _download(path, url, probably_big, verbose, exception):
92
94
93
95
94
96
def verify (path , sha_path , verbose ):
97
+ """Check if the sha256 sum of the given path is valid"""
95
98
if verbose :
96
99
print ("verifying " + path )
97
- with open (path , "rb" ) as f :
98
- found = hashlib .sha256 (f .read ()).hexdigest ()
99
- with open (sha_path , "r" ) as f :
100
- expected = f .readline ().split ()[0 ]
100
+ with open (path , "rb" ) as source :
101
+ found = hashlib .sha256 (source .read ()).hexdigest ()
102
+ with open (sha_path , "r" ) as sha256sum :
103
+ expected = sha256sum .readline ().split ()[0 ]
101
104
verified = found == expected
102
105
if not verified :
103
106
print ("invalid checksum:\n "
@@ -107,6 +110,7 @@ def verify(path, sha_path, verbose):
107
110
108
111
109
112
def unpack (tarball , dst , verbose = False , match = None ):
113
+ """Unpack the given tarball file"""
110
114
print ("extracting " + tarball )
111
115
fname = os .path .basename (tarball ).replace (".tar.gz" , "" )
112
116
with contextlib .closing (tarfile .open (tarball )) as tar :
@@ -128,6 +132,7 @@ def unpack(tarball, dst, verbose=False, match=None):
128
132
shutil .move (tp , fp )
129
133
shutil .rmtree (os .path .join (dst , fname ))
130
134
135
+
131
136
def run (args , verbose = False , exception = False , ** kwargs ):
132
137
if verbose :
133
138
print ("running: " + ' ' .join (args ))
@@ -245,7 +250,8 @@ def fix_executable(self, fname):
245
250
return
246
251
247
252
# At this point we're pretty sure the user is running NixOS
248
- print ("info: you seem to be running NixOS. Attempting to patch " + fname )
253
+ nix_os_msg = "info: you seem to be running NixOS. Attempting to patch"
254
+ print (nix_os_msg , fname )
249
255
250
256
try :
251
257
interpreter = subprocess .check_output (
@@ -293,18 +299,22 @@ def stage0_cargo_channel(self):
293
299
return self ._cargo_channel
294
300
295
301
def rustc_stamp (self ):
302
+ """Return the path for .rustc-stamp"""
296
303
return os .path .join (self .bin_root (), '.rustc-stamp' )
297
304
298
305
def cargo_stamp (self ):
306
+ """Return the path for .cargo-stamp"""
299
307
return os .path .join (self .bin_root (), '.cargo-stamp' )
300
308
301
309
def rustc_out_of_date (self ):
310
+ """Check if rustc is out of date"""
302
311
if not os .path .exists (self .rustc_stamp ()) or self .clean :
303
312
return True
304
313
with open (self .rustc_stamp (), 'r' ) as f :
305
314
return self .stage0_date () != f .read ()
306
315
307
316
def cargo_out_of_date (self ):
317
+ """Check if cargo is out of date"""
308
318
if not os .path .exists (self .cargo_stamp ()) or self .clean :
309
319
return True
310
320
with open (self .cargo_stamp (), 'r' ) as f :
@@ -357,16 +367,15 @@ def get_string(self, line):
357
367
def exe_suffix (self ):
358
368
if sys .platform == 'win32' :
359
369
return '.exe'
360
- else :
361
- return ''
370
+ return ''
362
371
363
372
def print_what_it_means_to_bootstrap (self ):
364
373
if hasattr (self , 'printed' ):
365
374
return
366
375
self .printed = True
367
376
if os .path .exists (self .bootstrap_binary ()):
368
377
return
369
- if not '--help' in sys .argv or len (sys .argv ) == 1 :
378
+ if '--help' not in sys .argv or len (sys .argv ) == 1 :
370
379
return
371
380
372
381
print ('info: the build system for Rust is written in Rust, so this' )
@@ -461,8 +470,8 @@ def build_triple(self):
461
470
# always emit 'i386' on x86/amd64 systems). As such, isainfo -k
462
471
# must be used instead.
463
472
try :
464
- cputype = subprocess .check_output ([ 'isainfo' ,
465
- '-k' ]).strip ().decode (default_encoding )
473
+ cputype = subprocess .check_output (
474
+ [ 'isainfo' , '-k' ]).strip ().decode (default_encoding )
466
475
except (subprocess .CalledProcessError , OSError ):
467
476
err = "isainfo not found"
468
477
if self .verbose :
@@ -562,21 +571,26 @@ def update_submodules(self):
562
571
default_encoding = sys .getdefaultencoding ()
563
572
run (["git" , "submodule" , "-q" , "sync" ], cwd = self .rust_root )
564
573
submodules = [s .split (' ' , 1 )[1 ] for s in subprocess .check_output (
565
- ["git" , "config" , "--file" , os .path .join (self .rust_root , ".gitmodules" ),
574
+ ["git" , "config" , "--file" ,
575
+ os .path .join (self .rust_root , ".gitmodules" ),
566
576
"--get-regexp" , "path" ]
567
577
).decode (default_encoding ).splitlines ()]
568
578
submodules = [module for module in submodules
569
579
if not ((module .endswith ("llvm" ) and
570
- (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' ))) or
580
+ (self .get_toml ('llvm-config' ) or
581
+ self .get_mk ('CFG_LLVM_ROOT' ))) or
571
582
(module .endswith ("jemalloc" ) and
572
- (self .get_toml ('jemalloc' ) or self . get_mk ( 'CFG_JEMALLOC_ROOT' ))))
573
- ]
583
+ (self .get_toml ('jemalloc' ) or
584
+ self . get_mk ( 'CFG_JEMALLOC_ROOT' )))) ]
574
585
run (["git" , "submodule" , "update" ,
575
- "--init" ] + submodules , cwd = self .rust_root , verbose = self .verbose )
586
+ "--init" ] + submodules ,
587
+ cwd = self .rust_root , verbose = self .verbose )
576
588
run (["git" , "submodule" , "-q" , "foreach" , "git" ,
577
- "reset" , "-q" , "--hard" ], cwd = self .rust_root , verbose = self .verbose )
589
+ "reset" , "-q" , "--hard" ],
590
+ cwd = self .rust_root , verbose = self .verbose )
578
591
run (["git" , "submodule" , "-q" , "foreach" , "git" ,
579
- "clean" , "-qdfx" ], cwd = self .rust_root , verbose = self .verbose )
592
+ "clean" , "-qdfx" ],
593
+ cwd = self .rust_root , verbose = self .verbose )
580
594
581
595
582
596
def bootstrap ():
@@ -692,5 +706,6 @@ def main():
692
706
format_build_time (time () - start_time ))
693
707
sys .exit (exit_code )
694
708
709
+
695
710
if __name__ == '__main__' :
696
711
main ()
0 commit comments