diff options
| author | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2024-07-15 12:07:36 +0000 |
|---|---|---|
| committer | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2024-07-17 12:48:22 +0000 |
| commit | e956808c6c5117b85ebc0eb6b3d92f6e512a593c (patch) | |
| tree | 56843bffce673699b5169e5f1e2047bed32f3d43 | |
| parent | 88fd1df017d7652ffd82ad11cb9f63d8a660f95f (diff) | |
| download | rust-e956808c6c5117b85ebc0eb6b3d92f6e512a593c.tar.gz rust-e956808c6c5117b85ebc0eb6b3d92f6e512a593c.zip | |
run_make_support: move `handle_failed_output` into `util` module
| -rw-r--r-- | src/tools/run-make-support/src/command.rs | 4 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/lib.rs | 22 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/path_helpers.rs | 2 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/run.rs | 3 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/targets.rs | 3 | ||||
| -rw-r--r-- | src/tools/run-make-support/src/util.rs | 21 |
6 files changed, 31 insertions, 24 deletions
diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index 5017a4b88da..47376c401bb 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -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 diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 658b6cc3559..7c7b890f6ed 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -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"); diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs index 59e0cec0be4..a35c32cbe48 100644 --- a/src/tools/run-make-support/src/path_helpers.rs +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -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. /// diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs index 54730bb7de7..d47e009fe9f 100644 --- a/src/tools/run-make-support/src/run.rs +++ b/src/tools/run-make-support/src/run.rs @@ -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(); diff --git a/src/tools/run-make-support/src/targets.rs b/src/tools/run-make-support/src/targets.rs index 68b66e68448..42d4a45680d 100644 --- a/src/tools/run-make-support/src/targets.rs +++ b/src/tools/run-make-support/src/targets.rs @@ -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] diff --git a/src/tools/run-make-support/src/util.rs b/src/tools/run-make-support/src/util.rs new file mode 100644 index 00000000000..41fdaf55aad --- /dev/null +++ b/src/tools/run-make-support/src/util.rs @@ -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) +} |
