Skip to content

Commit

Permalink
run_make_support: make set_host_rpath private and move into util
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Jul 15, 2024
1 parent 4586364 commit 4769fc9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/tools/run-make-support/src/external_deps/llvm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::{Path, PathBuf};

use crate::{env_var, Command};
use crate::command::Command;
use crate::env_checked::env_var;

/// Construct a new `llvm-readobj` invocation with the `GNU` output style.
/// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`.
Expand Down
6 changes: 4 additions & 2 deletions src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use command::Command;
use std::ffi::{OsStr, OsString};
use std::path::Path;

use crate::{command, cwd, env_var, set_host_rpath};
use crate::command::Command;
use crate::env_checked::env_var;
use crate::path_helpers::cwd;
use crate::util::set_host_rpath;

/// Construct a new `rustc` invocation. This will automatically set the library
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
Expand Down
3 changes: 2 additions & 1 deletion src/tools/run-make-support/src/external_deps/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::ffi::OsStr;
use std::path::Path;

use crate::command::Command;
use crate::{env_var, env_var_os, set_host_rpath};
use crate::env_checked::{env_var, env_var_os};
use crate::util::set_host_rpath;

/// Construct a plain `rustdoc` invocation with no flags set.
#[track_caller]
Expand Down
18 changes: 0 additions & 18 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub mod run;
pub mod scoped_run;
pub mod targets;

use std::path::PathBuf;

// Re-exports of third-party library crates.
pub use bstr;
pub use gimli;
Expand Down Expand Up @@ -84,19 +82,3 @@ pub use assertion_helpers::{
has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains,
shallow_find_files,
};

use command::Command;

/// 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");
cmd.env(&ld_lib_path_envvar, {
let mut paths = vec![];
paths.push(cwd());
paths.push(PathBuf::from(env_var("HOST_RPATH_DIR")));
for p in std::env::split_paths(&env_var(&ld_lib_path_envvar)) {
paths.push(p.to_path_buf());
}
std::env::join_paths(paths.iter()).unwrap()
});
}
4 changes: 2 additions & 2 deletions src/tools/run-make-support/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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 crate::util::{handle_failed_output, set_host_rpath};
use crate::{cwd, env_var, is_windows};

#[track_caller]
fn run_common(name: &str, args: Option<&[&str]>) -> Command {
Expand Down
18 changes: 18 additions & 0 deletions src/tools/run-make-support/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::path::PathBuf;

use crate::command::{Command, CompletedProcess};
use crate::env_checked::env_var;
use crate::path_helpers::cwd;

/// 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
Expand All @@ -19,3 +23,17 @@ pub(crate) fn handle_failed_output(
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(crate) fn set_host_rpath(cmd: &mut Command) {
let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR");
cmd.env(&ld_lib_path_envvar, {
let mut paths = vec![];
paths.push(cwd());
paths.push(PathBuf::from(env_var("HOST_RPATH_DIR")));
for p in std::env::split_paths(&env_var(&ld_lib_path_envvar)) {
paths.push(p.to_path_buf());
}
std::env::join_paths(paths.iter()).unwrap()
});
}

0 comments on commit 4769fc9

Please sign in to comment.