@@ -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,7 @@ def __init__(self):
331
331
self .use_vendored_sources = ''
332
332
self .verbose = False
333
333
334
+
334
335
def download_stage0 (self ):
335
336
"""Fetch the build system for Rust, written in Rust
336
337
@@ -344,18 +345,30 @@ def download_stage0(self):
344
345
rustc_channel = self .rustc_channel
345
346
cargo_channel = self .cargo_channel
346
347
348
+ def support_xz ():
349
+ try :
350
+ with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
351
+ temp_path = temp_file .name
352
+ with tarfile .open (temp_path , "w:xz" ) as tar :
353
+ pass
354
+ return True
355
+ except tarfile .CompressionError :
356
+ return False
357
+
347
358
if self .rustc ().startswith (self .bin_root ()) and \
348
359
(not os .path .exists (self .rustc ()) or
349
360
self .program_out_of_date (self .rustc_stamp ())):
350
361
if os .path .exists (self .bin_root ()):
351
362
shutil .rmtree (self .bin_root ())
352
- filename = "rust-std-{}-{}.tar.gz" .format (
353
- rustc_channel , self .build )
363
+ tarball_suffix = '.tar.xz' if support_xz () else '.tar.gz'
364
+ filename = "rust-std-{}-{}{}" .format (
365
+ rustc_channel , self .build , tarball_suffix )
354
366
pattern = "rust-std-{}" .format (self .build )
355
- self ._download_stage0_helper (filename , pattern )
367
+ self ._download_stage0_helper (filename , pattern , tarball_suffix )
356
368
357
- filename = "rustc-{}-{}.tar.gz" .format (rustc_channel , self .build )
358
- self ._download_stage0_helper (filename , "rustc" )
369
+ filename = "rustc-{}-{}{}" .format (rustc_channel , self .build ,
370
+ tarball_suffix )
371
+ self ._download_stage0_helper (filename , "rustc" , tarball_suffix )
359
372
self .fix_executable ("{}/bin/rustc" .format (self .bin_root ()))
360
373
self .fix_executable ("{}/bin/rustdoc" .format (self .bin_root ()))
361
374
with output (self .rustc_stamp ()) as rust_stamp :
@@ -365,20 +378,22 @@ 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 )
370
- self ._download_stage0_helper (filename , "rust-mingw" )
381
+ filename = "rust-mingw-{}-{}{} " .format (
382
+ rustc_channel , self .build , tarball_suffix )
383
+ self ._download_stage0_helper (filename , "rust-mingw" , tarball_suffix )
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 )
376
- self ._download_stage0_helper (filename , "cargo" )
388
+ tarball_suffix = '.tar.xz' if support_xz () else '.tar.gz'
389
+ filename = "cargo-{}-{}{}" .format (cargo_channel , self .build ,
390
+ tarball_suffix )
391
+ self ._download_stage0_helper (filename , "cargo" , tarball_suffix )
377
392
self .fix_executable ("{}/bin/cargo" .format (self .bin_root ()))
378
393
with output (self .cargo_stamp ()) as cargo_stamp :
379
394
cargo_stamp .write (self .date )
380
395
381
- def _download_stage0_helper (self , filename , pattern ):
396
+ def _download_stage0_helper (self , filename , pattern , tarball_suffix ):
382
397
cache_dst = os .path .join (self .build_dir , "cache" )
383
398
rustc_cache = os .path .join (cache_dst , self .date )
384
399
if not os .path .exists (rustc_cache ):
@@ -388,7 +403,7 @@ def _download_stage0_helper(self, filename, pattern):
388
403
tarball = os .path .join (rustc_cache , filename )
389
404
if not os .path .exists (tarball ):
390
405
get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
391
- unpack (tarball , self .bin_root (), match = pattern , verbose = self .verbose )
406
+ unpack (tarball , tarball_suffix , self .bin_root (), match = pattern , verbose = self .verbose )
392
407
393
408
@staticmethod
394
409
def fix_executable (fname ):
0 commit comments