forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#116581 - Kobzol:bootstrap-cmd-run, r=onur-ozkan
Centralize command running in boostrap (part one) This PR tries to consolidate the various `run, try_run, run_quiet, run_quiet_delaying_failure, run_delaying_failure` etc. methods on `Builder`. This PR only touches command execution which doesn't produce output that would be later read by bootstrap, and it also only refactors spawning of commands that happens after a builder is created (commands executed during download & git submodule checkout are left as-is, for now). The `run_cmd` method is quite meaty, but I expect that it will be changing rapidly soon, so I considered it easy to kept everything in a single method, and only after things settle down a bit, then maybe again split it up a bit. I still kept the original shortcut methods like `run_quiet_delaying_failure`, but they now only delegate to `run_cmd`. I tried to keep the original behavior (or as close to it as possible) for all the various commands, but it is a giant mess, so there may be some deviations. Notably, `cmd.output()` is now always called, instead of just `status()`, which was called previously in some situations. Apart from the refactored methods, there is also `Config::try_run`, `check_run`, methods that run commands that produce output, oh my… that's left for follow-up PRs :) The driving goal of this (and following) refactors is to centralize command execution in bootstrap on a single place, to make command mocking feasible. r? `@onur-ozkan`
- Loading branch information
Showing
6 changed files
with
158 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::process::Command; | ||
|
||
/// What should be done when the command fails. | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum BehaviorOnFailure { | ||
/// Immediately stop bootstrap. | ||
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. | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum OutputMode { | ||
/// Print both the output (by inheriting stdout/stderr) and also the command itself, if it | ||
/// fails. | ||
PrintAll, | ||
/// Print the output (by inheriting stdout/stderr). | ||
PrintOutput, | ||
/// Suppress the output if the command succeeds, otherwise print the output. | ||
SuppressOnSuccess, | ||
} | ||
|
||
/// Wrapper around `std::process::Command`. | ||
#[derive(Debug)] | ||
pub struct BootstrapCommand<'a> { | ||
pub command: &'a mut Command, | ||
pub failure_behavior: BehaviorOnFailure, | ||
pub output_mode: OutputMode, | ||
} | ||
|
||
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 } | ||
} | ||
} | ||
|
||
impl<'a> From<&'a mut Command> for BootstrapCommand<'a> { | ||
fn from(command: &'a mut Command) -> Self { | ||
Self { | ||
command, | ||
failure_behavior: BehaviorOnFailure::Exit, | ||
output_mode: OutputMode::SuppressOnSuccess, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters