Skip to content

Commit 49fcb27

Browse files
committed
auto merge of #17667 : wizeman/rust/fix-override-env, r=alexcrichton
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
2 parents 00ebebb + 5f4c280 commit 49fcb27

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/libstd/io/process.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,22 @@ mod tests {
956956
})
957957

958958
iotest!(fn test_override_env() {
959-
let new_env = vec![("RUN_TEST_NEW_ENV", "123")];
959+
use os;
960+
let mut new_env = vec![("RUN_TEST_NEW_ENV", "123")];
961+
962+
// In some build environments (such as chrooted Nix builds), `env` can
963+
// only be found in the explicitly-provided PATH env variable, not in
964+
// default places such as /bin or /usr/bin. So we need to pass through
965+
// PATH to our sub-process.
966+
let path_val: String;
967+
match os::getenv("PATH") {
968+
None => {}
969+
Some(val) => {
970+
path_val = val;
971+
new_env.push(("PATH", path_val.as_slice()))
972+
}
973+
}
974+
960975
let prog = env_cmd().env_set_all(new_env.as_slice()).spawn().unwrap();
961976
let result = prog.wait_with_output().unwrap();
962977
let output = String::from_utf8_lossy(result.output.as_slice()).into_string();

0 commit comments

Comments
 (0)