Skip to content

Commit 0e18a9c

Browse files
committed
use embedded implementation instead of istty crate
1 parent 7b0a7fd commit 0e18a9c

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/librustc_driver/lib.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ extern crate log;
5656
extern crate syntax;
5757
extern crate syntax_ext;
5858
extern crate syntax_pos;
59-
extern crate isatty;
6059

6160
use driver::CompileController;
6261
use pretty::{PpMode, UserIdentifiedItem};
@@ -101,8 +100,6 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures};
101100
use syntax::parse::{self, PResult};
102101
use syntax_pos::{DUMMY_SP, MultiSpan};
103102

104-
use isatty::stdout_isatty;
105-
106103
#[cfg(test)]
107104
pub mod test;
108105

@@ -347,6 +344,35 @@ pub trait CompilerCalls<'a> {
347344
#[derive(Copy, Clone)]
348345
pub struct RustcDefaultCalls;
349346

347+
/**
348+
* TODO remove these and use winapi 0.3 instead
349+
*
350+
* These are duplicated in
351+
* - bootstrap/compile.rs#L478
352+
* - librustc_errors/emitter.rs#L1253
353+
*/
354+
#[cfg(unix)]
355+
fn stdout_isatty() -> bool {
356+
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
357+
}
358+
#[cfg(windows)]
359+
fn stdout_isatty() -> bool {
360+
type DWORD = u32;
361+
type BOOL = i32;
362+
type HANDLE = *mut u8;
363+
type LPDWORD = *mut u32;
364+
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
365+
extern "system" {
366+
fn GetStdHandle(which: DWORD) -> HANDLE;
367+
fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL;
368+
}
369+
unsafe {
370+
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
371+
let mut out = 0;
372+
GetConsoleMode(handle, &mut out) != 0
373+
}
374+
}
375+
350376
fn handle_explain(code: &str,
351377
descriptions: &errors::registry::Registry,
352378
output: ErrorOutputType) {

0 commit comments

Comments
 (0)