Skip to content

Commit

Permalink
Allow ignoring the failure of command execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Oct 26, 2023
1 parent b153a01 commit 5d7fca1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -1009,6 +1012,7 @@ impl Build {
BehaviorOnFailure::Exit => {
exit!(1);
}
BehaviorOnFailure::Ignore => {}
}
false
}
Expand Down
8 changes: 8 additions & 0 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 }
}
Expand Down

0 comments on commit 5d7fca1

Please sign in to comment.