Skip to content

Commit fa9d460

Browse files
authored
Rollup merge of rust-lang#129134 - lolbinarycat:continue-at, r=Kobzol
bootstrap: improve error recovery flags to curl alternative to rust-lang#128459 fixes rust-lang#110178 r? ``@Kobzol``
2 parents bafc91f + 56adf87 commit fa9d460

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Diff for: src/bootstrap/bootstrap.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ def get(base, url, path, checksums, verbose=False):
7979
eprint("removing", temp_path)
8080
os.unlink(temp_path)
8181

82+
def curl_version():
83+
m = re.match(bytes("^curl ([0-9]+)\\.([0-9]+)", "utf8"), require(["curl", "-V"]))
84+
if m is None:
85+
return (0, 0)
86+
return (int(m[1]), int(m[2]))
8287

8388
def download(path, url, probably_big, verbose):
8489
for _ in range(4):
@@ -107,11 +112,15 @@ def _download(path, url, probably_big, verbose, exception):
107112
# If curl is not present on Win32, we should not sys.exit
108113
# but raise `CalledProcessError` or `OSError` instead
109114
require(["curl", "--version"], exception=platform_is_win32())
110-
run(["curl", option,
115+
extra_flags = []
116+
if curl_version() > (7, 70):
117+
extra_flags = [ "--retry-all-errors" ]
118+
run(["curl", option] + extra_flags + [
111119
"-L", # Follow redirect.
112120
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
113121
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
114122
"-o", path,
123+
"--continue-at", "-",
115124
"--retry", "3", "-SRf", url],
116125
verbose=verbose,
117126
exception=True, # Will raise RuntimeError on failure

Diff for: src/bootstrap/src/core/download.rs

+24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ fn try_run(config: &Config, cmd: &mut Command) -> Result<(), ()> {
2222
config.try_run(cmd)
2323
}
2424

25+
fn extract_curl_version(out: &[u8]) -> semver::Version {
26+
let out = String::from_utf8_lossy(out);
27+
// The output should look like this: "curl <major>.<minor>.<patch> ..."
28+
out.lines()
29+
.next()
30+
.and_then(|line| line.split(" ").nth(1))
31+
.and_then(|version| semver::Version::parse(version).ok())
32+
.unwrap_or(semver::Version::new(1, 0, 0))
33+
}
34+
35+
fn curl_version() -> semver::Version {
36+
let mut curl = Command::new("curl");
37+
curl.arg("-V");
38+
let Ok(out) = curl.output() else { return semver::Version::new(1, 0, 0) };
39+
let out = out.stdout;
40+
extract_curl_version(&out)
41+
}
42+
2543
/// Generic helpers that are useful anywhere in bootstrap.
2644
impl Config {
2745
pub fn is_verbose(&self) -> bool {
@@ -220,6 +238,8 @@ impl Config {
220238
"30", // timeout if cannot connect within 30 seconds
221239
"-o",
222240
tempfile.to_str().unwrap(),
241+
"--continue-at",
242+
"-",
223243
"--retry",
224244
"3",
225245
"-SRf",
@@ -230,6 +250,10 @@ impl Config {
230250
} else {
231251
curl.arg("--progress-bar");
232252
}
253+
// --retry-all-errors was added in 7.71.0, don't use it if curl is old.
254+
if curl_version() >= semver::Version::new(7, 71, 0) {
255+
curl.arg("--retry-all-errors");
256+
}
233257
curl.arg(url);
234258
if !self.check_run(&mut curl) {
235259
if self.build.contains("windows-msvc") {

0 commit comments

Comments
 (0)