Small refactoring

This commit is contained in:
Jakub Beránek 2024-06-07 11:31:45 +02:00
parent d86c981908
commit 4b0842f3ce
No known key found for this signature in database
GPG Key ID: 909CD0D26483516B
3 changed files with 7 additions and 9 deletions

View File

@ -227,7 +227,7 @@ 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(env::current_dir().unwrap());
paths.push(cwd());
paths.push(PathBuf::from(env_var("HOST_RPATH_DIR")));
for p in env::split_paths(&env_var(&ld_lib_path_envvar)) {
paths.push(p.to_path_buf());
@ -325,9 +325,8 @@ pub fn assert_not_contains(haystack: &str, needle: &str) {
/// 4) Calls `callback`
/// 5) Switches working directory back to the original one
/// 6) Removes `tmpdir`
/// Switch current working directory to a temporary directory
pub fn run_in_tmpdir<F: FnOnce()>(callback: F) {
let original_dir = env::current_dir().unwrap();
let original_dir = cwd();
let tmpdir = original_dir.join("../temporary-directory");
copy_dir_all(".", &tmpdir);

View File

@ -2,19 +2,19 @@
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use crate::{env_var, is_windows};
use crate::{cwd, env_var, is_windows};
use super::handle_failed_output;
fn run_common(name: &str) -> (Command, Output) {
let mut bin_path = PathBuf::new();
bin_path.push(env::current_dir().unwrap());
bin_path.push(cwd());
bin_path.push(name);
let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR");
let mut cmd = Command::new(bin_path);
cmd.env(&ld_lib_path_envvar, {
let mut paths = vec![];
paths.push(env::current_dir().unwrap());
paths.push(cwd());
for p in env::split_paths(&env_var("TARGET_RPATH_ENV")) {
paths.push(p.to_path_buf());
}

View File

@ -1,10 +1,9 @@
use std::env;
use std::ffi::{OsStr, OsString};
use std::io::Write;
use std::path::Path;
use std::process::{Command, Output, Stdio};
use crate::{env_var, handle_failed_output, set_host_rpath};
use crate::{cwd, env_var, handle_failed_output, set_host_rpath};
/// Construct a new `rustc` invocation.
pub fn rustc() -> Rustc {
@ -29,7 +28,7 @@ fn setup_common() -> Command {
let rustc = env_var("RUSTC");
let mut cmd = Command::new(rustc);
set_host_rpath(&mut cmd);
cmd.arg("-L").arg(env::current_dir().unwrap());
cmd.arg("-L").arg(cwd());
cmd
}