@@ -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,20 +128,21 @@ 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
130
- def run (args , verbose = False , exception = False , cwd = None , env = None ):
131
+ def run (args , verbose = False , exception = False , ** kwargs ):
131
132
if verbose :
132
133
print ("running: " + ' ' .join (args ))
133
134
sys .stdout .flush ()
134
135
# Use Popen here instead of call() as it apparently allows powershell on
135
136
# Windows to not lock up waiting for input presumably.
136
- ret = subprocess .Popen (args , cwd = cwd , env = env )
137
+ ret = subprocess .Popen (args , ** kwargs )
137
138
code = ret .wait ()
138
139
if code != 0 :
139
140
err = "failed to run: " + ' ' .join (args )
140
141
if verbose or exception :
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" ,
@@ -395,16 +412,6 @@ def build_bootstrap(self):
395
412
args .append ("--frozen" )
396
413
run (args , env = env , verbose = self .verbose )
397
414
398
- def output (self , args , env = None , cwd = None ):
399
- default_encoding = sys .getdefaultencoding ()
400
- proc = subprocess .Popen (args , stdout = subprocess .PIPE , env = env , cwd = cwd )
401
- (out , err ) = proc .communicate ()
402
- ret = proc .wait ()
403
- if ret != 0 :
404
- print (out )
405
- sys .exit (ret )
406
- return out .decode (default_encoding )
407
-
408
415
def build_triple (self ):
409
416
default_encoding = sys .getdefaultencoding ()
410
417
config = self .get_toml ('build' )
@@ -414,8 +421,10 @@ def build_triple(self):
414
421
if config :
415
422
return config
416
423
try :
417
- ostype = subprocess .check_output (['uname' , '-s' ]).strip ().decode (default_encoding )
418
- 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 )
419
428
except (subprocess .CalledProcessError , OSError ):
420
429
if sys .platform == 'win32' :
421
430
return 'x86_64-pc-windows-msvc'
@@ -427,7 +436,8 @@ def build_triple(self):
427
436
# The goal here is to come up with the same triple as LLVM would,
428
437
# at least for the subset of platforms we're willing to target.
429
438
if ostype == 'Linux' :
430
- 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 )
431
441
if os_from_sp == 'Android' :
432
442
ostype = 'linux-android'
433
443
else :
@@ -451,7 +461,7 @@ def build_triple(self):
451
461
# must be used instead.
452
462
try :
453
463
cputype = subprocess .check_output (['isainfo' ,
454
- '-k' ]).strip ().decode (default_encoding )
464
+ '-k' ]).strip ().decode (default_encoding )
455
465
except (subprocess .CalledProcessError , OSError ):
456
466
err = "isainfo not found"
457
467
if self .verbose :
@@ -544,51 +554,29 @@ def build_triple(self):
544
554
545
555
def update_submodules (self ):
546
556
if (not os .path .exists (os .path .join (self .rust_root , ".git" ))) or \
547
- self .get_toml ('submodules' ) == "false" or \
548
- self .get_mk ('CFG_DISABLE_MANAGE_SUBMODULES' ) == "1" :
557
+ self .get_toml ('submodules' ) == "false" or \
558
+ self .get_mk ('CFG_DISABLE_MANAGE_SUBMODULES' ) == "1" :
549
559
return
550
-
551
560
print ('Updating submodules' )
552
- output = self .output (["git" , "submodule" , "status" ], cwd = self .rust_root )
553
- submodules = []
554
- for line in output .splitlines ():
555
- # NOTE `git submodule status` output looks like this:
556
- #
557
- # -5066b7dcab7e700844b0e2ba71b8af9dc627a59b src/liblibc
558
- # +b37ef24aa82d2be3a3cc0fe89bf82292f4ca181c src/compiler-rt (remotes/origin/..)
559
- # e058ca661692a8d01f8cf9d35939dfe3105ce968 src/jemalloc (3.6.0-533-ge058ca6)
560
- #
561
- # The first character can be '-', '+' or ' ' and denotes the
562
- # `State` of the submodule Right next to this character is the
563
- # SHA-1 of the submodule HEAD And after that comes the path to the
564
- # submodule
565
- path = line [1 :].split (' ' )[1 ]
566
- submodules .append ([path , line [0 ]])
567
-
568
- run (["git" , "submodule" , "sync" ], cwd = self .rust_root )
569
-
570
- for submod in submodules :
571
- path , status = submod
572
- if path .endswith ('llvm' ) and \
573
- (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' )):
574
- continue
575
- if path .endswith ('jemalloc' ) and \
576
- (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' )):
577
- continue
578
- submod_path = os .path .join (self .rust_root , path )
579
-
580
- if status == ' ' :
581
- run (["git" , "reset" , "--hard" ], cwd = submod_path )
582
- run (["git" , "clean" , "-fdx" ], cwd = submod_path )
583
- elif status == '+' :
584
- run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
585
- run (["git" , "reset" , "--hard" ], cwd = submod_path )
586
- run (["git" , "clean" , "-fdx" ], cwd = submod_path )
587
- elif status == '-' :
588
- run (["git" , "submodule" , "init" , path ], cwd = self .rust_root )
589
- run (["git" , "submodule" , "update" , path ], cwd = self .rust_root )
590
- else :
591
- raise ValueError ('unknown submodule status: ' + status )
561
+ default_encoding = sys .getdefaultencoding ()
562
+ run (["git" , "submodule" , "-q" , "sync" ], cwd = self .rust_root )
563
+ submodules = [s .split (' ' , 1 )[1 ] for s in subprocess .check_output (
564
+ ["git" , "config" , "--file" , os .path .join (self .rust_root , ".gitmodules" ),
565
+ "--get-regexp" , "path" ]
566
+ ).decode (default_encoding ).splitlines ()]
567
+ submodules = [module for module in submodules
568
+ if not ((module .endswith ("llvm" ) and
569
+ (self .get_toml ('llvm-config' ) or self .get_mk ('CFG_LLVM_ROOT' ))) or
570
+ (module .endswith ("jemalloc" ) and
571
+ (self .get_toml ('jemalloc' ) or self .get_mk ('CFG_JEMALLOC_ROOT' ))))
572
+ ]
573
+ run (["git" , "submodule" , "update" ,
574
+ "--init" ] + submodules , cwd = self .rust_root , verbose = self .verbose )
575
+ run (["git" , "submodule" , "-q" , "foreach" , "git" ,
576
+ "reset" , "-q" , "--hard" ], cwd = self .rust_root , verbose = self .verbose )
577
+ run (["git" , "submodule" , "-q" , "foreach" , "git" ,
578
+ "clean" , "-qdfx" ], cwd = self .rust_root , verbose = self .verbose )
579
+
592
580
593
581
def bootstrap ():
594
582
parser = argparse .ArgumentParser (description = 'Build rust' )
@@ -641,7 +629,7 @@ def bootstrap():
641
629
if rb .use_vendored_sources :
642
630
if not os .path .exists ('.cargo' ):
643
631
os .makedirs ('.cargo' )
644
- with open ('.cargo/config' ,'w' ) as f :
632
+ with open ('.cargo/config' , 'w' ) as f :
645
633
f .write ("""
646
634
[source.crates-io]
647
635
replace-with = 'vendored-sources'
@@ -681,21 +669,25 @@ def bootstrap():
681
669
env ["BOOTSTRAP_PARENT_ID" ] = str (os .getpid ())
682
670
run (args , env = env , verbose = rb .verbose )
683
671
672
+
684
673
def main ():
685
674
start_time = time ()
686
- 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 )
687
677
try :
688
678
bootstrap ()
689
679
if not help_triggered :
690
- 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 ))
691
682
except (SystemExit , KeyboardInterrupt ) as e :
692
683
if hasattr (e , 'code' ) and isinstance (e .code , int ):
693
684
exit_code = e .code
694
685
else :
695
686
exit_code = 1
696
687
print (e )
697
688
if not help_triggered :
698
- 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 ))
699
691
sys .exit (exit_code )
700
692
701
693
if __name__ == '__main__' :
0 commit comments