]> git.lizzy.rs Git - rust.git/commitdiff
Preserve existing LD_LIBRARY_PATH in remote-test-server
authorAmanieu d'Antras <amanieu.dantras@huawei.com>
Wed, 20 Jan 2021 18:37:14 +0000 (18:37 +0000)
committerAmanieu d'Antras <amanieu@gmail.com>
Wed, 27 Jan 2021 23:08:15 +0000 (23:08 +0000)
src/tools/remote-test-server/src/main.rs

index d92758eb7474cda8ec9f3db0cf69f78cfe233235..cd9d530096496b4adb7036755c1477e02599bbac 100644 (file)
@@ -218,25 +218,19 @@ fn handle_run(socket: TcpStream, work: &Path, tmp: &Path, lock: &Mutex<()>, conf
     cmd.args(args);
     cmd.envs(env);
 
+    // On windows, libraries are just searched in the executable directory,
+    // system directories, PWD, and PATH, in that order. PATH is the only one
+    // we can change for this.
+    let library_path = if cfg!(windows) { "PATH" } else { "LD_LIBRARY_PATH" };
+
     // Support libraries were uploaded to `work` earlier, so make sure that's
     // in `LD_LIBRARY_PATH`. Also include our own current dir which may have
     // had some libs uploaded.
-    if cfg!(windows) {
-        // On windows, libraries are just searched in the executable directory,
-        // system directories, PWD, and PATH, in that order. PATH is the only one
-        // we can change for this.
-        cmd.env(
-            "PATH",
-            env::join_paths(
-                std::iter::once(work.to_owned())
-                    .chain(std::iter::once(path.clone()))
-                    .chain(env::split_paths(&env::var_os("PATH").unwrap())),
-            )
-            .unwrap(),
-        );
-    } else {
-        cmd.env("LD_LIBRARY_PATH", format!("{}:{}", work.display(), path.display()));
+    let mut paths = vec![work.to_owned(), path.clone()];
+    if let Some(library_path) = env::var_os(library_path) {
+        paths.extend(env::split_paths(&library_path));
     }
+    cmd.env(library_path, env::join_paths(paths).unwrap());
 
     // Some tests assume RUST_TEST_TMPDIR exists
     cmd.env("RUST_TEST_TMPDIR", tmp.to_owned());