about summary refs log tree commit diff
path: root/src/compiletest
diff options
context:
space:
mode:
authorgareth <gareth@gareth-N56VM.(none)>2013-05-12 13:58:00 +0100
committergareth <gareth@gareth-N56VM.(none)>2013-05-27 13:50:33 +0100
commit76c31217bee0f80b096b33d8a1b499f491d92c9f (patch)
tree7acc05357fd53b79704b908c3438c83e86b01341 /src/compiletest
parentd577eafff3fed544e616373c06c987ed0471dfc4 (diff)
downloadrust-76c31217bee0f80b096b33d8a1b499f491d92c9f.tar.gz
rust-76c31217bee0f80b096b33d8a1b499f491d92c9f.zip
Refactor core::run in order to address many of the issues
mentioned in #2625.

This change makes the module more oriented around
Process values instead of having to deal with process ids
directly.

Apart from issues mentioned in #2625, other changes include:
- Changing the naming to be more consistent - Process/process
  is now used instead of a mixture of Program/program and
  Process/process.
- More docs/tests.

Some io/scheduler related issues remain (mentioned in #2625).
Diffstat (limited to 'src/compiletest')
-rw-r--r--src/compiletest/procsrv.rs85
1 files changed, 16 insertions, 69 deletions
diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs
index 2a4cd08c124..a059f97daab 100644
--- a/src/compiletest/procsrv.rs
+++ b/src/compiletest/procsrv.rs
@@ -10,8 +10,6 @@
 
 use core::prelude::*;
 
-use core::libc::c_int;
-use core::run::spawn_process;
 use core::run;
 
 #[cfg(target_os = "win32")]
@@ -38,86 +36,35 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
 #[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}
 
-// FIXME (#2659): This code is duplicated in core::run::program_output
 pub fn run(lib_path: &str,
            prog: &str,
            args: &[~str],
            env: ~[(~str, ~str)],
            input: Option<~str>) -> Result {
-    let pipe_in = os::pipe();
-    let pipe_out = os::pipe();
-    let pipe_err = os::pipe();
-    let pid = spawn_process(prog, args,
-                            &Some(env + target_env(lib_path, prog)),
-                            &None, pipe_in.in, pipe_out.out, pipe_err.out);
-
-    os::close(pipe_in.in);
-    os::close(pipe_out.out);
-    os::close(pipe_err.out);
-    if pid == -1i32 {
-        os::close(pipe_in.out);
-        os::close(pipe_out.in);
-        os::close(pipe_err.in);
-        fail!();
-    }
 
+    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
+    });
 
-    writeclose(pipe_in.out, input);
-    let p = comm::PortSet::new();
-    let ch = p.chan();
-    do task::spawn_sched(task::SingleThreaded) || {
-        let errput = readclose(pipe_err.in);
-        ch.send((2, errput));
+    for input.each |input| {
+        proc.input().write_str(*input);
     }
-    let ch = p.chan();
-    do task::spawn_sched(task::SingleThreaded) || {
-        let output = readclose(pipe_out.in);
-        ch.send((1, output));
-    }
-    let status = run::waitpid(pid);
-    let mut errs = ~"";
-    let mut outs = ~"";
-    let mut count = 2;
-    while count > 0 {
-        match p.recv() {
-          (1, s) => {
-            outs = s;
-          }
-          (2, s) => {
-            errs = s;
-          }
-          _ => { fail!() }
-        };
-        count -= 1;
-    };
-    return Result {status: status, out: outs, err: errs};
-}
+    let output = proc.finish_with_output();
 
-fn writeclose(fd: c_int, s: Option<~str>) {
-    if s.is_some() {
-        let writer = io::fd_writer(fd, false);
-        writer.write_str(s.get());
+    Result {
+        status: output.status,
+        out: str::from_bytes(output.output),
+        err: str::from_bytes(output.error)
     }
-
-    os::close(fd);
 }
 
-fn readclose(fd: c_int) -> ~str {
-    unsafe {
-        // Copied from run::program_output
-        let file = os::fdopen(fd);
-        let reader = io::FILE_reader(file, false);
-        let mut buf = ~"";
-        while !reader.eof() {
-            let bytes = reader.read_bytes(4096u);
-            str::push_str(&mut buf, str::from_bytes(bytes));
-        }
-        os::fclose(file);
-        return buf;
-    }
-}