run_make_support: move handle_failed_output
into util
module
This commit is contained in:
parent
88fd1df017
commit
e956808c6c
6 changed files with 31 additions and 24 deletions
|
@ -5,7 +5,9 @@ use std::panic;
|
|||
use std::path::Path;
|
||||
use std::process::{Command as StdCommand, ExitStatus, Output, Stdio};
|
||||
|
||||
use crate::{assert_contains, assert_equals, assert_not_contains, handle_failed_output};
|
||||
use crate::util::handle_failed_output;
|
||||
use crate::{assert_contains, assert_equals, assert_not_contains};
|
||||
|
||||
use build_helper::drop_bomb::DropBomb;
|
||||
|
||||
/// This is a custom command wrapper that simplifies working with commands and makes it easier to
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
mod command;
|
||||
mod macros;
|
||||
mod util;
|
||||
|
||||
pub mod ar;
|
||||
pub mod artifact_names;
|
||||
|
@ -19,7 +20,7 @@ pub mod run;
|
|||
pub mod scoped_run;
|
||||
pub mod targets;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
// Re-exports of third-party library crates.
|
||||
pub use bstr;
|
||||
|
@ -84,7 +85,7 @@ pub use assertion_helpers::{
|
|||
shallow_find_files,
|
||||
};
|
||||
|
||||
use command::{Command, CompletedProcess};
|
||||
use command::Command;
|
||||
|
||||
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
|
||||
#[track_caller]
|
||||
|
@ -106,23 +107,6 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
|
|||
path(lib_path)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_failed_output(
|
||||
cmd: &Command,
|
||||
output: CompletedProcess,
|
||||
caller_line_number: u32,
|
||||
) -> ! {
|
||||
if output.status().success() {
|
||||
eprintln!("command unexpectedly succeeded at line {caller_line_number}");
|
||||
} else {
|
||||
eprintln!("command failed at line {caller_line_number}");
|
||||
}
|
||||
eprintln!("{cmd:?}");
|
||||
eprintln!("output status: `{}`", output.status());
|
||||
eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8());
|
||||
eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8());
|
||||
std::process::exit(1)
|
||||
}
|
||||
|
||||
/// Set the runtime library path as needed for running the host rustc/rustdoc/etc.
|
||||
pub fn set_host_rpath(cmd: &mut Command) {
|
||||
let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR");
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use crate::command::Command;
|
||||
use crate::env_checked::env_var;
|
||||
use crate::handle_failed_output;
|
||||
use crate::util::handle_failed_output;
|
||||
|
||||
/// Return the current working directory.
|
||||
///
|
||||
|
|
|
@ -4,10 +4,9 @@ use std::panic;
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::command::{Command, CompletedProcess};
|
||||
use crate::util::handle_failed_output;
|
||||
use crate::{cwd, env_var, is_windows, set_host_rpath};
|
||||
|
||||
use super::handle_failed_output;
|
||||
|
||||
#[track_caller]
|
||||
fn run_common(name: &str, args: Option<&[&str]>) -> Command {
|
||||
let mut bin_path = PathBuf::new();
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use std::panic;
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::{env_var, handle_failed_output};
|
||||
use crate::env_var;
|
||||
use crate::util::handle_failed_output;
|
||||
|
||||
/// `TARGET`
|
||||
#[must_use]
|
||||
|
|
21
src/tools/run-make-support/src/util.rs
Normal file
21
src/tools/run-make-support/src/util.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use crate::command::{Command, CompletedProcess};
|
||||
|
||||
/// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the
|
||||
/// executed command, failure location, output status and stdout/stderr, and abort the process with
|
||||
/// exit code `1`.
|
||||
pub(crate) fn handle_failed_output(
|
||||
cmd: &Command,
|
||||
output: CompletedProcess,
|
||||
caller_line_number: u32,
|
||||
) -> ! {
|
||||
if output.status().success() {
|
||||
eprintln!("command unexpectedly succeeded at line {caller_line_number}");
|
||||
} else {
|
||||
eprintln!("command failed at line {caller_line_number}");
|
||||
}
|
||||
eprintln!("{cmd:?}");
|
||||
eprintln!("output status: `{}`", output.status());
|
||||
eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8());
|
||||
eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8());
|
||||
std::process::exit(1)
|
||||
}
|
Loading…
Add table
Reference in a new issue