bootstrap: don't call support_xz in hot-path
This commit is contained in:
parent
8d56bcc59c
commit
0019371e3d
@ -331,17 +331,6 @@ class RustBuild(object):
|
||||
self.use_vendored_sources = ''
|
||||
self.verbose = False
|
||||
|
||||
def support_xz():
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
temp_path = temp_file.name
|
||||
with tarfile.open(temp_path, "w:xz") as tar:
|
||||
pass
|
||||
return True
|
||||
except tarfile.CompressionError:
|
||||
return False
|
||||
|
||||
self.tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
|
||||
|
||||
def download_stage0(self):
|
||||
"""Fetch the build system for Rust, written in Rust
|
||||
@ -356,19 +345,30 @@ class RustBuild(object):
|
||||
rustc_channel = self.rustc_channel
|
||||
cargo_channel = self.cargo_channel
|
||||
|
||||
def support_xz():
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
temp_path = temp_file.name
|
||||
with tarfile.open(temp_path, "w:xz") as tar:
|
||||
pass
|
||||
return True
|
||||
except tarfile.CompressionError:
|
||||
return False
|
||||
|
||||
if self.rustc().startswith(self.bin_root()) and \
|
||||
(not os.path.exists(self.rustc()) or
|
||||
self.program_out_of_date(self.rustc_stamp())):
|
||||
if os.path.exists(self.bin_root()):
|
||||
shutil.rmtree(self.bin_root())
|
||||
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
|
||||
filename = "rust-std-{}-{}{}".format(
|
||||
rustc_channel, self.build, self.tarball_suffix)
|
||||
rustc_channel, self.build, tarball_suffix)
|
||||
pattern = "rust-std-{}".format(self.build)
|
||||
self._download_stage0_helper(filename, pattern)
|
||||
self._download_stage0_helper(filename, pattern, tarball_suffix)
|
||||
|
||||
filename = "rustc-{}-{}{}".format(rustc_channel, self.build,
|
||||
self.tarball_suffix)
|
||||
self._download_stage0_helper(filename, "rustc")
|
||||
tarball_suffix)
|
||||
self._download_stage0_helper(filename, "rustc", tarball_suffix)
|
||||
self.fix_executable("{}/bin/rustc".format(self.bin_root()))
|
||||
self.fix_executable("{}/bin/rustdoc".format(self.bin_root()))
|
||||
with output(self.rustc_stamp()) as rust_stamp:
|
||||
@ -379,20 +379,21 @@ class RustBuild(object):
|
||||
# the system MinGW ones.
|
||||
if "pc-windows-gnu" in self.build:
|
||||
filename = "rust-mingw-{}-{}{}".format(
|
||||
rustc_channel, self.build, self.tarball_suffix)
|
||||
self._download_stage0_helper(filename, "rust-mingw")
|
||||
rustc_channel, self.build, tarball_suffix)
|
||||
self._download_stage0_helper(filename, "rust-mingw", tarball_suffix)
|
||||
|
||||
if self.cargo().startswith(self.bin_root()) and \
|
||||
(not os.path.exists(self.cargo()) or
|
||||
self.program_out_of_date(self.cargo_stamp())):
|
||||
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
|
||||
filename = "cargo-{}-{}{}".format(cargo_channel, self.build,
|
||||
self.tarball_suffix)
|
||||
self._download_stage0_helper(filename, "cargo")
|
||||
tarball_suffix)
|
||||
self._download_stage0_helper(filename, "cargo", tarball_suffix)
|
||||
self.fix_executable("{}/bin/cargo".format(self.bin_root()))
|
||||
with output(self.cargo_stamp()) as cargo_stamp:
|
||||
cargo_stamp.write(self.date)
|
||||
|
||||
def _download_stage0_helper(self, filename, pattern):
|
||||
def _download_stage0_helper(self, filename, pattern, tarball_suffix):
|
||||
cache_dst = os.path.join(self.build_dir, "cache")
|
||||
rustc_cache = os.path.join(cache_dst, self.date)
|
||||
if not os.path.exists(rustc_cache):
|
||||
@ -402,7 +403,7 @@ class RustBuild(object):
|
||||
tarball = os.path.join(rustc_cache, filename)
|
||||
if not os.path.exists(tarball):
|
||||
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
|
||||
unpack(tarball, self.tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose)
|
||||
unpack(tarball, tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose)
|
||||
|
||||
@staticmethod
|
||||
def fix_executable(fname):
|
||||
|
Loading…
Reference in New Issue
Block a user