14
14
15
15
from time import time
16
16
17
-
18
- def get (url , path , verbose = False ):
17
+ def support_xz ():
18
+ try :
19
+ with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
20
+ temp_path = temp_file .name
21
+ with tarfile .open (temp_path , "w:xz" ):
22
+ pass
23
+ return True
24
+ except tarfile .CompressionError :
25
+ return False
26
+
27
+ def get (url , path , verbose = False , do_verify = True ):
19
28
suffix = '.sha256'
20
29
sha_url = url + suffix
21
30
with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
@@ -24,19 +33,20 @@ def get(url, path, verbose=False):
24
33
sha_path = sha_file .name
25
34
26
35
try :
27
- download (sha_path , sha_url , False , verbose )
28
- if os .path .exists (path ):
29
- if verify (path , sha_path , False ):
30
- if verbose :
31
- print ("using already-download file" , path )
32
- return
33
- else :
34
- if verbose :
35
- print ("ignoring already-download file" ,
36
- path , "due to failed verification" )
37
- os .unlink (path )
36
+ if do_verify :
37
+ download (sha_path , sha_url , False , verbose )
38
+ if os .path .exists (path ):
39
+ if verify (path , sha_path , False ):
40
+ if verbose :
41
+ print ("using already-download file" , path )
42
+ return
43
+ else :
44
+ if verbose :
45
+ print ("ignoring already-download file" ,
46
+ path , "due to failed verification" )
47
+ os .unlink (path )
38
48
download (temp_path , url , True , verbose )
39
- if not verify (temp_path , sha_path , verbose ):
49
+ if do_verify and not verify (temp_path , sha_path , verbose ):
40
50
raise RuntimeError ("failed verification" )
41
51
if verbose :
42
52
print ("moving {} to {}" .format (temp_path , path ))
@@ -365,16 +375,6 @@ def download_stage0(self):
365
375
cargo_channel = self .cargo_channel
366
376
rustfmt_channel = self .rustfmt_channel
367
377
368
- def support_xz ():
369
- try :
370
- with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
371
- temp_path = temp_file .name
372
- with tarfile .open (temp_path , "w:xz" ):
373
- pass
374
- return True
375
- except tarfile .CompressionError :
376
- return False
377
-
378
378
if self .rustc ().startswith (self .bin_root ()) and \
379
379
(not os .path .exists (self .rustc ()) or
380
380
self .program_out_of_date (self .rustc_stamp ())):
@@ -423,6 +423,19 @@ def support_xz():
423
423
with output (self .rustfmt_stamp ()) as rustfmt_stamp :
424
424
rustfmt_stamp .write (self .date + self .rustfmt_channel )
425
425
426
+ if self .downloading_llvm ():
427
+ llvm_sha = subprocess .check_output (["git" , "log" , "--author=bors" ,
428
+ "--format=%H" , "-n1" ]).decode (sys .getdefaultencoding ()).strip ()
429
+ llvm_assertions = self .get_toml ('assertions' , 'llvm' ) == 'true'
430
+ if self .program_out_of_date (self .llvm_stamp (), llvm_sha + str (llvm_assertions )):
431
+ self ._download_ci_llvm (llvm_sha , llvm_assertions )
432
+ with output (self .llvm_stamp ()) as llvm_stamp :
433
+ llvm_stamp .write (self .date + llvm_sha + str (llvm_assertions ))
434
+
435
+ def downloading_llvm (self ):
436
+ opt = self .get_toml ('download-ci-llvm' , 'llvm' )
437
+ return opt == "true"
438
+
426
439
def _download_stage0_helper (self , filename , pattern , tarball_suffix , date = None ):
427
440
if date is None :
428
441
date = self .date
@@ -437,6 +450,25 @@ def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None):
437
450
get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
438
451
unpack (tarball , tarball_suffix , self .bin_root (), match = pattern , verbose = self .verbose )
439
452
453
+ def _download_ci_llvm (self , llvm_sha , llvm_assertions ):
454
+ cache_prefix = "llvm-{}-{}" .format (llvm_sha , llvm_assertions )
455
+ cache_dst = os .path .join (self .build_dir , "cache" )
456
+ rustc_cache = os .path .join (cache_dst , cache_prefix )
457
+ if not os .path .exists (rustc_cache ):
458
+ os .makedirs (rustc_cache )
459
+
460
+ url = "https://ci-artifacts.rust-lang.org/rustc-builds/{}" .format (llvm_sha )
461
+ if llvm_assertions :
462
+ url = url .replace ('rustc-builds' , 'rustc-builds-alt' )
463
+ tarball_suffix = '.tar.xz' if support_xz () else '.tar.gz'
464
+ filename = "rust-dev-nightly-" + self .build + tarball_suffix
465
+ tarball = os .path .join (rustc_cache , filename )
466
+ if not os .path .exists (tarball ):
467
+ get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose , do_verify = False )
468
+ unpack (tarball , tarball_suffix , self .llvm_root (),
469
+ match = "rust-dev" ,
470
+ verbose = self .verbose )
471
+
440
472
def fix_bin_or_dylib (self , fname ):
441
473
"""Modifies the interpreter section of 'fname' to fix the dynamic linker,
442
474
or the RPATH section, to fix the dynamic library search path
@@ -558,6 +590,17 @@ def rustfmt_stamp(self):
558
590
"""
559
591
return os .path .join (self .bin_root (), '.rustfmt-stamp' )
560
592
593
+ def llvm_stamp (self ):
594
+ """Return the path for .rustfmt-stamp
595
+
596
+ >>> rb = RustBuild()
597
+ >>> rb.build_dir = "build"
598
+ >>> rb.llvm_stamp() == os.path.join("build", "ci-llvm", ".llvm-stamp")
599
+ True
600
+ """
601
+ return os .path .join (self .llvm_root (), '.llvm-stamp' )
602
+
603
+
561
604
def program_out_of_date (self , stamp_path , extra = "" ):
562
605
"""Check if the given program stamp is out of date"""
563
606
if not os .path .exists (stamp_path ) or self .clean :
@@ -581,6 +624,22 @@ def bin_root(self):
581
624
"""
582
625
return os .path .join (self .build_dir , self .build , "stage0" )
583
626
627
+ def llvm_root (self ):
628
+ """Return the CI LLVM root directory
629
+
630
+ >>> rb = RustBuild()
631
+ >>> rb.build_dir = "build"
632
+ >>> rb.llvm_root() == os.path.join("build", "ci-llvm")
633
+ True
634
+
635
+ When the 'build' property is given should be a nested directory:
636
+
637
+ >>> rb.build = "devel"
638
+ >>> rb.llvm_root() == os.path.join("build", "devel", "ci-llvm")
639
+ True
640
+ """
641
+ return os .path .join (self .build_dir , self .build , "ci-llvm" )
642
+
584
643
def get_toml (self , key , section = None ):
585
644
"""Returns the value of the given key in config.toml, otherwise returns None
586
645
0 commit comments