@@ -102,10 +102,10 @@ def verify(path, sha_path, verbose):
102
102
return verified
103
103
104
104
105
- def unpack (tarball , dst , verbose = False , match = None ):
105
+ def unpack (tarball , tarball_suffix , dst , verbose = False , match = None ):
106
106
"""Unpack the given tarball file"""
107
107
print ("extracting" , tarball )
108
- fname = os .path .basename (tarball ).replace (".tar.gz" , "" )
108
+ fname = os .path .basename (tarball ).replace (tarball_suffix , "" )
109
109
with contextlib .closing (tarfile .open (tarball )) as tar :
110
110
for member in tar .getnames ():
111
111
if "/" not in member :
@@ -331,6 +331,18 @@ def __init__(self):
331
331
self .use_vendored_sources = ''
332
332
self .verbose = False
333
333
334
+ def support_xz ():
335
+ try :
336
+ with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
337
+ temp_path = temp_file .name
338
+ with tarfile .open (temp_path , "w:xz" ) as tar :
339
+ pass
340
+ return True
341
+ except tarfile .CompressionError :
342
+ return False
343
+
344
+ self .tarball_suffix = '.tar.xz' if support_xz () else '.tar.gz'
345
+
334
346
def download_stage0 (self ):
335
347
"""Fetch the build system for Rust, written in Rust
336
348
@@ -349,12 +361,13 @@ def download_stage0(self):
349
361
self .program_out_of_date (self .rustc_stamp ())):
350
362
if os .path .exists (self .bin_root ()):
351
363
shutil .rmtree (self .bin_root ())
352
- filename = "rust-std-{}-{}.tar.gz " .format (
353
- rustc_channel , self .build )
364
+ filename = "rust-std-{}-{}{} " .format (
365
+ rustc_channel , self .build , self . tarball_suffix )
354
366
pattern = "rust-std-{}" .format (self .build )
355
367
self ._download_stage0_helper (filename , pattern )
356
368
357
- filename = "rustc-{}-{}.tar.gz" .format (rustc_channel , self .build )
369
+ filename = "rustc-{}-{}{}" .format (rustc_channel , self .build ,
370
+ self .tarball_suffix )
358
371
self ._download_stage0_helper (filename , "rustc" )
359
372
self .fix_executable ("{}/bin/rustc" .format (self .bin_root ()))
360
373
self .fix_executable ("{}/bin/rustdoc" .format (self .bin_root ()))
@@ -365,14 +378,15 @@ def download_stage0(self):
365
378
# libraries/binaries that are included in rust-std with
366
379
# the system MinGW ones.
367
380
if "pc-windows-gnu" in self .build :
368
- filename = "rust-mingw-{}-{}.tar.gz " .format (
369
- rustc_channel , self .build )
381
+ filename = "rust-mingw-{}-{}{} " .format (
382
+ rustc_channel , self .build , self . tarball_suffix )
370
383
self ._download_stage0_helper (filename , "rust-mingw" )
371
384
372
385
if self .cargo ().startswith (self .bin_root ()) and \
373
386
(not os .path .exists (self .cargo ()) or
374
387
self .program_out_of_date (self .cargo_stamp ())):
375
- filename = "cargo-{}-{}.tar.gz" .format (cargo_channel , self .build )
388
+ filename = "cargo-{}-{}{}" .format (cargo_channel , self .build ,
389
+ self .tarball_suffix )
376
390
self ._download_stage0_helper (filename , "cargo" )
377
391
self .fix_executable ("{}/bin/cargo" .format (self .bin_root ()))
378
392
with output (self .cargo_stamp ()) as cargo_stamp :
@@ -388,7 +402,7 @@ def _download_stage0_helper(self, filename, pattern):
388
402
tarball = os .path .join (rustc_cache , filename )
389
403
if not os .path .exists (tarball ):
390
404
get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
391
- unpack (tarball , self .bin_root (), match = pattern , verbose = self .verbose )
405
+ unpack (tarball , self .tarball_suffix , self . bin_root (), match = pattern , verbose = self .verbose )
392
406
393
407
@staticmethod
394
408
def fix_executable (fname ):
0 commit comments