Skip to content

Commit

Permalink
auto merge of #17667 : wizeman/rust/fix-override-env, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 1, 2014
2 parents 00ebebb + 5f4c280 commit 49fcb27
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/libstd/io/process.rs
Expand Up @@ -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();
Expand Down

0 comments on commit 49fcb27

Please sign in to comment.