1414
1515from time import time
1616
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 ):
1928 suffix = '.sha256'
2029 sha_url = url + suffix
2130 with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
@@ -24,19 +33,20 @@ def get(url, path, verbose=False):
2433 sha_path = sha_file .name
2534
2635 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 )
3848 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 ):
4050 raise RuntimeError ("failed verification" )
4151 if verbose :
4252 print ("moving {} to {}" .format (temp_path , path ))
@@ -365,16 +375,6 @@ def download_stage0(self):
365375 cargo_channel = self .cargo_channel
366376 rustfmt_channel = self .rustfmt_channel
367377
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-
378378 if self .rustc ().startswith (self .bin_root ()) and \
379379 (not os .path .exists (self .rustc ()) or
380380 self .program_out_of_date (self .rustc_stamp ())):
@@ -423,6 +423,19 @@ def support_xz():
423423 with output (self .rustfmt_stamp ()) as rustfmt_stamp :
424424 rustfmt_stamp .write (self .date + self .rustfmt_channel )
425425
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+
426439 def _download_stage0_helper (self , filename , pattern , tarball_suffix , date = None ):
427440 if date is None :
428441 date = self .date
@@ -437,6 +450,25 @@ def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None):
437450 get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
438451 unpack (tarball , tarball_suffix , self .bin_root (), match = pattern , verbose = self .verbose )
439452
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+
440472 def fix_bin_or_dylib (self , fname ):
441473 """Modifies the interpreter section of 'fname' to fix the dynamic linker,
442474 or the RPATH section, to fix the dynamic library search path
@@ -558,6 +590,17 @@ def rustfmt_stamp(self):
558590 """
559591 return os .path .join (self .bin_root (), '.rustfmt-stamp' )
560592
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+
561604 def program_out_of_date (self , stamp_path , extra = "" ):
562605 """Check if the given program stamp is out of date"""
563606 if not os .path .exists (stamp_path ) or self .clean :
@@ -581,6 +624,22 @@ def bin_root(self):
581624 """
582625 return os .path .join (self .build_dir , self .build , "stage0" )
583626
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+
584643 def get_toml (self , key , section = None ):
585644 """Returns the value of the given key in config.toml, otherwise returns None
586645
0 commit comments