Use cfg_if in libtest.
Simplifies some of the expressions, and provides a default.
This commit is contained in:
parent
8c6c1dd3d3
commit
432b4c14aa
|
@ -4552,6 +4552,7 @@ dependencies = [
|
|||
name = "test"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"core",
|
||||
"getopts",
|
||||
"libc",
|
||||
|
|
|
@ -10,6 +10,7 @@ path = "lib.rs"
|
|||
crate-type = ["dylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
|
||||
getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] }
|
||||
term = { path = "../libterm" }
|
||||
std = { path = "../libstd" }
|
||||
|
|
|
@ -14,8 +14,10 @@ pub fn get_concurrency() -> usize {
|
|||
}
|
||||
Err(..) => num_cpus(),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
#[allow(nonstandard_style)]
|
||||
fn num_cpus() -> usize {
|
||||
#[repr(C)]
|
||||
|
@ -41,34 +43,7 @@ pub fn get_concurrency() -> usize {
|
|||
sysinfo.dwNumberOfProcessors as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "vxworks")]
|
||||
fn num_cpus() -> usize {
|
||||
// FIXME: Implement num_cpus on vxWorks
|
||||
1
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
fn num_cpus() -> usize {
|
||||
// FIXME: Implement num_cpus on Redox
|
||||
1
|
||||
}
|
||||
|
||||
#[cfg(target_os = "hermit")]
|
||||
fn num_cpus() -> usize {
|
||||
// FIXME: Implement num_cpus on HermitCore
|
||||
1
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
all(target_arch = "wasm32", not(target_os = "emscripten")),
|
||||
all(target_vendor = "fortanix", target_env = "sgx")
|
||||
))]
|
||||
fn num_cpus() -> usize {
|
||||
1
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
} else if #[cfg(any(
|
||||
target_os = "android",
|
||||
target_os = "cloudabi",
|
||||
target_os = "emscripten",
|
||||
|
@ -78,12 +53,11 @@ pub fn get_concurrency() -> usize {
|
|||
target_os = "macos",
|
||||
target_os = "solaris",
|
||||
target_os = "illumos",
|
||||
))]
|
||||
))] {
|
||||
fn num_cpus() -> usize {
|
||||
unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize }
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))]
|
||||
} else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))] {
|
||||
fn num_cpus() -> usize {
|
||||
use std::ptr;
|
||||
|
||||
|
@ -111,8 +85,7 @@ pub fn get_concurrency() -> usize {
|
|||
}
|
||||
cpus as usize
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
} else if #[cfg(target_os = "openbsd")] {
|
||||
fn num_cpus() -> usize {
|
||||
use std::ptr;
|
||||
|
||||
|
@ -135,16 +108,10 @@ pub fn get_concurrency() -> usize {
|
|||
}
|
||||
cpus as usize
|
||||
}
|
||||
|
||||
#[cfg(target_os = "haiku")]
|
||||
} else {
|
||||
// FIXME: implement on vxWorks, Redox, HermitCore, Haiku, l4re
|
||||
fn num_cpus() -> usize {
|
||||
// FIXME: implement
|
||||
1
|
||||
}
|
||||
|
||||
#[cfg(target_os = "l4re")]
|
||||
fn num_cpus() -> usize {
|
||||
// FIXME: implement
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,12 @@
|
|||
//! Helper module which provides a function to test
|
||||
//! if stdout is a tty.
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "cloudabi",
|
||||
target_os = "hermit",
|
||||
all(target_arch = "wasm32", not(target_os = "emscripten")),
|
||||
all(target_vendor = "fortanix", target_env = "sgx")
|
||||
))]
|
||||
pub fn stdout_isatty() -> bool {
|
||||
// FIXME: Implement isatty on SGX
|
||||
false
|
||||
}
|
||||
#[cfg(unix)]
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(unix)] {
|
||||
pub fn stdout_isatty() -> bool {
|
||||
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
|
||||
}
|
||||
#[cfg(windows)]
|
||||
} else if #[cfg(windows)] {
|
||||
pub fn stdout_isatty() -> bool {
|
||||
type DWORD = u32;
|
||||
type BOOL = i32;
|
||||
|
@ -32,3 +23,10 @@ pub fn stdout_isatty() -> bool {
|
|||
GetConsoleMode(handle, &mut out) != 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// FIXME: Implement isatty on SGX
|
||||
pub fn stdout_isatty() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue