about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2023-10-26 10:54:21 +0200
committerJakub Beránek <berykubik@gmail.com>2023-10-26 21:52:48 +0200
commit5d7fca15d3c7d991733abd0d187e49e403b0b200 (patch)
treedf9d108c21c8be5cce58c1bddab47ab364526d0f /src
parentb153a0182875b420bdecb19c81be0731e2e2f6b4 (diff)
downloadrust-5d7fca15d3c7d991733abd0d187e49e403b0b200.tar.gz
rust-5d7fca15d3c7d991733abd0d187e49e403b0b200.zip
Allow ignoring the failure of command execution
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/src/core/build_steps/test.rs2
-rw-r--r--src/bootstrap/src/core/build_steps/tool.rs3
-rw-r--r--src/bootstrap/src/lib.rs10
-rw-r--r--src/bootstrap/src/utils/exec.rs8
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 ee9effa468e..246d742a99f 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 7c35e2a0e9f..d5f759ea159 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 701c8df11a7..1c62d5c41e9 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 1b9e5cb174a..9c1c21cd958 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 }
     }