run_make_support/util.rs
1use std::path::PathBuf;
2
3use crate::command::{Command, CompletedProcess};
4use crate::env::env_var;
5use crate::path_helpers::cwd;
6
7/// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the
8/// executed command, failure location, output status and stdout/stderr, and abort the process with
9/// exit code `1`.
10pub(crate) fn handle_failed_output(
11 cmd: &Command,
12 output: CompletedProcess,
13 caller_line_number: u32,
14) -> ! {
15 if output.status().success() {
16 eprintln!("command unexpectedly succeeded at line {caller_line_number}");
17 } else {
18 eprintln!("command failed at line {caller_line_number}");
19 }
20 eprintln!("{cmd:?}");
21 eprintln!("output status: `{}`", output.status());
22 eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8());
23 eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8());
24 if !cmd.get_context().is_empty() {
25 eprintln!("Context:\n{}", cmd.get_context());
26 }
27 std::process::exit(1)
28}
29
30/// Set the runtime library paths as needed for running the host compilers (rustc/rustdoc/etc).
31pub(crate) fn set_host_compiler_dylib_path(cmd: &mut Command) {
32 let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR");
33 cmd.env(&ld_lib_path_envvar, {
34 let mut paths = vec![];
35 paths.push(cwd());
36 paths.push(PathBuf::from(env_var("HOST_RUSTC_DYLIB_PATH")));
37 for p in std::env::split_paths(&env_var(&ld_lib_path_envvar)) {
38 paths.push(p.to_path_buf());
39 }
40 std::env::join_paths(paths.iter()).unwrap()
41 });
42}