Skip to content

Commit 4586364

Browse files
committed
run_make_support: move handle_failed_output into util module
1 parent 04a9056 commit 4586364

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

src/tools/run-make-support/src/command.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::panic;
55
use std::path::Path;
66
use std::process::{Command as StdCommand, ExitStatus, Output, Stdio};
77

8-
use crate::{assert_contains, assert_equals, assert_not_contains, handle_failed_output};
8+
use crate::util::handle_failed_output;
9+
use crate::{assert_contains, assert_equals, assert_not_contains};
10+
911
use build_helper::drop_bomb::DropBomb;
1012

1113
/// This is a custom command wrapper that simplifies working with commands and makes it easier to

src/tools/run-make-support/src/lib.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
mod command;
77
mod macros;
8+
mod util;
89

910
pub mod ar;
1011
pub mod artifact_names;
@@ -19,7 +20,7 @@ pub mod run;
1920
pub mod scoped_run;
2021
pub mod targets;
2122

22-
use std::path::{Path, PathBuf};
23+
use std::path::PathBuf;
2324

2425
// Re-exports of third-party library crates.
2526
pub use bstr;
@@ -84,24 +85,7 @@ pub use assertion_helpers::{
8485
shallow_find_files,
8586
};
8687

87-
use command::{Command, CompletedProcess};
88-
89-
pub(crate) fn handle_failed_output(
90-
cmd: &Command,
91-
output: CompletedProcess,
92-
caller_line_number: u32,
93-
) -> ! {
94-
if output.status().success() {
95-
eprintln!("command unexpectedly succeeded at line {caller_line_number}");
96-
} else {
97-
eprintln!("command failed at line {caller_line_number}");
98-
}
99-
eprintln!("{cmd:?}");
100-
eprintln!("output status: `{}`", output.status());
101-
eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8());
102-
eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8());
103-
std::process::exit(1)
104-
}
88+
use command::Command;
10589

10690
/// Set the runtime library path as needed for running the host rustc/rustdoc/etc.
10791
pub fn set_host_rpath(cmd: &mut Command) {

src/tools/run-make-support/src/path_helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
55

66
use crate::command::Command;
77
use crate::env_checked::env_var;
8-
use crate::handle_failed_output;
8+
use crate::util::handle_failed_output;
99

1010
/// Return the current working directory.
1111
///

src/tools/run-make-support/src/run.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ use std::panic;
44
use std::path::{Path, PathBuf};
55

66
use crate::command::{Command, CompletedProcess};
7+
use crate::util::handle_failed_output;
78
use crate::{cwd, env_var, is_windows, set_host_rpath};
89

9-
use super::handle_failed_output;
10-
1110
#[track_caller]
1211
fn run_common(name: &str, args: Option<&[&str]>) -> Command {
1312
let mut bin_path = PathBuf::new();

src/tools/run-make-support/src/targets.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::panic;
22

33
use crate::command::Command;
4-
use crate::{env_var, handle_failed_output};
4+
use crate::env_var;
5+
use crate::util::handle_failed_output;
56

67
/// `TARGET`
78
#[must_use]
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::command::{Command, CompletedProcess};
2+
3+
/// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the
4+
/// executed command, failure location, output status and stdout/stderr, and abort the process with
5+
/// exit code `1`.
6+
pub(crate) fn handle_failed_output(
7+
cmd: &Command,
8+
output: CompletedProcess,
9+
caller_line_number: u32,
10+
) -> ! {
11+
if output.status().success() {
12+
eprintln!("command unexpectedly succeeded at line {caller_line_number}");
13+
} else {
14+
eprintln!("command failed at line {caller_line_number}");
15+
}
16+
eprintln!("{cmd:?}");
17+
eprintln!("output status: `{}`", output.status());
18+
eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8());
19+
eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8());
20+
std::process::exit(1)
21+
}

0 commit comments

Comments
 (0)