From c0f18f9412f222e7f314a637d69968618f633b01 Mon Sep 17 00:00:00 2001 From: binggh Date: Sun, 29 May 2022 22:11:36 +0800 Subject: [PATCH] Re-add help_on_error for download-ci-llvm Remove dead code Missing } ./x.py fmt Remove duplicate check Recursively remove all usage of help_on_error --- src/bootstrap/bootstrap.py | 18 ++++++++---------- src/bootstrap/builder.rs | 15 ++++++++++++--- src/bootstrap/config.rs | 2 +- src/bootstrap/native.rs | 10 +++++++++- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 955edd94c78..a997c4f63ab 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -63,7 +63,7 @@ def support_xz(): except tarfile.CompressionError: return False -def get(base, url, path, checksums, verbose=False, do_verify=True, help_on_error=None): +def get(base, url, path, checksums, verbose=False, do_verify=True): with tempfile.NamedTemporaryFile(delete=False) as temp_file: temp_path = temp_file.name @@ -86,7 +86,7 @@ def get(base, url, path, checksums, verbose=False, do_verify=True, help_on_error print("ignoring already-download file", path, "due to failed verification") os.unlink(path) - download(temp_path, "{}/{}".format(base, url), True, verbose, help_on_error=help_on_error) + download(temp_path, "{}/{}".format(base, url), True, verbose) if do_verify and not verify(temp_path, sha256, verbose): raise RuntimeError("failed verification") if verbose: @@ -99,17 +99,17 @@ def get(base, url, path, checksums, verbose=False, do_verify=True, help_on_error os.unlink(temp_path) -def download(path, url, probably_big, verbose, help_on_error=None): +def download(path, url, probably_big, verbose): for _ in range(0, 4): try: - _download(path, url, probably_big, verbose, True, help_on_error=help_on_error) + _download(path, url, probably_big, verbose, True) return except RuntimeError: print("\nspurious failure, trying again") - _download(path, url, probably_big, verbose, False, help_on_error=help_on_error) + _download(path, url, probably_big, verbose, False) -def _download(path, url, probably_big, verbose, exception, help_on_error=None): +def _download(path, url, probably_big, verbose, exception): # Try to use curl (potentially available on win32 # https://devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows/) # If an error occurs: @@ -134,7 +134,7 @@ def _download(path, url, probably_big, verbose, exception, help_on_error=None): "--retry", "3", "-Sf", "-o", path, url], verbose=verbose, exception=True, # Will raise RuntimeError on failure - help_on_error=help_on_error) + ) except (subprocess.CalledProcessError, OSError, RuntimeError): # see http://serverfault.com/questions/301128/how-to-download if platform_is_win32: @@ -186,7 +186,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None): shutil.rmtree(os.path.join(dst, fname)) -def run(args, verbose=False, exception=False, is_bootstrap=False, help_on_error=None, **kwargs): +def run(args, verbose=False, exception=False, is_bootstrap=False, **kwargs): """Run a child program in a new process""" if verbose: print("running: " + ' '.join(args)) @@ -197,8 +197,6 @@ def run(args, verbose=False, exception=False, is_bootstrap=False, help_on_error= code = ret.wait() if code != 0: err = "failed to run: " + ' '.join(args) - if help_on_error is not None: - err += "\n" + help_on_error if verbose or exception: raise RuntimeError(err) # For most failures, we definitely do want to print this error, or the user will have no diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index d344c55158a..56d59c03e49 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -869,15 +869,21 @@ pub(crate) fn fix_bin_or_dylib(&self, fname: &Path) { self.try_run(patchelf.arg(fname)); } - pub(crate) fn download_component(&self, base: &str, url: &str, dest_path: &Path) { + pub(crate) fn download_component( + &self, + base: &str, + url: &str, + dest_path: &Path, + help_on_error: &str, + ) { // Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/. let tempfile = self.tempdir().join(dest_path.file_name().unwrap()); // FIXME: support `do_verify` (only really needed for nightly rustfmt) - self.download_with_retries(&tempfile, &format!("{}/{}", base, url)); + self.download_with_retries(&tempfile, &format!("{}/{}", base, url), help_on_error); t!(std::fs::rename(&tempfile, dest_path)); } - fn download_with_retries(&self, tempfile: &Path, url: &str) { + fn download_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) { println!("downloading {}", url); // Try curl. If that fails and we are on windows, fallback to PowerShell. let mut curl = Command::new("curl"); @@ -914,6 +920,9 @@ fn download_with_retries(&self, tempfile: &Path, url: &str) { println!("\nspurious failure, trying again"); } } + if !help_on_error.is_empty() { + eprintln!("{}", help_on_error); + } std::process::exit(1); } } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 7775e057370..8e94fc7c4be 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -1491,7 +1491,7 @@ fn download_component(builder: &Builder<'_>, filename: String, prefix: &str, com let url = format!("rustc-builds/{commit}"); let tarball = rustc_cache.join(&filename); if !tarball.exists() { - builder.download_component(base, &format!("{url}/{filename}"), &tarball); + builder.download_component(base, &format!("{url}/{filename}"), &tarball, ""); } let bin_root = builder.out.join(builder.config.build.triple).join("ci-rustc"); builder.unpack(&tarball, &bin_root, prefix) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 72c2c2e654d..cbd877e5f42 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -179,7 +179,15 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) { let filename = format!("rust-dev-nightly-{}.tar.xz", builder.build.build.triple); let tarball = rustc_cache.join(&filename); if !tarball.exists() { - builder.download_component(base, &format!("{}/{}", url, filename), &tarball); + let help_on_error = "error: failed to download llvm from ci\n +\nhelp: old builds get deleted after a certain time +\nhelp: if trying to compile an old commit of rustc, disable `download-ci-llvm` in config.toml: +\n +\n[llvm] +\ndownload-ci-llvm = false +\n +"; + builder.download_component(base, &format!("{}/{}", url, filename), &tarball, help_on_error); } let llvm_root = builder.config.ci_llvm_root(); builder.unpack(&tarball, &llvm_root, "rust-dev"); -- GitLab