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