From 5d7fca15d3c7d991733abd0d187e49e403b0b200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Thu, 26 Oct 2023 10:54:21 +0200 Subject: [PATCH] Allow ignoring the failure of command execution --- src/bootstrap/src/core/build_steps/test.rs | 2 +- src/bootstrap/src/core/build_steps/tool.rs | 3 ++- src/bootstrap/src/lib.rs | 10 +++++++--- src/bootstrap/src/utils/exec.rs | 8 ++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index ee9effa468e1b..246d742a99faa 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -810,7 +810,7 @@ impl Step for Clippy { let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host); // Clippy reports errors if it blessed the outputs - if builder.run_cmd(&mut cargo) { + if builder.run_cmd(BootstrapCommand::from(&mut cargo).allow_failure()) { // The tests succeeded; nothing to do. return; } diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 7c35e2a0e9f95..d5f759ea159aa 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -8,6 +8,7 @@ use crate::core::build_steps::toolstate::ToolState; use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step}; use crate::core::config::TargetSelection; use crate::utils::channel::GitInfo; +use crate::utils::exec::BootstrapCommand; use crate::utils::helpers::{add_dylib_path, exe, t}; use crate::Compiler; use crate::Mode; @@ -109,7 +110,7 @@ impl Step for ToolBuild { let mut cargo = Command::from(cargo); // we check this in `is_optional_tool` in a second - let is_expected = builder.run_cmd(&mut cargo); + let is_expected = builder.run_cmd(BootstrapCommand::from(&mut cargo).allow_failure()); builder.save_toolstate( tool, diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 701c8df11a723..1c62d5c41e926 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -581,9 +581,12 @@ impl Build { // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error). // diff-index reports the modifications through the exit status let has_local_modifications = !self.run_cmd( - Command::new("git") - .args(&["diff-index", "--quiet", "HEAD"]) - .current_dir(&absolute_path), + BootstrapCommand::from( + Command::new("git") + .args(&["diff-index", "--quiet", "HEAD"]) + .current_dir(&absolute_path), + ) + .allow_failure(), ); if has_local_modifications { self.run(Command::new("git").args(&["stash", "push"]).current_dir(&absolute_path)); @@ -1009,6 +1012,7 @@ impl Build { BehaviorOnFailure::Exit => { exit!(1); } + BehaviorOnFailure::Ignore => {} } false } diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 1b9e5cb174a0c..9c1c21cd95894 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -7,6 +7,8 @@ pub enum BehaviorOnFailure { Exit, /// Delay failure until the end of bootstrap invocation. DelayFail, + /// Ignore the failure, the command can fail in an expected way. + Ignore, } /// How should the output of the command be handled. @@ -33,9 +35,15 @@ impl<'a> BootstrapCommand<'a> { pub fn delay_failure(self) -> Self { Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self } } + pub fn fail_fast(self) -> Self { Self { failure_behavior: BehaviorOnFailure::Exit, ..self } } + + pub fn allow_failure(self) -> Self { + Self { failure_behavior: BehaviorOnFailure::Ignore, ..self } + } + pub fn output_mode(self, output_mode: OutputMode) -> Self { Self { output_mode, ..self } }