Skip to content

Commit

Permalink
Use std::env::{split,join}_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Feb 29, 2024
1 parent df7a627 commit 54a26d9
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
use std::env;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};

fn setup_common_build_cmd() -> Command {
Expand Down Expand Up @@ -88,36 88,36 @@ impl AuxBuildInvocationBuilder {
}
}

fn path_sep(target: &str) -> char {
if target.contains("windows") { ';' } else { ':' }
}

fn run_common(bin_name: &str) -> (Command, Output) {
let target = std::env::var("TARGET").unwrap();
let target = env::var("TARGET").unwrap();

let bin_name =
if target.contains("windows") { format!("{}.exe", bin_name) } else { bin_name.to_owned() };

let mut bin_path = PathBuf::new();
bin_path.push(std::env::var("TMPDIR").unwrap());
bin_path.push(env::var("TMPDIR").unwrap());
bin_path.push(&bin_name);
let ld_lib_path_envvar = std::env::var("LD_LIB_PATH_ENVVAR").unwrap();
let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap();
let mut cmd = Command::new(bin_path);
cmd.env(&ld_lib_path_envvar, {
let mut target_rpath_env_path = String::new();
target_rpath_env_path.push_str(&std::env::var("TMPDIR").unwrap());
target_rpath_env_path.push(path_sep(&target));
target_rpath_env_path.push_str(&std::env::var("TARGET_RPATH_ENV").unwrap());
target_rpath_env_path.push(path_sep(&target));
target_rpath_env_path.push_str(&std::env::var(&ld_lib_path_envvar).unwrap());
target_rpath_env_path
let mut paths = vec![];
paths.push(PathBuf::from(env::var("TMPDIR").unwrap()));
for p in env::split_paths(&env::var("TARGET_RPATH_ENV").unwrap()) {
paths.push(p.to_path_buf());
}
for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) {
paths.push(p.to_path_buf());
}
env::join_paths(paths.iter()).unwrap()
});

if target.contains("windows") {
let mut path = std::env::var("PATH").unwrap_or(String::new());
path.push(path_sep(&target));
path.push_str(&std::env::var("TARGET_RPATH_DIR").unwrap());
cmd.env("PATH", &path);
let mut paths = vec![];
for p in env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) {
paths.push(p.to_path_buf());
}
paths.push(Path::new(&std::env::var("TARGET_RPATH_DIR").unwrap()).to_path_buf());
cmd.env("PATH", env::join_paths(paths.iter()).unwrap());
}

let output = cmd.output().unwrap();
Expand Down

0 comments on commit 54a26d9

Please sign in to comment.