Skip to content

Commit

Permalink
support telemetry with lots of output
Browse files Browse the repository at this point in the history
  • Loading branch information
TimNN committed Aug 10, 2016
1 parent b31770d commit 5752195
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ term = "0.4.4"
itertools = "0.4.1"
time = "0.1.34"
tempdir = "0.3.4"
tempfile = "2.1.4"
libc = "0.2.0"
rand = "0.3.11"
scopeguard = "0.1.2"
Expand Down
22 changes: 20 additions & 2 deletions src/rustup/command.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::env;
use std::ffi::OsStr;
use std::fs::File;
use std::io::{self, Write, BufRead, BufReader};
use std::path::PathBuf;
use std::process::{self, Command, Stdio};
use std::time::Instant;
use regex::Regex;
use tempfile::tempfile;

use Cfg;
use errors::*;
Expand All @@ -29,6 +31,18 @@ pub fn run_command_for_dir<S: AsRef<OsStr>>(cmd: Command,
}

fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) -> Result<()> {
#[cfg(unix)]
fn file_as_stdio(file: &File) -> Stdio {
use std::os::unix::io::{AsRawFd, FromRawFd};
unsafe { Stdio::from_raw_fd(file.as_raw_fd()) }
}

#[cfg(windows)]
fn file_as_stdio(file: &File) -> Stdio {
use std::os::windows::io::{AsRawHandle, FromRawHandle};
unsafe { Stdio::from_raw_handle(file.as_raw_handle()) }
}

let now = Instant::now();

cmd.args(&args[1..]);
Expand All @@ -44,15 +58,17 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) ->
cmd.arg("always");
}

let cmd_err_file = tempfile().unwrap();
let cmd_err_stdio = file_as_stdio(&cmd_err_file);

// FIXME rust-lang/rust#32254. It's not clear to me
// when and why this is needed.
let mut cmd = cmd.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::piped())
.stderr(cmd_err_stdio)
.spawn()
.unwrap();

let mut buffered_stderr = BufReader::new(cmd.stderr.take().unwrap());
let status = cmd.wait();

let duration = now.elapsed();
Expand All @@ -75,6 +91,8 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) ->
let stderr = io::stderr();
let mut handle = stderr.lock();

let mut buffered_stderr = BufReader::new(cmd_err_file);

while buffered_stderr.read_line(&mut buffer).unwrap() > 0 {
let b = buffer.to_owned();
buffer.clear();
Expand Down
1 change: 1 addition & 0 deletions src/rustup/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern crate url;
extern crate regex;
extern crate itertools;
extern crate rustc_serialize;
extern crate tempfile;
extern crate time;
extern crate toml;
#[cfg(unix)]
Expand Down

0 comments on commit 5752195

Please sign in to comment.