Skip to content

Commit e75d6e5

Browse files
committed
move all download.rs method to new execution context command invocation
1 parent ea21ae0 commit e75d6e5

File tree

2 files changed

+13
-34
lines changed

2 files changed

+13
-34
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,18 +1034,6 @@ impl Config {
10341034
self.explicit_stage_from_cli || self.explicit_stage_from_config
10351035
}
10361036

1037-
/// Runs a command, printing out nice contextual information if it fails.
1038-
/// Exits if the command failed to execute at all, otherwise returns its
1039-
/// `status.success()`.
1040-
#[deprecated = "use `Builder::try_run` instead where possible"]
1041-
pub(crate) fn try_run(&self, cmd: &mut Command) -> Result<(), ()> {
1042-
if self.dry_run() {
1043-
return Ok(());
1044-
}
1045-
self.verbose(|| println!("running: {cmd:?}"));
1046-
build_helper::util::try_run(cmd, self.is_verbose())
1047-
}
1048-
10491037
pub(crate) fn test_args(&self) -> Vec<&str> {
10501038
let mut test_args = match self.cmd {
10511039
Subcommand::Test { ref test_args, .. }

src/bootstrap/src/core/download.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::ffi::OsString;
33
use std::fs::{self, File};
44
use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Write};
55
use std::path::{Path, PathBuf};
6-
use std::process::Command;
76
use std::sync::OnceLock;
87

98
use xz2::bufread::XzDecoder;
@@ -16,12 +15,6 @@ use crate::{Config, t};
1615

1716
static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
1817

19-
/// `Config::try_run` wrapper for this module to avoid warnings on `try_run`, since we don't have access to a `builder` yet.
20-
fn try_run(config: &Config, cmd: &mut Command) -> Result<(), ()> {
21-
#[expect(deprecated)]
22-
config.try_run(cmd)
23-
}
24-
2518
fn extract_curl_version(out: String) -> semver::Version {
2619
// The output should look like this: "curl <major>.<minor>.<patch> ..."
2720
out.lines()
@@ -169,23 +162,18 @@ impl Config {
169162
];
170163
}
171164
";
172-
nix_build_succeeded = try_run(
173-
self,
174-
Command::new("nix-build").args([
175-
Path::new("-E"),
176-
Path::new(NIX_EXPR),
177-
Path::new("-o"),
178-
&nix_deps_dir,
179-
]),
180-
)
181-
.is_ok();
165+
nix_build_succeeded = command("nix-build")
166+
.allow_failure()
167+
.args([Path::new("-E"), Path::new(NIX_EXPR), Path::new("-o"), &nix_deps_dir])
168+
.run_capture_stdout_exec_ctx(self)
169+
.is_success();
182170
nix_deps_dir
183171
});
184172
if !nix_build_succeeded {
185173
return;
186174
}
187175

188-
let mut patchelf = Command::new(nix_deps_dir.join("bin/patchelf"));
176+
let mut patchelf = command(nix_deps_dir.join("bin/patchelf"));
189177
patchelf.args(&[
190178
OsString::from("--add-rpath"),
191179
OsString::from(t!(fs::canonicalize(nix_deps_dir)).join("lib")),
@@ -196,8 +184,8 @@ impl Config {
196184
let dynamic_linker = t!(fs::read_to_string(dynamic_linker_path));
197185
patchelf.args(["--set-interpreter", dynamic_linker.trim_end()]);
198186
}
199-
200-
let _ = try_run(self, patchelf.arg(fname));
187+
patchelf.arg(fname);
188+
let _ = patchelf.run_capture_stdout_exec_ctx(self);
201189
}
202190

203191
fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) {
@@ -271,17 +259,20 @@ impl Config {
271259
if self.build.contains("windows-msvc") {
272260
eprintln!("Fallback to PowerShell");
273261
for _ in 0..3 {
274-
if try_run(self, Command::new("PowerShell.exe").args([
262+
let powershell = command("PowerShell.exe").args([
275263
"/nologo",
276264
"-Command",
277265
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
278266
&format!(
279267
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
280268
url, tempfile.to_str().expect("invalid UTF-8 not supported with powershell downloads"),
281269
),
282-
])).is_err() {
270+
]).run_capture_stdout_exec_ctx(self);
271+
272+
if powershell.is_failure() {
283273
return;
284274
}
275+
285276
eprintln!("\nspurious failure, trying again");
286277
}
287278
}

0 commit comments

Comments
 (0)