@@ -40,7 +40,8 @@ def get(url, path, verbose=False):
4040 return
4141 else :
4242 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" )
4445 os .unlink (path )
4546 download (temp_path , url , True , verbose )
4647 if not verify (temp_path , sha_path , verbose ):
@@ -100,8 +101,8 @@ def verify(path, sha_path, verbose):
100101 verified = found == expected
101102 if not verified :
102103 print ("invalid checksum:\n "
103- " found: {}\n "
104- " expected: {}" .format (found , expected ))
104+ " found: {}\n "
105+ " expected: {}" .format (found , expected ))
105106 return verified
106107
107108
@@ -141,6 +142,7 @@ def run(args, verbose=False, exception=False, **kwargs):
141142 raise RuntimeError (err )
142143 sys .exit (err )
143144
145+
144146def stage0_data (rust_root ):
145147 nightlies = os .path .join (rust_root , "src/stage0.txt" )
146148 data = {}
@@ -153,11 +155,13 @@ def stage0_data(rust_root):
153155 data [a ] = b
154156 return data
155157
158+
156159def format_build_time (duration ):
157160 return str (datetime .timedelta (seconds = int (duration )))
158161
159162
160163class RustBuild (object ):
164+
161165 def download_stage0 (self ):
162166 cache_dst = os .path .join (self .build_dir , "cache" )
163167 rustc_cache = os .path .join (cache_dst , self .stage0_date ())
@@ -172,11 +176,13 @@ def download_stage0(self):
172176 self .print_what_it_means_to_bootstrap ()
173177 if os .path .exists (self .bin_root ()):
174178 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 )
176181 url = self ._download_url + "/dist/" + self .stage0_date ()
177182 tarball = os .path .join (rustc_cache , filename )
178183 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 )
180186 unpack (tarball , self .bin_root (),
181187 match = "rust-std-" + self .build ,
182188 verbose = self .verbose )
@@ -185,20 +191,25 @@ def download_stage0(self):
185191 url = self ._download_url + "/dist/" + self .stage0_date ()
186192 tarball = os .path .join (rustc_cache , filename )
187193 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 )
190198 self .fix_executable (self .bin_root () + "/bin/rustc" )
191199 self .fix_executable (self .bin_root () + "/bin/rustdoc" )
192200 with open (self .rustc_stamp (), 'w' ) as f :
193201 f .write (self .stage0_date ())
194202
195203 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 )
197206 url = self ._download_url + "/dist/" + self .stage0_date ()
198207 tarball = os .path .join (rustc_cache , filename )
199208 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 )
202213
203214 if self .cargo ().startswith (self .bin_root ()) and \
204215 (not os .path .exists (self .cargo ()) or self .cargo_out_of_date ()):
@@ -207,8 +218,10 @@ def download_stage0(self):
207218 url = self ._download_url + "/dist/" + self .stage0_date ()
208219 tarball = os .path .join (rustc_cache , filename )
209220 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 )
212225 self .fix_executable (self .bin_root () + "/bin/cargo" )
213226 with open (self .cargo_stamp (), 'w' ) as f :
214227 f .write (self .stage0_date ())
@@ -218,7 +231,8 @@ def fix_executable(self, fname):
218231
219232 default_encoding = sys .getdefaultencoding ()
220233 try :
221- ostype = subprocess .check_output (['uname' , '-s' ]).strip ().decode (default_encoding )
234+ ostype = subprocess .check_output (
235+ ['uname' , '-s' ]).strip ().decode (default_encoding )
222236 except (subprocess .CalledProcessError , WindowsError ):
223237 return
224238
@@ -234,7 +248,8 @@ def fix_executable(self, fname):
234248 print ("info: you seem to be running NixOS. Attempting to patch " + fname )
235249
236250 try :
237- interpreter = subprocess .check_output (["patchelf" , "--print-interpreter" , fname ])
251+ interpreter = subprocess .check_output (
252+ ["patchelf" , "--print-interpreter" , fname ])
238253 interpreter = interpreter .strip ().decode (default_encoding )
239254 except subprocess .CalledProcessError as e :
240255 print ("warning: failed to call patchelf: %s" % e )
@@ -243,7 +258,8 @@ def fix_executable(self, fname):
243258 loader = interpreter .split ("/" )[- 1 ]
244259
245260 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' ])
247263 ldd_output = ldd_output .strip ().decode (default_encoding )
248264 except subprocess .CalledProcessError as e :
249265 print ("warning: unable to call ldd: %s" % e )
@@ -261,7 +277,8 @@ def fix_executable(self, fname):
261277 correct_interpreter = loader_path + loader
262278
263279 try :
264- subprocess .check_output (["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
280+ subprocess .check_output (
281+ ["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
265282 except subprocess .CalledProcessError as e :
266283 print ("warning: failed to call patchelf: %s" % e )
267284 return
@@ -371,16 +388,16 @@ def build_bootstrap(self):
371388 env ["CARGO_TARGET_DIR" ] = build_dir
372389 env ["RUSTC" ] = self .rustc ()
373390 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 ""
376393 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 ""
379396 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 ""
382399 env ["PATH" ] = os .path .join (self .bin_root (), "bin" ) + \
383- os .pathsep + env ["PATH" ]
400+ os .pathsep + env ["PATH" ]
384401 if not os .path .isfile (self .cargo ()):
385402 raise Exception ("no cargo executable found at `%s`" % self .cargo ())
386403 args = [self .cargo (), "build" , "--manifest-path" ,
@@ -404,8 +421,10 @@ def build_triple(self):
404421 if config :
405422 return config
406423 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 )
409428 except (subprocess .CalledProcessError , OSError ):
410429 if sys .platform == 'win32' :
411430 return 'x86_64-pc-windows-msvc'
@@ -417,7 +436,8 @@ def build_triple(self):
417436 # The goal here is to come up with the same triple as LLVM would,
418437 # at least for the subset of platforms we're willing to target.
419438 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 )
421441 if os_from_sp == 'Android' :
422442 ostype = 'linux-android'
423443 else :
@@ -441,7 +461,7 @@ def build_triple(self):
441461 # must be used instead.
442462 try :
443463 cputype = subprocess .check_output (['isainfo' ,
444- '-k' ]).strip ().decode (default_encoding )
464+ '-k' ]).strip ().decode (default_encoding )
445465 except (subprocess .CalledProcessError , OSError ):
446466 err = "isainfo not found"
447467 if self .verbose :
@@ -534,8 +554,8 @@ def build_triple(self):
534554
535555 def update_submodules (self ):
536556 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" :
539559 return
540560
541561 print ('Updating submodules' )
@@ -547,10 +567,10 @@ def update_submodules(self):
547567 self .rust_root , ".gitmodules" ), "--get-regexp" , "path" ]).splitlines ()]
548568 for module in submodules :
549569 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' )):
551571 continue
552572 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' )):
554574 continue
555575 run (["git" , "submodule" , "update" ,
556576 "--init" , module ], cwd = self .rust_root )
@@ -611,7 +631,7 @@ def bootstrap():
611631 if rb .use_vendored_sources :
612632 if not os .path .exists ('.cargo' ):
613633 os .makedirs ('.cargo' )
614- with open ('.cargo/config' ,'w' ) as f :
634+ with open ('.cargo/config' , 'w' ) as f :
615635 f .write ("""
616636 [source.crates-io]
617637 replace-with = 'vendored-sources'
@@ -651,21 +671,25 @@ def bootstrap():
651671 env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
652672 run (args , env = env , verbose = rb .verbose )
653673
674+
654675def main ():
655676 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 )
657679 try :
658680 bootstrap ()
659681 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 ))
661684 except (SystemExit , KeyboardInterrupt ) as e :
662685 if hasattr (e , 'code' ) and isinstance (e .code , int ):
663686 exit_code = e .code
664687 else :
665688 exit_code = 1
666689 print (e )
667690 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 ))
669693 sys .exit (exit_code )
670694
671695if __name__ == '__main__' :
0 commit comments