about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2024-06-07 11:31:45 +0200
committerJakub Beránek <berykubik@gmail.com>2024-06-07 12:20:47 +0200
commit4b0842f3cedc26ba841b6e8fb7314da2048c5ee2 (patch)
treef5f88d33c7c7c6aff6fac3db03c65c87ad75cac7
parentd86c9819087fbc64b7d0a638b2fd8584831bb661 (diff)
downloadrust-4b0842f3cedc26ba841b6e8fb7314da2048c5ee2.tar.gz
rust-4b0842f3cedc26ba841b6e8fb7314da2048c5ee2.zip
Small refactoring
-rw-r--r--src/tools/run-make-support/src/lib.rs5
-rw-r--r--src/tools/run-make-support/src/run.rs6
-rw-r--r--src/tools/run-make-support/src/rustc.rs5
3 files changed, 7 insertions, 9 deletions
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index d4b02a81a4f..79f732ecebb 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -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);
 
diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs
index 20fc29650f8..b607c583e32 100644
--- a/src/tools/run-make-support/src/run.rs
+++ b/src/tools/run-make-support/src/run.rs
@@ -2,19 +2,19 @@ use std::env;
 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());
         }
diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs
index bcdedb2722f..a64dd9d30cf 100644
--- a/src/tools/run-make-support/src/rustc.rs
+++ b/src/tools/run-make-support/src/rustc.rs
@@ -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
 }