@@ -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
@@ -127,6 +128,7 @@ def unpack(tarball, dst, verbose=False, match=None):
127
128
shutil .move (tp , fp )
128
129
shutil .rmtree (os .path .join (dst , fname ))
129
130
131
+
130
132
def run (args , verbose = False , exception = False ):
131
133
if verbose :
132
134
print ("running: " + ' ' .join (args ))
@@ -141,6 +143,7 @@ def run(args, verbose=False, exception=False):
141
143
raise RuntimeError (err )
142
144
sys .exit (err )
143
145
146
+
144
147
def stage0_data (rust_root ):
145
148
nightlies = os .path .join (rust_root , "src/stage0.txt" )
146
149
data = {}
@@ -153,11 +156,13 @@ def stage0_data(rust_root):
153
156
data [a ] = b
154
157
return data
155
158
159
+
156
160
def format_build_time (duration ):
157
161
return str (datetime .timedelta (seconds = int (duration )))
158
162
159
163
160
164
class RustBuild (object ):
165
+
161
166
def download_stage0 (self ):
162
167
cache_dst = os .path .join (self .build_dir , "cache" )
163
168
rustc_cache = os .path .join (cache_dst , self .stage0_date ())
@@ -172,11 +177,13 @@ def download_stage0(self):
172
177
self .print_what_it_means_to_bootstrap ()
173
178
if os .path .exists (self .bin_root ()):
174
179
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 )
176
182
url = self ._download_url + "/dist/" + self .stage0_date ()
177
183
tarball = os .path .join (rustc_cache , filename )
178
184
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 )
180
187
unpack (tarball , self .bin_root (),
181
188
match = "rust-std-" + self .build ,
182
189
verbose = self .verbose )
@@ -185,20 +192,25 @@ def download_stage0(self):
185
192
url = self ._download_url + "/dist/" + self .stage0_date ()
186
193
tarball = os .path .join (rustc_cache , filename )
187
194
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 )
190
199
self .fix_executable (self .bin_root () + "/bin/rustc" )
191
200
self .fix_executable (self .bin_root () + "/bin/rustdoc" )
192
201
with open (self .rustc_stamp (), 'w' ) as f :
193
202
f .write (self .stage0_date ())
194
203
195
204
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 )
197
207
url = self ._download_url + "/dist/" + self .stage0_date ()
198
208
tarball = os .path .join (rustc_cache , filename )
199
209
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 )
202
214
203
215
if self .cargo ().startswith (self .bin_root ()) and \
204
216
(not os .path .exists (self .cargo ()) or self .cargo_out_of_date ()):
@@ -207,8 +219,10 @@ def download_stage0(self):
207
219
url = self ._download_url + "/dist/" + self .stage0_date ()
208
220
tarball = os .path .join (rustc_cache , filename )
209
221
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 )
212
226
self .fix_executable (self .bin_root () + "/bin/cargo" )
213
227
with open (self .cargo_stamp (), 'w' ) as f :
214
228
f .write (self .stage0_date ())
@@ -218,7 +232,8 @@ def fix_executable(self, fname):
218
232
219
233
default_encoding = sys .getdefaultencoding ()
220
234
try :
221
- ostype = subprocess .check_output (['uname' , '-s' ]).strip ().decode (default_encoding )
235
+ ostype = subprocess .check_output (
236
+ ['uname' , '-s' ]).strip ().decode (default_encoding )
222
237
except (subprocess .CalledProcessError , WindowsError ):
223
238
return
224
239
@@ -234,7 +249,8 @@ def fix_executable(self, fname):
234
249
print ("info: you seem to be running NixOS. Attempting to patch " + fname )
235
250
236
251
try :
237
- interpreter = subprocess .check_output (["patchelf" , "--print-interpreter" , fname ])
252
+ interpreter = subprocess .check_output (
253
+ ["patchelf" , "--print-interpreter" , fname ])
238
254
interpreter = interpreter .strip ().decode (default_encoding )
239
255
except subprocess .CalledProcessError as e :
240
256
print ("warning: failed to call patchelf: %s" % e )
@@ -243,7 +259,8 @@ def fix_executable(self, fname):
243
259
loader = interpreter .split ("/" )[- 1 ]
244
260
245
261
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' ])
247
264
ldd_output = ldd_output .strip ().decode (default_encoding )
248
265
except subprocess .CalledProcessError as e :
249
266
print ("warning: unable to call ldd: %s" % e )
@@ -261,7 +278,8 @@ def fix_executable(self, fname):
261
278
correct_interpreter = loader_path + loader
262
279
263
280
try :
264
- subprocess .check_output (["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
281
+ subprocess .check_output (
282
+ ["patchelf" , "--set-interpreter" , correct_interpreter , fname ])
265
283
except subprocess .CalledProcessError as e :
266
284
print ("warning: failed to call patchelf: %s" % e )
267
285
return
@@ -371,16 +389,16 @@ def build_bootstrap(self):
371
389
env ["CARGO_TARGET_DIR" ] = build_dir
372
390
env ["RUSTC" ] = self .rustc ()
373
391
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 ""
376
394
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 ""
379
397
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 ""
382
400
env ["PATH" ] = os .path .join (self .bin_root (), "bin" ) + \
383
- os .pathsep + env ["PATH" ]
401
+ os .pathsep + env ["PATH" ]
384
402
if not os .path .isfile (self .cargo ()):
385
403
raise Exception ("no cargo executable found at `%s`" % self .cargo ())
386
404
args = [self .cargo (), "build" , "--manifest-path" ,
@@ -406,8 +424,10 @@ def build_triple(self):
406
424
if config :
407
425
return config
408
426
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 )
411
431
except (subprocess .CalledProcessError , OSError ):
412
432
if sys .platform == 'win32' :
413
433
return 'x86_64-pc-windows-msvc'
@@ -419,7 +439,8 @@ def build_triple(self):
419
439
# The goal here is to come up with the same triple as LLVM would,
420
440
# at least for the subset of platforms we're willing to target.
421
441
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 )
423
444
if os_from_sp == 'Android' :
424
445
ostype = 'linux-android'
425
446
else :
@@ -443,7 +464,7 @@ def build_triple(self):
443
464
# must be used instead.
444
465
try :
445
466
cputype = subprocess .check_output (['isainfo' ,
446
- '-k' ]).strip ().decode (default_encoding )
467
+ '-k' ]).strip ().decode (default_encoding )
447
468
except (subprocess .CalledProcessError , OSError ):
448
469
err = "isainfo not found"
449
470
if self .verbose :
@@ -536,8 +557,8 @@ def build_triple(self):
536
557
537
558
def update_submodules (self ):
538
559
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" :
541
562
return
542
563
543
564
print ('Updating submodules' )
@@ -549,10 +570,10 @@ def update_submodules(self):
549
570
self .rust_root , ".gitmodules" ), "--get-regexp" , "path" ]).splitlines ()]
550
571
for module in submodules :
551
572
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' )):
553
574
continue
554
575
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' )):
556
577
continue
557
578
self .run (["git" , "submodule" , "update" ,
558
579
"--init" , module ], cwd = self .rust_root )
@@ -608,7 +629,7 @@ def bootstrap():
608
629
if rb .use_vendored_sources :
609
630
if not os .path .exists ('.cargo' ):
610
631
os .makedirs ('.cargo' )
611
- with open ('.cargo/config' ,'w' ) as f :
632
+ with open ('.cargo/config' , 'w' ) as f :
612
633
f .write ("""
613
634
[source.crates-io]
614
635
replace-with = 'vendored-sources'
@@ -648,21 +669,25 @@ def bootstrap():
648
669
env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
649
670
rb .run (args , env = env )
650
671
672
+
651
673
def main ():
652
674
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 )
654
677
try :
655
678
bootstrap ()
656
679
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 ))
658
682
except (SystemExit , KeyboardInterrupt ) as e :
659
683
if hasattr (e , 'code' ) and isinstance (e .code , int ):
660
684
exit_code = e .code
661
685
else :
662
686
exit_code = 1
663
687
print (e )
664
688
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 ))
666
691
sys .exit (exit_code )
667
692
668
693
if __name__ == '__main__' :
0 commit comments