Download LLVM from CI to bootstrap
This commit is contained in:
parent
2d6cbd21b2
commit
a7b092f418
5 changed files with 178 additions and 37 deletions
|
@ -14,8 +14,17 @@ import tempfile
|
|||
|
||||
from time import time
|
||||
|
||||
def support_xz():
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
temp_path = temp_file.name
|
||||
with tarfile.open(temp_path, "w:xz"):
|
||||
pass
|
||||
return True
|
||||
except tarfile.CompressionError:
|
||||
return False
|
||||
|
||||
def get(url, path, verbose=False):
|
||||
def get(url, path, verbose=False, do_verify=True):
|
||||
suffix = '.sha256'
|
||||
sha_url = url + suffix
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
|
@ -24,19 +33,20 @@ def get(url, path, verbose=False):
|
|||
sha_path = sha_file.name
|
||||
|
||||
try:
|
||||
download(sha_path, sha_url, False, verbose)
|
||||
if os.path.exists(path):
|
||||
if verify(path, sha_path, False):
|
||||
if verbose:
|
||||
print("using already-download file", path)
|
||||
return
|
||||
else:
|
||||
if verbose:
|
||||
print("ignoring already-download file",
|
||||
path, "due to failed verification")
|
||||
os.unlink(path)
|
||||
if do_verify:
|
||||
download(sha_path, sha_url, False, verbose)
|
||||
if os.path.exists(path):
|
||||
if verify(path, sha_path, False):
|
||||
if verbose:
|
||||
print("using already-download file", path)
|
||||
return
|
||||
else:
|
||||
if verbose:
|
||||
print("ignoring already-download file",
|
||||
path, "due to failed verification")
|
||||
os.unlink(path)
|
||||
download(temp_path, url, True, verbose)
|
||||
if not verify(temp_path, sha_path, verbose):
|
||||
if do_verify and not verify(temp_path, sha_path, verbose):
|
||||
raise RuntimeError("failed verification")
|
||||
if verbose:
|
||||
print("moving {} to {}".format(temp_path, path))
|
||||
|
@ -365,16 +375,6 @@ class RustBuild(object):
|
|||
cargo_channel = self.cargo_channel
|
||||
rustfmt_channel = self.rustfmt_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"):
|
||||
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())):
|
||||
|
@ -423,6 +423,19 @@ class RustBuild(object):
|
|||
with output(self.rustfmt_stamp()) as rustfmt_stamp:
|
||||
rustfmt_stamp.write(self.date + self.rustfmt_channel)
|
||||
|
||||
if self.downloading_llvm():
|
||||
llvm_sha = subprocess.check_output(["git", "log", "--author=bors",
|
||||
"--format=%H", "-n1"]).decode(sys.getdefaultencoding()).strip()
|
||||
llvm_assertions = self.get_toml('assertions', 'llvm') == 'true'
|
||||
if self.program_out_of_date(self.llvm_stamp(), llvm_sha + str(llvm_assertions)):
|
||||
self._download_ci_llvm(llvm_sha, llvm_assertions)
|
||||
with output(self.llvm_stamp()) as llvm_stamp:
|
||||
llvm_stamp.write(self.date + llvm_sha + str(llvm_assertions))
|
||||
|
||||
def downloading_llvm(self):
|
||||
opt = self.get_toml('download-ci-llvm', 'llvm')
|
||||
return opt == "true"
|
||||
|
||||
def _download_stage0_helper(self, filename, pattern, tarball_suffix, date=None):
|
||||
if date is None:
|
||||
date = self.date
|
||||
|
@ -437,6 +450,25 @@ class RustBuild(object):
|
|||
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
|
||||
unpack(tarball, tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose)
|
||||
|
||||
def _download_ci_llvm(self, llvm_sha, llvm_assertions):
|
||||
cache_prefix = "llvm-{}-{}".format(llvm_sha, llvm_assertions)
|
||||
cache_dst = os.path.join(self.build_dir, "cache")
|
||||
rustc_cache = os.path.join(cache_dst, cache_prefix)
|
||||
if not os.path.exists(rustc_cache):
|
||||
os.makedirs(rustc_cache)
|
||||
|
||||
url = "https://ci-artifacts.rust-lang.org/rustc-builds/{}".format(llvm_sha)
|
||||
if llvm_assertions:
|
||||
url = url.replace('rustc-builds', 'rustc-builds-alt')
|
||||
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
|
||||
filename = "rust-dev-nightly-" + self.build + tarball_suffix
|
||||
tarball = os.path.join(rustc_cache, filename)
|
||||
if not os.path.exists(tarball):
|
||||
get("{}/{}".format(url, filename), tarball, verbose=self.verbose, do_verify=False)
|
||||
unpack(tarball, tarball_suffix, self.llvm_root(),
|
||||
match="rust-dev",
|
||||
verbose=self.verbose)
|
||||
|
||||
def fix_bin_or_dylib(self, fname):
|
||||
"""Modifies the interpreter section of 'fname' to fix the dynamic linker,
|
||||
or the RPATH section, to fix the dynamic library search path
|
||||
|
@ -558,6 +590,17 @@ class RustBuild(object):
|
|||
"""
|
||||
return os.path.join(self.bin_root(), '.rustfmt-stamp')
|
||||
|
||||
def llvm_stamp(self):
|
||||
"""Return the path for .rustfmt-stamp
|
||||
|
||||
>>> rb = RustBuild()
|
||||
>>> rb.build_dir = "build"
|
||||
>>> rb.llvm_stamp() == os.path.join("build", "ci-llvm", ".llvm-stamp")
|
||||
True
|
||||
"""
|
||||
return os.path.join(self.llvm_root(), '.llvm-stamp')
|
||||
|
||||
|
||||
def program_out_of_date(self, stamp_path, extra=""):
|
||||
"""Check if the given program stamp is out of date"""
|
||||
if not os.path.exists(stamp_path) or self.clean:
|
||||
|
@ -581,6 +624,22 @@ class RustBuild(object):
|
|||
"""
|
||||
return os.path.join(self.build_dir, self.build, "stage0")
|
||||
|
||||
def llvm_root(self):
|
||||
"""Return the CI LLVM root directory
|
||||
|
||||
>>> rb = RustBuild()
|
||||
>>> rb.build_dir = "build"
|
||||
>>> rb.llvm_root() == os.path.join("build", "ci-llvm")
|
||||
True
|
||||
|
||||
When the 'build' property is given should be a nested directory:
|
||||
|
||||
>>> rb.build = "devel"
|
||||
>>> rb.llvm_root() == os.path.join("build", "devel", "ci-llvm")
|
||||
True
|
||||
"""
|
||||
return os.path.join(self.build_dir, self.build, "ci-llvm")
|
||||
|
||||
def get_toml(self, key, section=None):
|
||||
"""Returns the value of the given key in config.toml, otherwise returns None
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue