rust/src/compiletest/procsrv.rs

77 lines
2.0 KiB
Rust
Raw Normal View History

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::prelude::*;
use core::comm;
use core::io;
use core::libc::c_int;
use core::os;
use core::run;
use core::str;
use core::task;
#[cfg(target_os = "win32")]
fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
2012-04-27 13:55:13 -05:00
let mut env = os::env();
// Make sure we include the aux directory in the path
2013-03-28 20:39:09 -05:00
assert!(prog.ends_with(~".exe"));
2013-04-03 13:54:49 -05:00
let aux_path = prog.slice(0u, prog.len() - 4u).to_owned() + ~".libaux";
2012-06-30 18:19:07 -05:00
env = do vec::map(env) |pair| {
2012-09-29 21:25:04 -05:00
let (k,v) = *pair;
2012-07-14 20:28:20 -05:00
if k == ~"PATH" { (~"PATH", v + ~";" + lib_path + ~";" + aux_path) }
else { (k,v) }
2012-01-04 23:14:53 -06:00
};
if str::ends_with(prog, "rustc.exe") {
env.push((~"RUST_THREADS", ~"1"));
}
2012-08-01 19:30:05 -05:00
return env;
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
fn target_env(_lib_path: &str, _prog: &str) -> ~[(~str,~str)] {
os::env()
}
pub struct Result {status: int, out: ~str, err: ~str}
pub fn run(lib_path: &str,
prog: &str,
args: &[~str],
env: ~[(~str, ~str)],
input: Option<~str>) -> Result {
let env = env + target_env(lib_path, prog);
let mut proc = run::Process::new(prog, args, run::ProcessOptions {
env: Some(env.slice(0, env.len())),
dir: None,
in_fd: None,
out_fd: None,
err_fd: None
});
for input.each |input| {
proc.input().write_str(*input);
}
let output = proc.finish_with_output();
Result {
status: output.status,
out: str::from_bytes(output.output),
err: str::from_bytes(output.error)
}
}