remove execution context from flag module and correct the command invocation according to suggestions

This commit is contained in:
bit-aloo 2025-06-09 20:34:30 +05:30
parent f3e1eb1dca
commit e9ced508f4
No known key found for this signature in database
5 changed files with 19 additions and 25 deletions

View file

@ -29,9 +29,9 @@ fn main() {
}
debug!("parsing flags");
let (flags, exec_ctx) = Flags::parse(&args);
let flags = Flags::parse(&args);
debug!("parsing config based on flags");
let config = Config::parse(flags, exec_ctx);
let config = Config::parse(flags);
let mut build_lock;
let _build_lock_guard;

View file

@ -368,7 +368,11 @@ impl Config {
feature = "tracing",
instrument(target = "CONFIG_HANDLING", level = "trace", name = "Config::parse", skip_all)
)]
pub fn parse(flags: Flags, exec_ctx: ExecutionContext) -> Config {
pub fn parse(flags: Flags) -> Config {
let mut exec_ctx = ExecutionContext::new();
exec_ctx.set_dry_run(if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled });
exec_ctx.set_verbose(flags.verbose);
exec_ctx.set_fail_fast(flags.cmd.fail_fast());
Self::parse_inner(flags, Self::get_toml, exec_ctx)
}
@ -1065,7 +1069,7 @@ impl Config {
let mut git = helpers::git(Some(&self.src));
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
git.allow_failure().run_capture_stdout(self).stdout()
git.run_capture_stdout(self).stdout()
}
/// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@ -1334,15 +1338,11 @@ impl Config {
};
// Determine commit checked out in submodule.
let checked_out_hash = submodule_git()
.allow_failure()
.args(["rev-parse", "HEAD"])
.run_capture_stdout(self)
.stdout();
let checked_out_hash =
submodule_git().args(["rev-parse", "HEAD"]).run_capture_stdout(self).stdout();
let checked_out_hash = checked_out_hash.trim_end();
// Determine commit that the submodule *should* have.
let recorded = helpers::git(Some(&self.src))
.allow_failure()
.run_always()
.args(["ls-tree", "HEAD"])
.arg(relative_path)

View file

@ -14,8 +14,7 @@ use crate::core::build_steps::setup::Profile;
use crate::core::builder::{Builder, Kind};
use crate::core::config::Config;
use crate::core::config::target_selection::{TargetSelectionList, target_selection_list};
use crate::utils::execution_context::ExecutionContext;
use crate::{Build, DocTests, DryRun};
use crate::{Build, DocTests};
#[derive(Copy, Clone, Default, Debug, ValueEnum)]
pub enum Color {
@ -210,8 +209,8 @@ impl Flags {
HelpVerboseOnly::try_parse_from(normalize_args(args))
{
println!("NOTE: updating submodules before printing available paths");
let (flags, exec_ctx) = Self::parse(&[String::from("build")]);
let config = Config::parse(flags, exec_ctx);
let flags = Self::parse(&[String::from("build")]);
let config = Config::parse(flags);
let build = Build::new(config);
let paths = Builder::get_help(&build, subcommand);
if let Some(s) = paths {
@ -229,13 +228,8 @@ impl Flags {
feature = "tracing",
instrument(level = "trace", name = "Flags::parse", skip_all, fields(args = ?args))
)]
pub fn parse(args: &[String]) -> (Self, ExecutionContext) {
let mut exec_ctx = ExecutionContext::new();
let flags = Flags::parse_from(normalize_args(args));
exec_ctx.set_dry_run(if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled });
exec_ctx.set_verbose(flags.verbose);
exec_ctx.set_fail_fast(flags.cmd.fail_fast());
(flags, exec_ctx)
pub fn parse(args: &[String]) -> Self {
Flags::parse_from(normalize_args(args))
}
}

View file

@ -80,7 +80,7 @@ impl Config {
/// on NixOS
fn should_fix_bins_and_dylibs(&self) -> bool {
let val = *SHOULD_FIX_BINS_AND_DYLIBS.get_or_init(|| {
let uname = command("uname").arg("-s").run_capture_stdout(self);
let uname = command("uname").allow_failure().arg("-s").run_capture_stdout(self);
if uname.is_failure() {
return false;
}
@ -185,7 +185,7 @@ impl Config {
patchelf.args(["--set-interpreter", dynamic_linker.trim_end()]);
}
patchelf.arg(fname);
let _ = patchelf.run_capture_stdout(self);
let _ = patchelf.allow_failure().run_capture_stdout(self);
}
fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) {
@ -259,7 +259,7 @@ impl Config {
if self.build.contains("windows-msvc") {
eprintln!("Fallback to PowerShell");
for _ in 0..3 {
let powershell = command("PowerShell.exe").args([
let powershell = command("PowerShell.exe").allow_failure().args([
"/nologo",
"-Command",
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",

View file

@ -46,7 +46,7 @@ impl GitInfo {
let mut git_command = helpers::git(Some(dir));
git_command.arg("rev-parse");
let output = git_command.allow_failure().run_capture_stdout(exec_ctx);
let output = git_command.allow_failure().run_capture(exec_ctx);
if output.is_failure() {
return GitInfo::Absent;