Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jul 3, 2024
1 parent 70b6e04 commit b90129d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
27 changes: 13 additions & 14 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ pub enum OutputMode {
/// If you want to allow failures, use [allow_failure].
/// If you want to delay failures until the end of bootstrap, use [delay_failure].
///
/// By default, the command will print its stdout/stderr to stdout/stderr of bootstrap
/// ([OutputMode::Print]).
/// By default, the command will print its stdout/stderr to stdout/stderr of bootstrap ([OutputMode::Print]).
/// If you want to handle the output programmatically, use [BootstrapCommand::capture].
///
/// Bootstrap will print a debug log to stdout if the command fails and failure is not allowed.
Expand Down Expand Up @@ -144,8 +143,8 @@ impl From<Command> for BootstrapCommand {
}
}

/// Represents the outcome of starting a command.
enum CommandOutcome {
/// Represents the current status of `BootstrapCommand`.
enum CommandStatus {
/// The command has started and finished with some status.
Finished(ExitStatus),
/// It was not even possible to start the command.
Expand All @@ -155,20 +154,20 @@ enum CommandOutcome {
/// Represents the output of an executed process.
#[allow(unused)]
pub struct CommandOutput {
outcome: CommandOutcome,
status: CommandStatus,
stdout: Vec<u8>,
stderr: Vec<u8>,
}

impl CommandOutput {
pub fn did_not_start() -> Self {
Self { outcome: CommandOutcome::DidNotStart, stdout: vec![], stderr: vec![] }
Self { status: CommandStatus::DidNotStart, stdout: vec![], stderr: vec![] }
}

pub fn is_success(&self) -> bool {
match self.outcome {
CommandOutcome::Finished(status) => status.success(),
CommandOutcome::DidNotStart => false,
match self.status {
CommandStatus::Finished(status) => status.success(),
CommandStatus::DidNotStart => false,
}
}

Expand All @@ -177,9 +176,9 @@ impl CommandOutput {
}

pub fn status(&self) -> Option<ExitStatus> {
match self.outcome {
CommandOutcome::Finished(status) => Some(status),
CommandOutcome::DidNotStart => None,
match self.status {
CommandStatus::Finished(status) => Some(status),
CommandStatus::DidNotStart => None,
}
}

Expand All @@ -199,7 +198,7 @@ impl CommandOutput {
impl Default for CommandOutput {
fn default() -> Self {
Self {
outcome: CommandOutcome::Finished(ExitStatus::default()),
status: CommandStatus::Finished(ExitStatus::default()),
stdout: vec![],
stderr: vec![],
}
Expand All @@ -209,7 +208,7 @@ impl Default for CommandOutput {
impl From<Output> for CommandOutput {
fn from(output: Output) -> Self {
Self {
outcome: CommandOutcome::Finished(output.status),
status: CommandStatus::Finished(output.status),
stdout: output.stdout,
stderr: output.stderr,
}
Expand Down
9 changes: 5 additions & 4 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,13 @@ pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
format!("--check-cfg=cfg({name}{next})")
}

/// Prepares `Command` that runs git inside the source directory if given.
/// Prepares `BootstrapCommand` that runs git inside the source directory if given.
///
/// Whenever a git invocation is needed, this function should be preferred over
/// manually building a git `Command`. This approach allows us to manage bootstrap-specific
/// needs/hacks from a single source, rather than applying them on next to every `Command::new("git")`,
/// which is painful to ensure that the required change is applied on each one of them correctly.
/// manually building a git `BootstrapCommand`. This approach allows us to manage
/// bootstrap-specific needs/hacks from a single source, rather than applying them on next to every
/// `BootstrapCommand::new("git")`, which is painful to ensure that the required change is applied
/// on each one of them correctly.
pub fn git(source_dir: Option<&Path>) -> BootstrapCommand {
let mut git = BootstrapCommand::new("git");

Expand Down

0 comments on commit b90129d

Please sign in to comment.