Implement `run_cmd` in terms of `run_tracked` · rust-lang/rust@5c4318d

@@ -1034,79 +1034,8 @@ impl Build {

1034103410351035

/// A centralized function for running commands that do not return output.

10361036

pub(crate) fn run_cmd<'a, C: Into<BootstrapCommand<'a>>>(&self, cmd: C) -> bool {

1037-

if self.config.dry_run() {

1038-

return true;

1039-

}

1040-10411037

let command = cmd.into();

1042-

self.verbose(|| println!("running: {command:?}"));

1043-1044-

let output_mode = command.output_mode.unwrap_or_else(|| match self.is_verbose() {

1045-

true => OutputMode::PrintAll,

1046-

false => OutputMode::PrintOutput,

1047-

});

1048-

let (output, print_error) = match output_mode {

1049-

mode @ (OutputMode::PrintAll | OutputMode::PrintOutput) => (

1050-

command.command.status().map(|status| Output {

1051-

status,

1052-

stdout: Vec::new(),

1053-

stderr: Vec::new(),

1054-

}),

1055-

matches!(mode, OutputMode::PrintAll),

1056-

),

1057-

OutputMode::PrintOnFailure => (command.command.output(), true),

1058-

};

1059-1060-

let output = match output {

1061-

Ok(output) => output,

1062-

Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", command, e)),

1063-

};

1064-

let result = if !output.status.success() {

1065-

if print_error {

1066-

println!(

1067-

"\n\nCommand did not execute successfully.\

1068-

\nExpected success, got: {}",

1069-

output.status,

1070-

);

1071-1072-

if !self.is_verbose() {

1073-

println!("Add `-v` to see more details.\n");

1074-

}

1075-1076-

self.verbose(|| {

1077-

println!(

1078-

"\nSTDOUT ----\n{}\n\

1079-

STDERR ----\n{}\n",

1080-

String::from_utf8_lossy(&output.stdout),

1081-

String::from_utf8_lossy(&output.stderr)

1082-

)

1083-

});

1084-

}

1085-

Err(())

1086-

} else {

1087-

Ok(())

1088-

};

1089-1090-

match result {

1091-

Ok(_) => true,

1092-

Err(_) => {

1093-

match command.failure_behavior {

1094-

BehaviorOnFailure::DelayFail => {

1095-

if self.fail_fast {

1096-

exit!(1);

1097-

}

1098-1099-

let mut failures = self.delayed_failures.borrow_mut();

1100-

failures.push(format!("{command:?}"));

1101-

}

1102-

BehaviorOnFailure::Exit => {

1103-

exit!(1);

1104-

}

1105-

BehaviorOnFailure::Ignore => {}

1106-

}

1107-

false

1108-

}

1109-

}

1038+

self.run_tracked(command).is_success()

11101039

}

1111104011121041

/// Check if verbosity is greater than the `level`