about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorRicardo M. Correia <rcorreia@wizy.org>2014-09-30 15:57:06 +0200
committerRicardo M. Correia <rcorreia@wizy.org>2014-10-01 03:35:35 +0200
commit5f4c2800fcf0556b351857867e5b527af77149ee (patch)
treefae6d90787c126fc37289f4adce32e0ebb75048d /src/libstd
parent88d1a22f76a774b2df3c904ceb54c86e58a859c3 (diff)
downloadrust-5f4c2800fcf0556b351857867e5b527af77149ee.tar.gz
rust-5f4c2800fcf0556b351857867e5b527af77149ee.zip
libstd: Pass-through PATH in test_override_env
In some build environments (such as chrooted Nix builds), `env` can only
be found in the explicitly-provided PATH, not in default places such as
/bin or /usr/bin. So we need to pass-through PATH when spawning the
`env` sub-process.

Fixes #17617
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/process.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs
index 83890d2b127..ec2fb2382c3 100644
--- a/src/libstd/io/process.rs
+++ b/src/libstd/io/process.rs
@@ -956,7 +956,22 @@ mod tests {
     })
 
     iotest!(fn test_override_env() {
-        let new_env = vec![("RUN_TEST_NEW_ENV", "123")];
+        use os;
+        let mut new_env = vec![("RUN_TEST_NEW_ENV", "123")];
+
+        // In some build environments (such as chrooted Nix builds), `env` can
+        // only be found in the explicitly-provided PATH env variable, not in
+        // default places such as /bin or /usr/bin. So we need to pass through
+        // PATH to our sub-process.
+        let path_val: String;
+        match os::getenv("PATH") {
+            None => {}
+            Some(val) => {
+                path_val = val;
+                new_env.push(("PATH", path_val.as_slice()))
+            }
+        }
+
         let prog = env_cmd().env_set_all(new_env.as_slice()).spawn().unwrap();
         let result = prog.wait_with_output().unwrap();
         let output = String::from_utf8_lossy(result.output.as_slice()).into_string();