Rollup merge of #80897 - camelid:atty, r=jyn514
driver: Use `atty` instead of rolling our own Fixes #80888. Rationale: - `atty` is widely used in the Rust ecosystem - We already use it (in `rustc_errors` and other places) - We shouldn't be rolling our own TTY detector when there's a widely-used, well-tested package that we can use
This commit is contained in:
commit
d682a6834d
3 changed files with 4 additions and 33 deletions
|
@ -3652,6 +3652,7 @@ dependencies = [
|
||||||
name = "rustc_driver"
|
name = "rustc_driver"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"atty",
|
||||||
"libc",
|
"libc",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_ast_pretty",
|
"rustc_ast_pretty",
|
||||||
|
|
|
@ -9,6 +9,7 @@ crate-type = ["dylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
atty = "0.2"
|
||||||
tracing = { version = "0.1.18" }
|
tracing = { version = "0.1.18" }
|
||||||
tracing-subscriber = { version = "0.2.13", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
|
tracing-subscriber = { version = "0.2.13", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
|
||||||
tracing-tree = "0.1.6"
|
tracing-tree = "0.1.6"
|
||||||
|
|
|
@ -546,43 +546,12 @@ impl Compilation {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct RustcDefaultCalls;
|
pub struct RustcDefaultCalls;
|
||||||
|
|
||||||
// FIXME remove these and use winapi 0.3 instead
|
|
||||||
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs
|
|
||||||
#[cfg(unix)]
|
|
||||||
fn stdout_isatty() -> bool {
|
fn stdout_isatty() -> bool {
|
||||||
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
|
atty::is(atty::Stream::Stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn stdout_isatty() -> bool {
|
|
||||||
use winapi::um::consoleapi::GetConsoleMode;
|
|
||||||
use winapi::um::processenv::GetStdHandle;
|
|
||||||
use winapi::um::winbase::STD_OUTPUT_HANDLE;
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
||||||
let mut out = 0;
|
|
||||||
GetConsoleMode(handle, &mut out) != 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME remove these and use winapi 0.3 instead
|
|
||||||
#[cfg(unix)]
|
|
||||||
fn stderr_isatty() -> bool {
|
fn stderr_isatty() -> bool {
|
||||||
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
|
atty::is(atty::Stream::Stderr)
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn stderr_isatty() -> bool {
|
|
||||||
use winapi::um::consoleapi::GetConsoleMode;
|
|
||||||
use winapi::um::processenv::GetStdHandle;
|
|
||||||
use winapi::um::winbase::STD_ERROR_HANDLE;
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
let handle = GetStdHandle(STD_ERROR_HANDLE);
|
|
||||||
let mut out = 0;
|
|
||||||
GetConsoleMode(handle, &mut out) != 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
|
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue