Skip to content

Commit 9bb3832

Browse files
authoredMay 30, 2022
Rollup merge of #97519 - binggh:readd-help-on-error, r=jyn514
Re-add help_on_error for download-ci-llvm Closes #97503 - Re-added `help_on_error` for `download_component()` and the downstream functions - Removed dead code in `bootstrap.py` Thanks `@jyn514` for the helpful tips! (first contribution here, please let me know if I missed anything out!)
2 parents 106d5fd + c0f18f9 commit 9bb3832

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed
 

‎src/bootstrap/bootstrap.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def support_xz():
6363
except tarfile.CompressionError:
6464
return False
6565

66-
def get(base, url, path, checksums, verbose=False, do_verify=True, help_on_error=None):
66+
def get(base, url, path, checksums, verbose=False, do_verify=True):
6767
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
6868
temp_path = temp_file.name
6969

@@ -86,7 +86,7 @@ def get(base, url, path, checksums, verbose=False, do_verify=True, help_on_error
8686
print("ignoring already-download file",
8787
path, "due to failed verification")
8888
os.unlink(path)
89-
download(temp_path, "{}/{}".format(base, url), True, verbose, help_on_error=help_on_error)
89+
download(temp_path, "{}/{}".format(base, url), True, verbose)
9090
if do_verify and not verify(temp_path, sha256, verbose):
9191
raise RuntimeError("failed verification")
9292
if verbose:
@@ -99,17 +99,17 @@ def get(base, url, path, checksums, verbose=False, do_verify=True, help_on_error
9999
os.unlink(temp_path)
100100

101101

102-
def download(path, url, probably_big, verbose, help_on_error=None):
102+
def download(path, url, probably_big, verbose):
103103
for _ in range(0, 4):
104104
try:
105-
_download(path, url, probably_big, verbose, True, help_on_error=help_on_error)
105+
_download(path, url, probably_big, verbose, True)
106106
return
107107
except RuntimeError:
108108
print("\nspurious failure, trying again")
109-
_download(path, url, probably_big, verbose, False, help_on_error=help_on_error)
109+
_download(path, url, probably_big, verbose, False)
110110

111111

112-
def _download(path, url, probably_big, verbose, exception, help_on_error=None):
112+
def _download(path, url, probably_big, verbose, exception):
113113
# Try to use curl (potentially available on win32
114114
# https://devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows/)
115115
# If an error occurs:
@@ -134,7 +134,7 @@ def _download(path, url, probably_big, verbose, exception, help_on_error=None):
134134
"--retry", "3", "-Sf", "-o", path, url],
135135
verbose=verbose,
136136
exception=True, # Will raise RuntimeError on failure
137-
help_on_error=help_on_error)
137+
)
138138
except (subprocess.CalledProcessError, OSError, RuntimeError):
139139
# see http://serverfault.com/questions/301128/how-to-download
140140
if platform_is_win32:
@@ -186,7 +186,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
186186
shutil.rmtree(os.path.join(dst, fname))
187187

188188

189-
def run(args, verbose=False, exception=False, is_bootstrap=False, help_on_error=None, **kwargs):
189+
def run(args, verbose=False, exception=False, is_bootstrap=False, **kwargs):
190190
"""Run a child program in a new process"""
191191
if verbose:
192192
print("running: " + ' '.join(args))
@@ -197,8 +197,6 @@ def run(args, verbose=False, exception=False, is_bootstrap=False, help_on_error=
197197
code = ret.wait()
198198
if code != 0:
199199
err = "failed to run: " + ' '.join(args)
200-
if help_on_error is not None:
201-
err += "\n" + help_on_error
202200
if verbose or exception:
203201
raise RuntimeError(err)
204202
# For most failures, we definitely do want to print this error, or the user will have no

‎src/bootstrap/builder.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -869,15 +869,21 @@ impl<'a> Builder<'a> {
869869
self.try_run(patchelf.arg(fname));
870870
}
871871

872-
pub(crate) fn download_component(&self, base: &str, url: &str, dest_path: &Path) {
872+
pub(crate) fn download_component(
873+
&self,
874+
base: &str,
875+
url: &str,
876+
dest_path: &Path,
877+
help_on_error: &str,
878+
) {
873879
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
874880
let tempfile = self.tempdir().join(dest_path.file_name().unwrap());
875881
// FIXME: support `do_verify` (only really needed for nightly rustfmt)
876-
self.download_with_retries(&tempfile, &format!("{}/{}", base, url));
882+
self.download_with_retries(&tempfile, &format!("{}/{}", base, url), help_on_error);
877883
t!(std::fs::rename(&tempfile, dest_path));
878884
}
879885

880-
fn download_with_retries(&self, tempfile: &Path, url: &str) {
886+
fn download_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
881887
println!("downloading {}", url);
882888
// Try curl. If that fails and we are on windows, fallback to PowerShell.
883889
let mut curl = Command::new("curl");
@@ -914,6 +920,9 @@ impl<'a> Builder<'a> {
914920
println!("\nspurious failure, trying again");
915921
}
916922
}
923+
if !help_on_error.is_empty() {
924+
eprintln!("{}", help_on_error);
925+
}
917926
std::process::exit(1);
918927
}
919928
}

‎src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ fn download_component(builder: &Builder<'_>, filename: String, prefix: &str, com
14911491
let url = format!("rustc-builds/{commit}");
14921492
let tarball = rustc_cache.join(&filename);
14931493
if !tarball.exists() {
1494-
builder.download_component(base, &format!("{url}/{filename}"), &tarball);
1494+
builder.download_component(base, &format!("{url}/{filename}"), &tarball, "");
14951495
}
14961496
let bin_root = builder.out.join(builder.config.build.triple).join("ci-rustc");
14971497
builder.unpack(&tarball, &bin_root, prefix)

‎src/bootstrap/native.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,15 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
179179
let filename = format!("rust-dev-nightly-{}.tar.xz", builder.build.build.triple);
180180
let tarball = rustc_cache.join(&filename);
181181
if !tarball.exists() {
182-
builder.download_component(base, &format!("{}/{}", url, filename), &tarball);
182+
let help_on_error = "error: failed to download llvm from ci\n
183+
\nhelp: old builds get deleted after a certain time
184+
\nhelp: if trying to compile an old commit of rustc, disable `download-ci-llvm` in config.toml:
185+
\n
186+
\n[llvm]
187+
\ndownload-ci-llvm = false
188+
\n
189+
";
190+
builder.download_component(base, &format!("{}/{}", url, filename), &tarball, help_on_error);
183191
}
184192
let llvm_root = builder.config.ci_llvm_root();
185193
builder.unpack(&tarball, &llvm_root, "rust-dev");

0 commit comments

Comments
 (0)
Please sign in to comment.