@@ -25,19 +25,17 @@ def support_xz():
25
25
except tarfile .CompressionError :
26
26
return False
27
27
28
- def get (url , path , verbose = False , do_verify = True ):
29
- suffix = '.sha256'
30
- sha_url = url + suffix
28
+ def get (base , url , path , checksums , verbose = False , do_verify = True ):
31
29
with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
32
30
temp_path = temp_file .name
33
- with tempfile .NamedTemporaryFile (suffix = suffix , delete = False ) as sha_file :
34
- sha_path = sha_file .name
35
31
36
32
try :
37
33
if do_verify :
38
- download (sha_path , sha_url , False , verbose )
34
+ if url not in checksums :
35
+ raise RuntimeError ("src/stage0.json doesn't contain a checksum for {}" .format (url ))
36
+ sha256 = checksums [url ]
39
37
if os .path .exists (path ):
40
- if verify (path , sha_path , False ):
38
+ if verify (path , sha256 , False ):
41
39
if verbose :
42
40
print ("using already-download file" , path )
43
41
return
@@ -46,23 +44,17 @@ def get(url, path, verbose=False, do_verify=True):
46
44
print ("ignoring already-download file" ,
47
45
path , "due to failed verification" )
48
46
os .unlink (path )
49
- download (temp_path , url , True , verbose )
50
- if do_verify and not verify (temp_path , sha_path , verbose ):
47
+ download (temp_path , "{}/{}" . format ( base , url ) , True , verbose )
48
+ if do_verify and not verify (temp_path , sha256 , verbose ):
51
49
raise RuntimeError ("failed verification" )
52
50
if verbose :
53
51
print ("moving {} to {}" .format (temp_path , path ))
54
52
shutil .move (temp_path , path )
55
53
finally :
56
- delete_if_present (sha_path , verbose )
57
- delete_if_present (temp_path , verbose )
58
-
59
-
60
- def delete_if_present (path , verbose ):
61
- """Remove the given file if present"""
62
- if os .path .isfile (path ):
63
- if verbose :
64
- print ("removing" , path )
65
- os .unlink (path )
54
+ if os .path .isfile (temp_path ):
55
+ if verbose :
56
+ print ("removing" , temp_path )
57
+ os .unlink (temp_path )
66
58
67
59
68
60
def download (path , url , probably_big , verbose ):
@@ -99,14 +91,12 @@ def _download(path, url, probably_big, verbose, exception):
99
91
exception = exception )
100
92
101
93
102
- def verify (path , sha_path , verbose ):
94
+ def verify (path , expected , verbose ):
103
95
"""Check if the sha256 sum of the given path is valid"""
104
96
if verbose :
105
97
print ("verifying" , path )
106
98
with open (path , "rb" ) as source :
107
99
found = hashlib .sha256 (source .read ()).hexdigest ()
108
- with open (sha_path , "r" ) as sha256sum :
109
- expected = sha256sum .readline ().split ()[0 ]
110
100
verified = found == expected
111
101
if not verified :
112
102
print ("invalid checksum:\n "
@@ -375,6 +365,7 @@ def channel(self):
375
365
class RustBuild (object ):
376
366
"""Provide all the methods required to build Rust"""
377
367
def __init__ (self ):
368
+ self .checksums_sha256 = {}
378
369
self .stage0_compiler = None
379
370
self .stage0_rustfmt = None
380
371
self ._download_url = ''
@@ -529,12 +520,21 @@ def _download_component_helper(
529
520
os .makedirs (rustc_cache )
530
521
531
522
if stage0 :
532
- url = "{}/dist/{}" .format (self ._download_url , key )
523
+ base = self ._download_url
524
+ url = "dist/{}" .format (key )
533
525
else :
534
- url = "https://ci-artifacts.rust-lang.org/rustc-builds/{}" .format (self .rustc_commit )
526
+ base = "https://ci-artifacts.rust-lang.org"
527
+ url = "rustc-builds/{}" .format (self .rustc_commit )
535
528
tarball = os .path .join (rustc_cache , filename )
536
529
if not os .path .exists (tarball ):
537
- get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose , do_verify = stage0 )
530
+ get (
531
+ base ,
532
+ "{}/{}" .format (url , filename ),
533
+ tarball ,
534
+ self .checksums_sha256 ,
535
+ verbose = self .verbose ,
536
+ do_verify = stage0 ,
537
+ )
538
538
unpack (tarball , tarball_suffix , self .bin_root (stage0 ), match = pattern , verbose = self .verbose )
539
539
540
540
def _download_ci_llvm (self , llvm_sha , llvm_assertions ):
@@ -544,7 +544,8 @@ def _download_ci_llvm(self, llvm_sha, llvm_assertions):
544
544
if not os .path .exists (rustc_cache ):
545
545
os .makedirs (rustc_cache )
546
546
547
- url = "https://ci-artifacts.rust-lang.org/rustc-builds/{}" .format (llvm_sha )
547
+ base = "https://ci-artifacts.rust-lang.org"
548
+ url = "rustc-builds/{}" .format (llvm_sha )
548
549
if llvm_assertions :
549
550
url = url .replace ('rustc-builds' , 'rustc-builds-alt' )
550
551
# ci-artifacts are only stored as .xz, not .gz
@@ -556,7 +557,14 @@ def _download_ci_llvm(self, llvm_sha, llvm_assertions):
556
557
filename = "rust-dev-nightly-" + self .build + tarball_suffix
557
558
tarball = os .path .join (rustc_cache , filename )
558
559
if not os .path .exists (tarball ):
559
- get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose , do_verify = False )
560
+ get (
561
+ base ,
562
+ "{}/{}" .format (url , filename ),
563
+ tarball ,
564
+ self .checksums_sha256 ,
565
+ verbose = self .verbose ,
566
+ do_verify = False ,
567
+ )
560
568
unpack (tarball , tarball_suffix , self .llvm_root (),
561
569
match = "rust-dev" ,
562
570
verbose = self .verbose )
@@ -1158,6 +1166,7 @@ def bootstrap(help_triggered):
1158
1166
1159
1167
with open (os .path .join (build .rust_root , "src" , "stage0.json" )) as f :
1160
1168
data = json .load (f )
1169
+ build .checksums_sha256 = data ["checksums_sha256" ]
1161
1170
build .stage0_compiler = Stage0Toolchain (data ["compiler" ])
1162
1171
if data .get ("rustfmt" ) is not None :
1163
1172
build .stage0_rustfmt = Stage0Toolchain (data ["rustfmt" ])
0 commit comments