diff --git a/Cargo.toml b/Cargo.toml index 6b646b58359..094d16e9211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -392,9 +392,11 @@ runcon = { optional = true, version = "0.13.0", package = "uu_runcon", path = "s [target.'cfg(unix)'.dev-dependencies] nix = { workspace = true, features = ["fs", "signal"] } -rlimit = { workspace = true } rustix = { workspace = true, features = ["net", "process"] } +[target.'cfg(all(unix, not(target_os = "fuchsia")))'.dev-dependencies] +rlimit = { workspace = true } + [build-dependencies] phf_codegen.workspace = true diff --git a/tests/uutests/Cargo.toml b/tests/uutests/Cargo.toml index 36ba7a39bc7..d4b6f5c8052 100644 --- a/tests/uutests/Cargo.toml +++ b/tests/uutests/Cargo.toml @@ -18,8 +18,7 @@ all-features = true [lib] path = "src/lib/lib.rs" -[dependencies] -ctor = { workspace = true } +[target.'cfg(not(any(target_os = "aix", target_os = "horizon")))'.dependencies] libc = { workspace = true } pretty_assertions = { workspace = true } rand = { workspace = true } @@ -35,13 +34,18 @@ uucore = { workspace = true, features = [ [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] -[target.'cfg(unix)'.dependencies] -nix = { workspace = true, features = ["fs", "term"] } +[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "fuchsia", target_os = "horizon"))))'.dependencies] rlimit = { workspace = true } + +[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "horizon"))))'.dependencies] +nix = { workspace = true, features = ["fs", "term"] } rustix = { workspace = true, features = ["pty", "termios"] } [target.'cfg(any(target_os = "freebsd", target_os = "hurd", target_os = "linux", target_os = "android", target_os = "netbsd"))'.dependencies] xattr = { workspace = true } +[target.'cfg(not(any(target_os = "aix", target_os = "horizon")))'.dev-dependencies] +ctor = { workspace = true } + [lints] workspace = true diff --git a/tests/uutests/src/lib/lib.rs b/tests/uutests/src/lib/lib.rs index afd8f1a3939..91777f33fdf 100644 --- a/tests/uutests/src/lib/lib.rs +++ b/tests/uutests/src/lib/lib.rs @@ -3,6 +3,8 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +#![cfg(not(any(target_os = "aix", target_os = "horizon")))] + #[macro_use] pub mod macros; pub mod random; diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 25db32151de..d9d6ea91aee 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -17,14 +17,14 @@ use core::str; #[cfg(unix)] use libc::mode_t; -#[cfg(all(unix, not(target_os = "redox")))] +#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))] use nix::pty::OpenptyResult; #[cfg(unix)] use nix::sys; -#[cfg(not(windows))] +#[cfg(unix)] use nix::sys::stat::{self, SFlag}; use pretty_assertions::assert_eq; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "fuchsia")))] use rlimit::{Resource, setrlimit}; use std::borrow::Cow; use std::collections::{BTreeMap, VecDeque}; @@ -353,8 +353,16 @@ impl CmdResult { /// /// # Platform specific behavior /// - /// This assertion method is only available on unix systems, except for fuchsia. - #[cfg(all(unix, not(target_os = "fuchsia")))] + /// This assertion method is only available on unix systems, except for fuchsia, haiku and hurd. + #[cfg(all( + unix, + not(any( + target_os = "dragonfly", + target_os = "fuchsia", + target_os = "haiku", + target_os = "hurd" + )) + ))] #[track_caller] pub fn signal_name_is(&self, name: &str) -> &Self { use uucore::signals::signal_by_name_or_value; @@ -1216,7 +1224,7 @@ impl AtPath { File::create(self.plus(file)).unwrap(); } - #[cfg(not(windows))] + #[cfg(unix)] pub fn mkfifo(&self, fifo: &str) { // rustix::fs::mkfifoat is linux only use nix::sys::stat::Mode; @@ -1234,13 +1242,13 @@ impl AtPath { UnixListener::bind(full_path).expect("Socket file creation failed."); } - #[cfg(not(windows))] + #[cfg(unix)] pub fn is_fifo(&self, fifo: &str) -> bool { stat::stat(&self.plus(fifo)) .is_ok_and(|s| SFlag::from_bits_truncate(s.st_mode).contains(SFlag::S_IFIFO)) } - #[cfg(not(windows))] + #[cfg(unix)] pub fn is_char_device(&self, char_dev: &str) -> bool { stat::stat(&self.plus(char_dev)) .is_ok_and(|s| SFlag::from_bits_truncate(s.st_mode).contains(SFlag::S_IFCHR)) @@ -1258,6 +1266,7 @@ impl AtPath { hard_link(self.plus(original), self.plus(link)).unwrap(); } + #[cfg(any(unix, windows))] pub fn symlink_file(&self, original: &str, link: &str) { log_info( "symlink", @@ -1270,6 +1279,7 @@ impl AtPath { symlink_file(self.plus(original), self.plus(link)).unwrap(); } + #[cfg(any(unix, windows))] pub fn relative_symlink_file(&self, original: &str, link: &str) { #[cfg(windows)] let original = original.replace('/', MAIN_SEPARATOR_STR); @@ -1280,6 +1290,7 @@ impl AtPath { symlink_file(original, self.plus(link)).unwrap(); } + #[cfg(any(unix, windows))] pub fn symlink_dir(&self, original: &str, link: &str) { log_info( "symlink", @@ -1292,6 +1303,7 @@ impl AtPath { symlink_dir(self.plus(original), self.plus(link)).unwrap(); } + #[cfg(any(unix, windows))] pub fn relative_symlink_dir(&self, original: &str, link: &str) { #[cfg(windows)] let original = original.replace('/', MAIN_SEPARATOR_STR); @@ -1403,7 +1415,7 @@ impl AtPath { /// /// This function panics if there is an error loading the metadata /// or setting the permissions of the file. - #[cfg(not(windows))] + #[cfg(unix)] pub fn set_mode(&self, filename: &str, mode: u32) { let path = self.plus(filename); let mut perms = fs::metadata(&path).unwrap().permissions(); @@ -1562,7 +1574,7 @@ pub struct UCommand { stdout: Option, stderr: Option, bytes_into_stdin: Option>, - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] limits: Vec<(Resource, u64, u64)>, #[cfg(unix)] ignore_sigxfsz: bool, @@ -1727,7 +1739,7 @@ impl UCommand { self } - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] pub fn limit(&mut self, resource: Resource, soft_limit: u64, hard_limit: u64) -> &mut Self { self.limits.push((resource, soft_limit, hard_limit)); self @@ -2000,9 +2012,9 @@ impl UCommand { let mut captured_stdout = None; let mut captured_stderr = None; - #[cfg(all(unix, not(target_os = "redox")))] + #[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))] let mut stdin_pty: Option = None; - #[cfg(not(all(unix, not(target_os = "redox"))))] + #[cfg(not(all(unix, not(any(target_os = "fuchsia", target_os = "redox")))))] let stdin_pty: Option = None; if self.stderr_to_stdout { let mut output = CapturedOutput::default(); @@ -2037,7 +2049,7 @@ impl UCommand { .stderr(stderr); } - #[cfg(all(unix, not(target_os = "redox")))] + #[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))] if let Some(simulated_terminal) = &self.terminal_simulation { let terminal_size = simulated_terminal.size.unwrap_or(libc::winsize { ws_col: 80, @@ -2086,7 +2098,7 @@ impl UCommand { } } - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] if !self.limits.is_empty() { // just to be safe: move a copy of the limits list into the closure. // this way the closure is fully self-contained. @@ -3050,14 +3062,9 @@ pub fn whoami() -> String { /// Open a PTY whose two ends are close-on-exec, so that commands started by /// other tests in the meantime don't inherit them. -#[cfg(all(unix, not(target_os = "redox")))] +#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))] fn open_pty(size: Option<&libc::winsize>) -> OpenptyResult { - #[cfg(any( - target_os = "linux", - target_os = "android", - target_os = "freebsd", - target_os = "netbsd" - ))] + #[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))] { use rustix::fs::{Mode, OFlags, open}; use rustix::pty::{OpenptFlags, grantpt, openpt, ptsname, unlockpt}; @@ -3088,12 +3095,7 @@ fn open_pty(size: Option<&libc::winsize>) -> OpenptyResult { // Elsewhere a PTY can't be opened close-on-exec, so a command started // between openpty and fcntl can still inherit it. - #[cfg(not(any( - target_os = "linux", - target_os = "android", - target_os = "freebsd", - target_os = "netbsd" - )))] + #[cfg(not(any(target_os = "linux", target_os = "android", target_os = "freebsd")))] { use nix::fcntl::{FcntlArg, FdFlag, fcntl}; @@ -3111,7 +3113,7 @@ fn open_pty(size: Option<&libc::winsize>) -> OpenptyResult { /// - path: The filesystem path to the PTY replica device /// - controller: The controller file /// - replica: The replica file -#[cfg(all(unix, not(target_os = "redox")))] +#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))] pub fn pty_path() -> (String, File, File) { use nix::unistd::ttyname; let pty = open_pty(None); @@ -3768,7 +3770,7 @@ mod tests { .stdout_is("unlimited\nunlimited\n"); } - #[cfg(unix)] + #[cfg(all(unix, not(target_os = "fuchsia")))] #[test] fn test_application_of_process_resource_limits_limited_file_size() { let unit_size_bytes = if cfg!(target_vendor = "apple") {