10
10
11
11
import argparse
12
12
import contextlib
13
+ import hashlib
13
14
import os
14
15
import shutil
15
16
import subprocess
18
19
19
20
def get (url , path , verbose = False ):
20
21
print ("downloading " + url )
21
- # see http://serverfault.com/questions/301128/how-to-download
22
- if sys .platform == 'win32' :
23
- run (["PowerShell.exe" , "/nologo" , "-Command" ,
24
- "(New-Object System.Net.WebClient).DownloadFile('" + url +
25
- "', '" + path + "')" ], verbose = verbose )
26
- else :
27
- run (["curl" , "-o" , path , url ], verbose = verbose )
22
+ sha_url = url + ".sha256"
23
+ sha_path = path + ".sha256"
24
+ for _url , _path in ((url , path ), (sha_url , sha_path )):
25
+ # see http://serverfault.com/questions/301128/how-to-download
26
+ if sys .platform == 'win32' :
27
+ run (["PowerShell.exe" , "/nologo" , "-Command" ,
28
+ "(New-Object System.Net.WebClient)"
29
+ ".DownloadFile('{}', '{}')" .format (_url , _path )],
30
+ verbose = verbose )
31
+ else :
32
+ run (["curl" , "-o" , _path , _url ], verbose = verbose )
33
+ print ("verifying " + path )
34
+ with open (path , "rb" ) as f :
35
+ found = hashlib .sha256 (f .read ()).hexdigest ()
36
+ with open (sha_path , "r" ) as f :
37
+ expected , _ = f .readline ().split ()
38
+ if found != expected :
39
+ err = ("invalid checksum:\n "
40
+ " found: {}\n "
41
+ " expected: {}" .format (found , expected ))
42
+ if verbose :
43
+ raise RuntimeError (err )
44
+ sys .exit (err )
28
45
29
46
def unpack (tarball , dst , verbose = False , match = None ):
30
47
print ("extracting " + tarball )
@@ -57,9 +74,10 @@ def run(args, verbose=False):
57
74
ret = subprocess .Popen (args )
58
75
code = ret .wait ()
59
76
if code != 0 :
60
- if not verbose :
61
- print ("failed to run: " + ' ' .join (args ))
62
- raise RuntimeError ("failed to run command" )
77
+ err = "failed to run: " + ' ' .join (args )
78
+ if verbose :
79
+ raise RuntimeError (err )
80
+ sys .exit (err )
63
81
64
82
class RustBuild :
65
83
def download_rust_nightly (self ):
@@ -210,7 +228,10 @@ def build_triple(self):
210
228
if sys .platform == 'win32' :
211
229
return 'x86_64-pc-windows-msvc'
212
230
else :
213
- raise
231
+ err = "uname not found"
232
+ if self .verbose :
233
+ raise Exception (err )
234
+ sys .exit (err )
214
235
215
236
# Darwin's `uname -s` lies and always returns i386. We have to use
216
237
# sysctl instead.
@@ -253,7 +274,10 @@ def build_triple(self):
253
274
cputype = 'x86_64'
254
275
ostype = 'pc-windows-gnu'
255
276
else :
256
- raise ValueError ("unknown OS type: " + ostype )
277
+ err = "unknown OS type: " + ostype
278
+ if self .verbose :
279
+ raise ValueError (err )
280
+ sys .exit (err )
257
281
258
282
if cputype in {'i386' , 'i486' , 'i686' , 'i786' , 'x86' }:
259
283
cputype = 'i686'
@@ -269,7 +293,10 @@ def build_triple(self):
269
293
elif cputype in {'amd64' , 'x86_64' , 'x86-64' , 'x64' }:
270
294
cputype = 'x86_64'
271
295
else :
272
- raise ValueError ("unknown cpu type: " + cputype )
296
+ err = "unknown cpu type: " + cputype
297
+ if self .verbose :
298
+ raise ValueError (err )
299
+ sys .exit (err )
273
300
274
301
return cputype + '-' + ostype
275
302
0 commit comments