Skip to content

Commit 0c7fa26

Browse files
committed
Auto merge of #128459 - lolbinarycat:wget, r=Kobzol
make bootstrap use wget if available this improves reliability when downloading over unreliable connections. without this change, it was basically impossible for me to run the bootstrap tests.
2 parents db5704f + 22dad3b commit 0c7fa26

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

src/bootstrap/bootstrap.py

+41-16
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def eprint(*args, **kwargs):
4444
kwargs["file"] = sys.stderr
4545
print(*args, **kwargs)
4646

47-
4847
def get(base, url, path, checksums, verbose=False):
4948
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
5049
temp_path = temp_file.name
@@ -89,6 +88,8 @@ def download(path, url, probably_big, verbose):
8988
eprint("\nspurious failure, trying again")
9089
_download(path, url, probably_big, verbose, False)
9190

91+
def has_wget():
92+
return require(["wget", "--version"], exit=False) is not None
9293

9394
def _download(path, url, probably_big, verbose, exception):
9495
# Try to use curl (potentially available on win32
@@ -100,22 +101,45 @@ def _download(path, url, probably_big, verbose, exception):
100101
eprint("downloading {}".format(url))
101102

102103
try:
103-
if (probably_big or verbose) and "GITHUB_ACTIONS" not in os.environ:
104-
option = "-#"
104+
if has_wget():
105+
# options should be kept in sync with
106+
# src/bootstrap/src/core/download.rs
107+
# for consistancy
108+
# these flags should also be as close as possible to the behavior
109+
# of curl (except for wget's superior handling of surious network
110+
# errors)
111+
# curl's -R and -f are wget's default behavior.
112+
run(["wget",
113+
"--connect-timeout=30",
114+
"--read-timeout=30",
115+
"--tries=3",
116+
"--show-progress",
117+
"-O", path, url],
118+
verbose=verbose,
119+
exception=True,
120+
)
105121
else:
106-
option = "-s"
107-
# If curl is not present on Win32, we should not sys.exit
108-
# but raise `CalledProcessError` or `OSError` instead
109-
require(["curl", "--version"], exception=platform_is_win32())
110-
run(["curl", option,
111-
"-L", # Follow redirect.
112-
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
113-
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
114-
"-o", path,
115-
"--retry", "3", "-SRf", url],
116-
verbose=verbose,
117-
exception=True, # Will raise RuntimeError on failure
118-
)
122+
if (probably_big or verbose) and "GITHUB_ACTIONS" not in os.environ:
123+
option = "-#"
124+
else:
125+
option = "-s"
126+
# If curl is not present on Win32, we should not sys.exit
127+
# but raise `CalledProcessError` or `OSError` instead
128+
require(["curl", "--version"], exception=platform_is_win32())
129+
run(["curl", option,
130+
"-L", # Follow redirect.
131+
# timeout if speed is < 10 bytes/sec for > 30 seconds
132+
"-y", "30", "-Y", "10",
133+
# timeout if cannot connect within 30 seconds
134+
"--connect-timeout", "30",
135+
"-o", path,
136+
# -S: show errors, even if -s is specified
137+
# -R: set timestamp of downloaded file to that of the server
138+
# -f: fail on http error
139+
"--retry", "3", "-SRf", url],
140+
verbose=verbose,
141+
exception=True, # Will raise RuntimeError on failure
142+
)
119143
except (subprocess.CalledProcessError, OSError, RuntimeError):
120144
# see http://serverfault.com/questions/301128/how-to-download
121145
if platform_is_win32():
@@ -129,6 +153,7 @@ def _download(path, url, probably_big, verbose, exception):
129153
raise
130154

131155

156+
132157
def verify(path, expected, verbose):
133158
"""Check if the sha256 sum of the given path is valid"""
134159
if verbose:

src/bootstrap/src/core/download.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ impl Config {
210210
println!("downloading {url}");
211211
// Try curl. If that fails and we are on windows, fallback to PowerShell.
212212
let mut curl = command("curl");
213+
// build the arguments for curl and wget simultaneously
214+
let mut wget = command("wget");
213215
curl.args([
214216
"-y",
215217
"30",
@@ -223,14 +225,27 @@ impl Config {
223225
"3",
224226
"-SRf",
225227
]);
228+
// options should be kept in sync with
229+
// src/bootstrap/bootstrap.py
230+
// for consistancy
231+
wget.args([
232+
"--connect-timeout=30",
233+
"--read-timeout=30",
234+
"--tries=3",
235+
"-O",
236+
tempfile.to_str().unwrap(),
237+
]);
226238
// Don't print progress in CI; the \r wrapping looks bad and downloads don't take long enough for progress to be useful.
227239
if CiEnv::is_ci() {
228240
curl.arg("-s");
229241
} else {
230242
curl.arg("--progress-bar");
243+
wget.arg("--show-progress");
231244
}
232245
curl.arg(url);
233-
if !self.check_run(&mut curl) {
246+
wget.arg(url);
247+
curl.mark_as_executed();
248+
if !(self.check_run(&mut wget) || self.check_run(&mut curl)) {
234249
if self.build.contains("windows-msvc") {
235250
eprintln!("Fallback to PowerShell");
236251
for _ in 0..3 {
@@ -346,7 +361,9 @@ impl Config {
346361
println!(
347362
"invalid checksum: \n\
348363
found: {checksum}\n\
349-
expected: {expected}",
364+
expected: {expected}\n\
365+
path: {}",
366+
path.display(),
350367
);
351368
}
352369

0 commit comments

Comments
 (0)