@@ -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
@@ -127,6 +128,7 @@ def unpack(tarball, dst, verbose=False, match=None):
127128 shutil .move (tp , fp )
128129 shutil .rmtree (os .path .join (dst , fname ))
129130
131+
130132def run (args , verbose = False , exception = False ):
131133 if verbose :
132134 print ("running: " + ' ' .join (args ))
@@ -141,6 +143,7 @@ def run(args, verbose=False, exception=False):
141143 raise RuntimeError (err )
142144 sys .exit (err )
143145
146+
144147def stage0_data (rust_root ):
145148 nightlies = os .path .join (rust_root , "src/stage0.txt" )
146149 data = {}
@@ -153,11 +156,13 @@ def stage0_data(rust_root):
153156 data [a ] = b
154157 return data
155158
159+
156160def format_build_time (duration ):
157161 return str (datetime .timedelta (seconds = int (duration )))
158162
159163
160164class RustBuild (object ):
165+
161166 def download_stage0 (self ):
162167 cache_dst = os .path .join (self .build_dir , "cache" )
163168 rustc_cache = os .path .join (cache_dst , self .stage0_date ())
@@ -172,11 +177,13 @@ def download_stage0(self):
172177 self .print_what_it_means_to_bootstrap ()
173178 if os .path .exists (self .bin_root ()):
174179 shutil .rmtree (self .bin_root ())
175- filename = "rust-std-{}-{}.tar.gz" .format (rustc_channel , self .build )
180+ filename = "rust-std-{}-{}.tar.gz" .format (
181+ rustc_channel , self .build )
176182 url = self ._download_url + "/dist/" + self .stage0_date ()
177183 tarball = os .path .join (rustc_cache , filename )
178184 if not os .path .exists (tarball ):
179- get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
185+ get ("{}/{}" .format (url , filename ),
186+ tarball , verbose = self .verbose )
180187 unpack (tarball , self .bin_root (),
181188 match = "rust-std-" + self .build ,
182189 verbose = self .verbose )
@@ -185,20 +192,25 @@ def download_stage0(self):
185192 url = self ._download_url + "/dist/" + self .stage0_date ()
186193 tarball = os .path .join (rustc_cache , filename )
187194 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 )
195+ get ("{}/{}" .format (url , filename ),
196+ tarball , verbose = self .verbose )
197+ unpack (tarball , self .bin_root (),
198+ match = "rustc" , verbose = self .verbose )
190199 self .fix_executable (self .bin_root () + "/bin/rustc" )
191200 self .fix_executable (self .bin_root () + "/bin/rustdoc" )
192201 with open (self .rustc_stamp (), 'w' ) as f :
193202 f .write (self .stage0_date ())
194203
195204 if "pc-windows-gnu" in self .build :
196- filename = "rust-mingw-{}-{}.tar.gz" .format (rustc_channel , self .build )
205+ filename = "rust-mingw-{}-{}.tar.gz" .format (
206+ rustc_channel , self .build )
197207 url = self ._download_url + "/dist/" + self .stage0_date ()
198208 tarball = os .path .join (rustc_cache , filename )
199209 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 )
210+ get ("{}/{}" .format (url , filename ),
211+ tarball , verbose = self .verbose )
212+ unpack (tarball , self .bin_root (),
213+ match = "rust-mingw" , verbose = self .verbose )
202214
203215 if self .cargo ().startswith (self .bin_root ()) and \
204216 (not os .path .exists (self .cargo ()) or self .cargo_out_of_date ()):
@@ -207,8 +219,10 @@ def download_stage0(self):
207219 url = self ._download_url + "/dist/" + self .stage0_date ()
208220 tarball = os .path .join (rustc_cache , filename )
209221 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 )
222+ get ("{}/{}" .format (url , filename ),
223+ tarball , verbose = self .verbose )
224+ unpack (tarball , self .bin_root (),
225+ match = "cargo" , verbose = self .verbose )
212226 self .fix_executable (self .bin_root () + "/bin/cargo" )
213227 with open (self .cargo_stamp (), 'w' ) as f :
214228 f .write (self .stage0_date ())
@@ -218,7 +232,8 @@ def fix_executable(self, fname):
218232
219233 default_encoding = sys .getdefaultencoding ()
220234 try :
221- ostype = subprocess .check_output (['uname' , '-s' ]).strip ().decode (default_encoding )
235+ ostype = subprocess .check_output (
236+ ['uname' , '-s' ]).strip ().decode (default_encoding )
222237 except (subprocess .CalledProcessError , WindowsError ):
223238 return
224239
@@ -234,7 +249,8 @@ def fix_executable(self, fname):
234249 print ("info: you seem to be running NixOS. Attempting to patch " + fname )
235250
236251 try :
237- interpreter = subprocess .check_output (["patchelf" , "--print-interpreter" , fname ])
252+ interpreter = subprocess .check_output (
253+ ["patchelf" , "--print-interpreter" , fname ])
238254 interpreter = interpreter .strip ().decode (default_encoding )
239255 except subprocess .CalledProcessError as e :
240256 print ("warning: failed to call patchelf: %s" % e )
@@ -243,7 +259,8 @@ def fix_executable(self, fname):
243259 loader = interpreter .split ("/" )[- 1 ]
244260
245261 try :
246- ldd_output = subprocess .check_output (['ldd' , '/run/current-system/sw/bin/sh' ])
262+ ldd_output = subprocess .check_output (
263+ ['ldd' , '/run/current-system/sw/bin/sh' ])
247264 ldd_output = ldd_output .strip ().decode (default_encoding )
248265 except subprocess .CalledProcessError as e :
249266 print ("warning: unable to call ldd: %s" % e )
@@ -261,7 +278,8 @@ def fix_executable(self, fname):
261278 correct_interpreter = loader_path + loader
262279
263280 try :
264- subprocess .check_output (["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
281+ subprocess .check_output (
282+ ["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
265283 except subprocess .CalledProcessError as e :
266284 print ("warning: failed to call patchelf: %s" % e )
267285 return
@@ -371,16 +389,16 @@ def build_bootstrap(self):
371389 env ["CARGO_TARGET_DIR" ] = build_dir
372390 env ["RUSTC" ] = self .rustc ()
373391 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 ""
392+ (os .pathsep + env ["LD_LIBRARY_PATH" ]) \
393+ if "LD_LIBRARY_PATH" in env else ""
376394 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 ""
395+ (os .pathsep + env ["DYLD_LIBRARY_PATH" ]) \
396+ if "DYLD_LIBRARY_PATH" in env else ""
379397 env ["LIBRARY_PATH" ] = os .path .join (self .bin_root (), "lib" ) + \
380- (os .pathsep + env ["LIBRARY_PATH" ]) \
381- if "LIBRARY_PATH" in env else ""
398+ (os .pathsep + env ["LIBRARY_PATH" ]) \
399+ if "LIBRARY_PATH" in env else ""
382400 env ["PATH" ] = os .path .join (self .bin_root (), "bin" ) + \
383- os .pathsep + env ["PATH" ]
401+ os .pathsep + env ["PATH" ]
384402 if not os .path .isfile (self .cargo ()):
385403 raise Exception ("no cargo executable found at `%s`" % self .cargo ())
386404 args = [self .cargo (), "build" , "--manifest-path" ,
@@ -406,8 +424,10 @@ def build_triple(self):
406424 if config :
407425 return config
408426 try :
409- ostype = subprocess .check_output (['uname' , '-s' ]).strip ().decode (default_encoding )
410- cputype = subprocess .check_output (['uname' , '-m' ]).strip ().decode (default_encoding )
427+ ostype = subprocess .check_output (
428+ ['uname' , '-s' ]).strip ().decode (default_encoding )
429+ cputype = subprocess .check_output (
430+ ['uname' , '-m' ]).strip ().decode (default_encoding )
411431 except (subprocess .CalledProcessError , OSError ):
412432 if sys .platform == 'win32' :
413433 return 'x86_64-pc-windows-msvc'
@@ -419,7 +439,8 @@ def build_triple(self):
419439 # The goal here is to come up with the same triple as LLVM would,
420440 # at least for the subset of platforms we're willing to target.
421441 if ostype == 'Linux' :
422- os_from_sp = subprocess .check_output (['uname' , '-o' ]).strip ().decode (default_encoding )
442+ os_from_sp = subprocess .check_output (
443+ ['uname' , '-o' ]).strip ().decode (default_encoding )
423444 if os_from_sp == 'Android' :
424445 ostype = 'linux-android'
425446 else :
@@ -443,7 +464,7 @@ def build_triple(self):
443464 # must be used instead.
444465 try :
445466 cputype = subprocess .check_output (['isainfo' ,
446- '-k' ]).strip ().decode (default_encoding )
467+ '-k' ]).strip ().decode (default_encoding )
447468 except (subprocess .CalledProcessError , OSError ):
448469 err = "isainfo not found"
449470 if self .verbose :
@@ -536,8 +557,8 @@ def build_triple(self):
536557
537558 def update_submodules (self ):
538559 if (not os .path .exists (os .path .join (self .rust_root , ".git" ))) or \
539- self .get_toml ('submodules' ) == "false" or \
540- self .get_mk ('CFG_DISABLE_MANAGE_SUBMODULES' ) == "1" :
560+ self .get_toml ('submodules' ) == "false" or \
561+ self .get_mk ('CFG_DISABLE_MANAGE_SUBMODULES' ) == "1" :
541562 return
542563
543564 print ('Updating submodules' )
@@ -549,10 +570,10 @@ def update_submodules(self):
549570 self .rust_root , ".gitmodules" ), "--get-regexp" , "path" ]).splitlines ()]
550571 for module in submodules :
551572 if module .endswith (b"llvm" ) and \
552- (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
573+ (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
553574 continue
554575 if module .endswith (b"jemalloc" ) and \
555- (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
576+ (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
556577 continue
557578 self .run (["git" , "submodule" , "update" ,
558579 "--init" , module ], cwd = self .rust_root )
@@ -608,7 +629,7 @@ def bootstrap():
608629 if rb .use_vendored_sources :
609630 if not os .path .exists ('.cargo' ):
610631 os .makedirs ('.cargo' )
611- with open ('.cargo/config' ,'w' ) as f :
632+ with open ('.cargo/config' , 'w' ) as f :
612633 f .write ("""
613634 [source.crates-io]
614635 replace-with = 'vendored-sources'
@@ -648,21 +669,25 @@ def bootstrap():
648669 env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
649670 rb .run (args , env = env )
650671
672+
651673def main ():
652674 start_time = time ()
653- help_triggered = ('-h' in sys .argv ) or ('--help' in sys .argv ) or (len (sys .argv ) == 1 )
675+ help_triggered = (
676+ '-h' in sys .argv ) or ('--help' in sys .argv ) or (len (sys .argv ) == 1 )
654677 try :
655678 bootstrap ()
656679 if not help_triggered :
657- print ("Build completed successfully in %s" % format_build_time (time () - start_time ))
680+ print ("Build completed successfully in %s" %
681+ format_build_time (time () - start_time ))
658682 except (SystemExit , KeyboardInterrupt ) as e :
659683 if hasattr (e , 'code' ) and isinstance (e .code , int ):
660684 exit_code = e .code
661685 else :
662686 exit_code = 1
663687 print (e )
664688 if not help_triggered :
665- print ("Build completed unsuccessfully in %s" % format_build_time (time () - start_time ))
689+ print ("Build completed unsuccessfully in %s" %
690+ format_build_time (time () - start_time ))
666691 sys .exit (exit_code )
667692
668693if __name__ == '__main__' :
0 commit comments