diff --git a/Cargo.toml b/Cargo.toml index 3c8fea771d5..ad9d1960e22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -615,8 +615,10 @@ workspace = true [workspace.lints.rust] # Allow "fuzzing" as a "cfg" condition name and "cygwin" as a value for "target_os" # https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html +# "linux_android" is a cfg alias for any(target_os = "linux", target_os = "android") unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(fuzzing)', + 'cfg(linux_android)', 'cfg(target_os, values("cygwin"))', ] } #unused_qualifications = "warn" // TODO: fix warnings in uucore, then re-enable this lint diff --git a/build.rs b/build.rs index aabd968329b..821d70b23e8 100644 --- a/build.rs +++ b/build.rs @@ -19,6 +19,11 @@ pub fn main() { // See println!("cargo:rerun-if-changed=build.rs"); + // Define cfg alias for Linux and Android platforms + // This avoids repetitive `any(target_os = "linux", target_os = "android")` patterns + #[cfg(any(target_os = "linux", target_os = "android"))] + println!("cargo:rustc-cfg=linux_android"); + // Check for tldr.zip when building uudoc to warn users once at build time // instead of repeatedly at runtime for each utility if env::var("CARGO_FEATURE_UUDOC").is_ok() && !Path::new("docs/tldr.zip").exists() { diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index eeec8902528..8e1d3368452 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -24,7 +24,7 @@ use uucore::translate; use uucore::{fast_inc::fast_inc_one, format_usage}; /// Linux splice support -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] mod splice; // Allocate 32 digits for the line number. @@ -85,7 +85,7 @@ enum CatError { #[error("{0}")] Io(#[from] io::Error), /// Wrapper around `nix::Error` - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] #[error("{0}")] Nix(#[from] nix::Error), /// Unknown file type; it's not a regular file, socket, etc. @@ -477,7 +477,7 @@ fn get_input_type(path: &OsString) -> CatResult { fn write_fast(handle: &mut InputHandle) -> CatResult<()> { let stdout = io::stdout(); let mut stdout_lock = stdout.lock(); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { // If we're on Linux or Android, try to use the splice() system call // for faster writing. If it works, we're done. diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index cd39858260e..b2c8b959f46 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -5,7 +5,7 @@ // spell-checker:ignore (vars) RFILE -#![cfg(any(target_os = "linux", target_os = "android"))] +#![cfg(linux_android)] #![allow(clippy::upper_case_acronyms)] use clap::builder::ValueParser; diff --git a/src/uu/chcon/src/errors.rs b/src/uu/chcon/src/errors.rs index fa4ae6fee54..ea54f021284 100644 --- a/src/uu/chcon/src/errors.rs +++ b/src/uu/chcon/src/errors.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#![cfg(any(target_os = "linux", target_os = "android"))] +#![cfg(linux_android)] use std::ffi::OsString; use std::fmt::Write; diff --git a/src/uu/chcon/src/fts.rs b/src/uu/chcon/src/fts.rs index 8214058a770..e73058a00b9 100644 --- a/src/uu/chcon/src/fts.rs +++ b/src/uu/chcon/src/fts.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#![cfg(any(target_os = "linux", target_os = "android"))] +#![cfg(linux_android)] use std::ffi::{CStr, CString, OsStr}; use std::marker::PhantomData; diff --git a/src/uu/chcon/src/main.rs b/src/uu/chcon/src/main.rs index bd502509571..116a6ca45be 100644 --- a/src/uu/chcon/src/main.rs +++ b/src/uu/chcon/src/main.rs @@ -9,10 +9,10 @@ //! entirely (via #![cfg(...)]), which can break tooling and cross builds that //! expect this binary to exist even when it's a no-op off Linux. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] uucore::bin!(uu_chcon); -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] fn main() { eprintln!("chcon: SELinux is not supported on this platform"); std::process::exit(1); diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 04cb8c0c965..caee92f2063 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -314,7 +314,7 @@ fn set_supplemental_gids(gids: &[libc::gid_t]) -> std::io::Result<()> { target_os = "cygwin" ))] let n = gids.len() as libc::c_int; - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] let n = gids.len() as libc::size_t; let err = unsafe { setgroups(n, gids.as_ptr()) }; if err == 0 { diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 62b8b7a7bcf..a4e2801aba5 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1790,7 +1790,7 @@ pub(crate) fn copy_attributes( Ok(()) })?; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] handle_preserve(&attributes.context, || -> CopyResult<()> { // Get the source context and apply it to the destination if let Ok(context) = selinux::SecurityContext::of_path(source, false, false) { @@ -2586,7 +2586,7 @@ fn copy_file( copy_attributes(source, dest, &options.attributes)?; } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] if options.set_selinux_context && uucore::selinux::is_selinux_enabled() { // Set the given selinux permissions on the copied file. if let Err(e) = diff --git a/src/uu/cp/src/platform/linux.rs b/src/uu/cp/src/platform/linux.rs index 427593ae25d..93a3508776a 100644 --- a/src/uu/cp/src/platform/linux.rs +++ b/src/uu/cp/src/platform/linux.rs @@ -53,7 +53,7 @@ enum CopyMethod { /// Use the Linux `ioctl_ficlone` API to do a copy-on-write clone. /// /// `fallback` controls what to do if the system call fails. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn clone

(source: P, dest: P, fallback: CloneFallback) -> std::io::Result<()> where P: AsRef, @@ -77,7 +77,7 @@ where /// Checks whether a file contains any non null bytes i.e. any byte != 0x0 /// This function returns a tuple of (bool, u64, u64) signifying a tuple of (whether a file has /// data, its size, no of blocks it has allocated in disk) -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn check_for_data(source: &Path) -> Result<(bool, u64, u64), std::io::Error> { let mut src_file = File::open(source)?; let metadata = src_file.metadata()?; @@ -102,7 +102,7 @@ fn check_for_data(source: &Path) -> Result<(bool, u64, u64), std::io::Error> { } } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] /// Checks whether a file is sparse i.e. it contains holes, uses the crude heuristic blocks < size / 512 /// Reference:`` fn check_sparse_detection(source: &Path) -> Result { @@ -119,7 +119,7 @@ fn check_sparse_detection(source: &Path) -> Result { /// Optimized [`sparse_copy`] doesn't create holes for large sequences of zeros in non `sparse_files` /// Used when `--sparse=auto` -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn sparse_copy_without_hole

(source: P, dest: P) -> std::io::Result<()> where P: AsRef, @@ -169,7 +169,7 @@ where } /// Perform a sparse copy from one file to another. /// Creates a holes for large sequences of zeros in `non_sparse_files`, used for `--sparse=always` -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn sparse_copy

(source: P, dest: P) -> std::io::Result<()> where P: AsRef, @@ -201,7 +201,7 @@ where Ok(()) } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] /// Checks whether an existing destination is a fifo fn check_dest_is_fifo(dest: &Path) -> bool { // If our destination file exists and its a fifo , we do a standard copy . diff --git a/src/uu/cp/src/platform/mod.rs b/src/uu/cp/src/platform/mod.rs index 2071e928f41..080b35e5060 100644 --- a/src/uu/cp/src/platform/mod.rs +++ b/src/uu/cp/src/platform/mod.rs @@ -19,9 +19,9 @@ mod macos; #[cfg(target_os = "macos")] pub(crate) use self::macos::copy_on_write; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] mod linux; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] pub(crate) use self::linux::copy_on_write; #[cfg(not(any( diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index fc1adc537fc..6ff89fec803 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -16,9 +16,9 @@ mod progress; use crate::bufferedoutput::BufferedOutput; use blocks::conv_block_unblock_helper; use datastructures::*; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use nix::fcntl::FcntlArg::F_SETFL; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use nix::fcntl::OFlag; use parseargs::Parser; use progress::ProgUpdateType; @@ -31,9 +31,9 @@ use std::env; use std::ffi::OsString; use std::fs::{File, OpenOptions}; use std::io::{self, Read, Seek, SeekFrom, Write}; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use std::os::fd::AsFd; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use std::os::unix::fs::OpenOptionsExt; #[cfg(unix)] use std::os::unix::{ @@ -405,7 +405,7 @@ impl<'a> Input<'a> { let mut opts = OpenOptions::new(); opts.read(true); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] if let Some(libc_flags) = make_linux_iflags(&settings.iflags) { opts.custom_flags(libc_flags); } @@ -427,7 +427,7 @@ impl<'a> Input<'a> { fn new_fifo(filename: &Path, settings: &'a Settings) -> UResult { let mut opts = OpenOptions::new(); opts.read(true); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] opts.custom_flags(make_linux_iflags(&settings.iflags).unwrap_or(0)); let mut src = Source::Fifo(opts.open(filename)?); if settings.skip > 0 { @@ -437,7 +437,7 @@ impl<'a> Input<'a> { } } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn make_linux_iflags(iflags: &IFlags) -> Option { let mut flag = 0; @@ -720,7 +720,7 @@ fn is_sparse(buf: &[u8]) -> bool { /// Handle O_DIRECT write errors by temporarily removing the flag and retrying. /// This follows GNU dd behavior for partial block writes with O_DIRECT. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn handle_o_direct_write(f: &mut File, buf: &[u8], original_error: io::Error) -> io::Result { use nix::fcntl::{FcntlArg, OFlag, fcntl}; @@ -757,7 +757,7 @@ fn handle_o_direct_write(f: &mut File, buf: &[u8], original_error: io::Error) -> } /// Stub for non-Linux platforms - just return the original error. -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] fn handle_o_direct_write( _f: &mut File, _buf: &[u8], @@ -845,7 +845,7 @@ impl<'a> Output<'a> { .create_new(cflags.excl) .append(oflags.append); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] if let Some(libc_flags) = make_linux_oflags(oflags) { opts.custom_flags(libc_flags); } @@ -891,7 +891,7 @@ impl<'a> Output<'a> { /// (current position) that shall be used. fn new_file_from_stdout(settings: &'a Settings) -> UResult { let fx = OwnedFileDescriptorOrHandle::from(io::stdout())?; - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] if let Some(libc_flags) = make_linux_oflags(&settings.oflags) { nix::fcntl::fcntl( fx.as_raw().as_fd(), @@ -925,7 +925,7 @@ impl<'a> Output<'a> { .create(!settings.oconv.nocreat) .create_new(settings.oconv.excl) .append(settings.oflags.append); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] opts.custom_flags(make_linux_oflags(&settings.oflags).unwrap_or(0)); let dst = Dest::Fifo(opts.open(filename)?); Ok(Self { dst, settings }) @@ -1321,7 +1321,7 @@ fn finalize( Ok(()) } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[allow(clippy::cognitive_complexity)] fn make_linux_oflags(oflags: &OFlags) -> Option { let mut flag = 0; diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index 2e8c104ff57..6b0d49e11d0 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -116,7 +116,7 @@ enum Block { /// Return an Unimplemented error when the target is not Linux or Android macro_rules! linux_only { ($s: expr, $val: expr) => { - if cfg!(any(target_os = "linux", target_os = "android")) { + if cfg!(linux_android) { $val } else { return Err(ParseError::Unimplemented($s.to_string()).into()); diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index cde0ef0cc1f..3a81801916b 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -12,7 +12,7 @@ use crate::conversion_tables::{ }; use crate::parseargs::Parser; -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] #[allow(clippy::useless_vec)] #[test] fn unimplemented_flags_should_error_non_linux() { @@ -384,7 +384,7 @@ fn parse_oflag_tokens() { ); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn parse_iflag_tokens_linux() { let args = ["iflag=direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow"]; @@ -407,7 +407,7 @@ fn parse_iflag_tokens_linux() { ); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn parse_oflag_tokens_linux() { let args = ["oflag=direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow"]; diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 7dde478b4c3..539188e0d77 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -10,7 +10,7 @@ mod mode; use clap::{Arg, ArgAction, ArgMatches, Command}; use file_diff::diff; use filetime::{FileTime, set_file_times}; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] use selinux::SecurityContext; use std::ffi::OsString; use std::fmt::Debug; @@ -27,7 +27,7 @@ use uucore::error::{FromIo, UError, UResult, UUsageError}; use uucore::fs::dir_strip_dot_for_creation; use uucore::perms::{Verbosity, VerbosityLevel, wrap_chown}; use uucore::process::{getegid, geteuid}; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] use uucore::selinux::{ SeLinuxError, contexts_differ, get_selinux_security_context, is_selinux_enabled, selinux_error_description, set_selinux_security_context, @@ -118,7 +118,7 @@ enum InstallError { #[error("{}", translate!("install-error-extra-operand", "operand" => .0.quote(), "usage" => .1.clone()))] ExtraOperand(OsString, String), - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] #[error("{}", .0)] SelinuxContextFailed(String), } @@ -1004,7 +1004,7 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> { Ok(()) } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] fn get_context_for_selinux(b: &Behavior) -> Option<&String> { if b.default_context { None @@ -1139,7 +1139,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool { false } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] /// Sets the `SELinux` security context for install's -Z flag behavior. /// /// This function implements the specific behavior needed for install's -Z flag, @@ -1173,7 +1173,7 @@ pub fn set_selinux_default_context(path: &Path) -> Result<(), SeLinuxError> { } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] /// Gets the default `SELinux` context for a path based on the system's security policy. /// /// This function attempts to determine what the "correct" `SELinux` context should be @@ -1229,7 +1229,7 @@ fn get_default_context_for_path(path: &Path) -> Result, SeLinuxEr Ok(None) } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] /// Derives an appropriate `SELinux` context based on a parent directory context. /// /// This is a heuristic function that attempts to generate an appropriate @@ -1267,7 +1267,7 @@ fn derive_context_from_parent(parent_context: &str) -> String { } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] /// Helper function to collect paths that need `SELinux` context setting. /// /// Traverses from the given starting path up to existing parent directories. @@ -1281,7 +1281,7 @@ fn collect_paths_for_context_setting(starting_path: &Path) -> Vec<&Path> { paths } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] /// Sets the `SELinux` security context for a directory hierarchy. /// /// This function traverses from the given starting path up to existing parent directories @@ -1321,7 +1321,7 @@ fn set_selinux_context_for_directories(target_path: &Path, context: Option<&Stri } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] /// Sets `SELinux` context for created directories using install's -Z default behavior. /// /// Similar to `set_selinux_context_for_directories` but uses install's @@ -1345,10 +1345,10 @@ pub fn set_selinux_context_for_directories_install(target_path: &Path, context: #[cfg(test)] mod tests { - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] use super::derive_context_from_parent; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] #[test] fn test_derive_context_from_parent() { // Test cases: (input_context, file_type, expected_output, description) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 1bad3002335..ce6f9956a73 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -373,7 +373,7 @@ pub struct Config { time_format_recent: String, // Time format for recent dates time_format_older: Option, // Time format for older dates (optional, if not present, time_format_recent is used) context: bool, - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] selinux_supported: bool, #[cfg(all(feature = "smack", target_os = "linux"))] smack_supported: bool, @@ -1233,7 +1233,7 @@ impl Config { time_format_recent, time_format_older, context, - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] selinux_supported: uucore::selinux::is_selinux_enabled(), #[cfg(all(feature = "smack", target_os = "linux"))] smack_supported: uucore::smack::is_smack_enabled(), @@ -3531,7 +3531,7 @@ fn get_security_context<'a>( } } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] if config.selinux_supported { match selinux::SecurityContext::of_path(path, must_dereference, false) { Err(_r) => { diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 740e8cdb475..f8a852a338d 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -65,7 +65,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // Apply SELinux context if requested - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(all(feature = "selinux", linux_android))] { // Extract the SELinux related flags and options let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index 615a705948c..a08eda024d2 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -13,7 +13,7 @@ use uucore::error::{UResult, USimpleError}; use uucore::format_usage; use uucore::translate; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] pub const _SC_NPROCESSORS_CONF: libc::c_int = 83; #[cfg(target_vendor = "apple")] pub const _SC_NPROCESSORS_CONF: libc::c_int = libc::_SC_NPROCESSORS_CONF; diff --git a/src/uu/runcon/src/errors.rs b/src/uu/runcon/src/errors.rs index 49dc83d16c2..47d5f055c57 100644 --- a/src/uu/runcon/src/errors.rs +++ b/src/uu/runcon/src/errors.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -#![cfg(any(target_os = "linux", target_os = "android"))] +#![cfg(linux_android)] use std::ffi::OsString; use std::fmt::{Display, Formatter, Write}; diff --git a/src/uu/runcon/src/main.rs b/src/uu/runcon/src/main.rs index 947934af1cb..b9e1f4991fb 100644 --- a/src/uu/runcon/src/main.rs +++ b/src/uu/runcon/src/main.rs @@ -9,10 +9,10 @@ //! entirely (via #![cfg(...)]), which can break tooling and cross builds that //! expect this binary to exist even when it's a no-op off Linux. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] uucore::bin!(uu_runcon); -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] fn main() { eprintln!("runcon: SELinux is not supported on this platform"); std::process::exit(1); diff --git a/src/uu/runcon/src/runcon.rs b/src/uu/runcon/src/runcon.rs index 128d0dce370..5953c80a02d 100644 --- a/src/uu/runcon/src/runcon.rs +++ b/src/uu/runcon/src/runcon.rs @@ -5,7 +5,7 @@ // spell-checker:ignore (vars) RFILE execv execvp -#![cfg(any(target_os = "linux", target_os = "android"))] +#![cfg(linux_android)] use clap::builder::ValueParser; use uucore::error::{UError, UResult}; diff --git a/src/uu/sort/src/buffer_hint.rs b/src/uu/sort/src/buffer_hint.rs index bb0ea754094..8745bdef16b 100644 --- a/src/uu/sort/src/buffer_hint.rs +++ b/src/uu/sort/src/buffer_hint.rs @@ -88,31 +88,19 @@ fn desired_file_buffer_bytes(total_bytes: u128) -> u128 { } fn physical_memory_bytes() -> Option { - #[cfg(all( - target_family = "unix", - not(target_os = "redox"), - any(target_os = "linux", target_os = "android") - ))] + #[cfg(all(target_family = "unix", not(target_os = "redox"), linux_android))] { physical_memory_bytes_unix() } - #[cfg(any( - not(target_family = "unix"), - target_os = "redox", - not(any(target_os = "linux", target_os = "android")) - ))] + #[cfg(any(not(target_family = "unix"), target_os = "redox", not(linux_android)))] { // No portable or safe API is available here to detect total physical memory. None } } -#[cfg(all( - target_family = "unix", - not(target_os = "redox"), - any(target_os = "linux", target_os = "android") -))] +#[cfg(all(target_family = "unix", not(target_os = "redox"), linux_android))] fn physical_memory_bytes_unix() -> Option { use nix::unistd::{SysconfVar, sysconf}; diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 24982e6a4b0..d51c8f872af 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -1044,10 +1044,7 @@ impl Stater { 'B' => OutputType::Unsigned(512), // SELinux security context string 'C' => { - #[cfg(all( - feature = "selinux", - any(target_os = "linux", target_os = "android") - ))] + #[cfg(all(feature = "selinux", linux_android))] { if uucore::selinux::is_selinux_enabled() { match uucore::selinux::get_selinux_security_context( @@ -1063,10 +1060,7 @@ impl Stater { OutputType::Str(translate!("stat-selinux-unsupported-system")) } } - #[cfg(not(all( - feature = "selinux", - any(target_os = "linux", target_os = "android") - )))] + #[cfg(not(all(feature = "selinux", linux_android)))] { OutputType::Str(translate!("stat-selinux-unsupported-os")) } diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index c346cbe7c5c..42226dda020 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -307,19 +307,19 @@ pub const BAUD_RATES: &[(&str, BaudRate)] = &[ ("57600", BaudRate::B57600), ("115200", BaudRate::B115200), ("230400", BaudRate::B230400), - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_android)] ("500000", BaudRate::B500000), - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_android)] ("576000", BaudRate::B576000), - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_android)] ("921600", BaudRate::B921600), - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_android)] ("1000000", BaudRate::B1000000), - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_android)] ("1152000", BaudRate::B1152000), - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_android)] ("1500000", BaudRate::B1500000), - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(linux_android)] ("2000000", BaudRate::B2000000), #[cfg(any( target_os = "android", diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index f34f9b498e5..e8231e3d2fd 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -1036,13 +1036,10 @@ fn apply_special_setting( match setting { SpecialSetting::Rows(n) => size.rows = *n, SpecialSetting::Cols(n) => size.columns = *n, - #[cfg_attr( - not(any(target_os = "linux", target_os = "android")), - expect(unused_variables) - )] + #[cfg_attr(not(linux_android), expect(unused_variables))] SpecialSetting::Line(n) => { // nix only defines Termios's `line_discipline` field on these platforms - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { _termios.line_discipline = *n; } diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index de79a957bf8..46e2a2fae1e 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -6,15 +6,15 @@ /* Last synced with: sync (GNU coreutils) 8.13 */ use clap::{Arg, ArgAction, Command}; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use nix::errno::Errno; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use nix::fcntl::{OFlag, open}; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use nix::sys::stat::Mode; use std::path::Path; use uucore::display::Quotable; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use uucore::error::FromIo; use uucore::error::{UResult, USimpleError}; use uucore::format_usage; @@ -29,14 +29,14 @@ static ARG_FILES: &str = "files"; #[cfg(unix)] mod platform { - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] use nix::fcntl::{FcntlArg, OFlag, fcntl}; use nix::unistd::sync; - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] use nix::unistd::{fdatasync, syncfs}; - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] use std::fs::File; - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] use uucore::error::FromIo; use uucore::error::UResult; @@ -46,7 +46,7 @@ mod platform { Ok(()) } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] pub fn do_syncfs(files: Vec) -> UResult<()> { for path in files { let f = File::open(&path).map_err_context(|| path.clone())?; @@ -57,7 +57,7 @@ mod platform { Ok(()) } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] pub fn do_fdatasync(files: Vec) -> UResult<()> { for path in files { let f = File::open(&path).map_err_context(|| path.clone())?; @@ -199,7 +199,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { for f in &files { // Use the Nix open to be able to set the NONBLOCK flags for fifo files - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let path = Path::new(&f); if let Err(e) = open(path, OFlag::O_NONBLOCK, Mode::empty()) { @@ -210,7 +210,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } } - #[cfg(not(any(target_os = "linux", target_os = "android")))] + #[cfg(not(linux_android))] { if !Path::new(&f).exists() { return Err(USimpleError::new( @@ -226,7 +226,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { #[cfg(any(target_os = "linux", target_os = "android", target_os = "windows"))] syncfs(files)?; } else if matches.get_flag(options::DATA) { - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] fdatasync(files)?; } else { sync()?; @@ -273,7 +273,7 @@ fn syncfs(files: Vec) -> UResult<()> { platform::do_syncfs(files) } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn fdatasync(files: Vec) -> UResult<()> { platform::do_fdatasync(files) } diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index d20c53d4fb8..7907cab7155 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -9,7 +9,7 @@ use uucore::hardware::SimdPolicy; use super::WordCountable; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use std::fs::OpenOptions; use std::io::{self, ErrorKind, Read}; @@ -28,13 +28,13 @@ const FILE_ATTRIBUTE_ARCHIVE: u32 = 32; #[cfg(windows)] const FILE_ATTRIBUTE_NORMAL: u32 = 128; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use libc::S_IFIFO; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use uucore::pipes::{pipe, splice, splice_exact}; const BUF_SIZE: usize = 256 * 1024; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] const SPLICE_SIZE: usize = 128 * 1024; /// This is a Linux-specific function to count the number of bytes using the @@ -43,7 +43,7 @@ const SPLICE_SIZE: usize = 128 * 1024; /// On error it returns the number of bytes it did manage to read, since the /// caller will fall back to a simpler method. #[inline] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn count_bytes_using_splice(fd: &impl AsFd) -> Result { let null_file = OpenOptions::new() .write(true) @@ -156,7 +156,7 @@ pub(crate) fn count_bytes_fast(handle: &mut T) -> (usize, Opti } } } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { // Else, if we're on Linux and our file is a FIFO pipe // (or stdin), we use splice to count the number of bytes. diff --git a/src/uucore/build.rs b/src/uucore/build.rs index 935394cd4cc..c944a0024a9 100644 --- a/src/uucore/build.rs +++ b/src/uucore/build.rs @@ -9,6 +9,11 @@ use std::io::Write; use std::path::Path; pub fn main() -> Result<(), Box> { + // Define cfg alias for Linux and Android platforms + // This avoids repetitive `any(target_os = "linux", target_os = "android")` patterns + #[cfg(any(target_os = "linux", target_os = "android"))] + println!("cargo:rustc-cfg=linux_android"); + let out_dir = env::var("OUT_DIR")?; let mut embedded_file = File::create(Path::new(&out_dir).join("embedded_locales.rs"))?; diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index 03d4101607b..7ea3c86d45b 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -81,7 +81,7 @@ pub mod tty; pub mod fsxattr; #[cfg(feature = "hardware")] pub mod hardware; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] pub mod selinux; #[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))] pub mod signals; diff --git a/src/uucore/src/lib/features/buf_copy.rs b/src/uucore/src/lib/features/buf_copy.rs index 3ab2814bc24..71c21206c67 100644 --- a/src/uucore/src/lib/features/buf_copy.rs +++ b/src/uucore/src/lib/features/buf_copy.rs @@ -11,14 +11,14 @@ pub mod common; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] pub mod linux; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] pub use linux::*; -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] pub mod other; -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] pub use other::copy_stream; #[cfg(test)] @@ -51,7 +51,7 @@ mod tests { .unwrap() } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] #[test] fn test_copy_exact() { let (mut pipe_read, mut pipe_write) = pipes::pipe().unwrap(); diff --git a/src/uucore/src/lib/features/buf_copy/linux.rs b/src/uucore/src/lib/features/buf_copy/linux.rs index 7760d668025..cd93cca3483 100644 --- a/src/uucore/src/lib/features/buf_copy/linux.rs +++ b/src/uucore/src/lib/features/buf_copy/linux.rs @@ -120,7 +120,7 @@ where /// Move exactly `num_bytes` bytes from `read_fd` to `write_fd` using the `read` /// and `write` calls. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] pub(crate) fn copy_exact( read_fd: &impl AsFd, write_fd: &impl AsFd, diff --git a/src/uucore/src/lib/features/entries.rs b/src/uucore/src/lib/features/entries.rs index 6a067e132b7..ef56f3e0b77 100644 --- a/src/uucore/src/lib/features/entries.rs +++ b/src/uucore/src/lib/features/entries.rs @@ -12,7 +12,7 @@ //! ``` //! use uucore::entries::{self, Locate}; //! -//! let root_group = if cfg!(any(target_os = "linux", target_os = "android")) { +//! let root_group = if cfg!(linux_android) { //! "root" //! } else { //! "wheel" diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index c31b8272599..2bbe385033b 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -812,7 +812,7 @@ impl FsMeta for StatFs { unimplemented!() } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] fn io_size(&self) -> u64 { self.f_frsize as u64 } @@ -865,7 +865,7 @@ impl FsMeta for StatFs { self.f_fsid as u64 } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] fn namelen(&self) -> u64 { self.f_namelen as u64 } @@ -1095,7 +1095,7 @@ mod tests { } #[test] - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] fn test_mountinfo() { // spell-checker:ignore (word) relatime let info = MountInfo::new( @@ -1137,7 +1137,7 @@ mod tests { } #[test] - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] fn test_mountinfo_dir_special_chars() { let info = MountInfo::new( LINUX_MOUNTINFO, @@ -1161,7 +1161,7 @@ mod tests { } #[test] - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] fn test_mountinfo_dir_non_unicode() { let info = MountInfo::new( LINUX_MOUNTINFO, diff --git a/src/uucore/src/lib/features/pipes.rs b/src/uucore/src/lib/features/pipes.rs index 5ac590b7b4a..d1366b8b761 100644 --- a/src/uucore/src/lib/features/pipes.rs +++ b/src/uucore/src/lib/features/pipes.rs @@ -6,12 +6,12 @@ //! Thin pipe-related wrappers around functions from the `nix` crate. use std::fs::File; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use std::io::IoSlice; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use std::os::fd::AsFd; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use nix::fcntl::SpliceFFlags; pub use nix::{Error, Result}; @@ -34,7 +34,7 @@ pub fn pipe() -> Result<(File, File)> { /// To get around this requirement, consider splicing from your source into /// a [`pipe`] and then from the pipe into your target (with `splice_exact`): /// this is still very efficient. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] pub fn splice(source: &impl AsFd, target: &impl AsFd, len: usize) -> Result { nix::fcntl::splice(source, None, target, None, len, SpliceFFlags::empty()) } @@ -44,7 +44,7 @@ pub fn splice(source: &impl AsFd, target: &impl AsFd, len: usize) -> Result Result<()> { let mut left = len; while left != 0 { @@ -58,7 +58,7 @@ pub fn splice_exact(source: &impl AsFd, target: &impl AsFd, len: usize) -> Resul /// Copy data from `bytes` into `target`, which must be a pipe. /// /// Returns the number of successfully copied bytes. -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] pub fn vmsplice(target: &impl AsFd, bytes: &[u8]) -> Result { nix::fcntl::vmsplice(target, &[IoSlice::new(bytes)], SpliceFFlags::empty()) } diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 03ae3d95576..608af0fefe6 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -122,7 +122,7 @@ pub use crate::features::fsext; #[cfg(all(unix, feature = "fsxattr"))] pub use crate::features::fsxattr; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(all(feature = "selinux", linux_android))] pub use crate::features::selinux; #[cfg(all(target_os = "linux", feature = "smack"))] diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index 7cb824f6099..8256931cb6d 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore NOFILE nonewline cmdline -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use rlimit::Resource; #[cfg(unix)] use std::fs::File; @@ -128,7 +128,7 @@ fn test_fifo_symlink() { #[test] // TODO(#7542): Re-enable on Android once we figure out why setting limit is broken. -// #[cfg(any(target_os = "linux", target_os = "android"))] +// #[cfg(linux_android)] #[cfg(target_os = "linux")] fn test_closes_file_descriptors() { // Each file creates a pipe, which has two file descriptors. @@ -524,10 +524,10 @@ fn test_squeeze_blank_before_numbering() { #[test] #[cfg(unix)] fn test_dev_random() { - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] const DEV_RANDOM: &str = "/dev/urandom"; - #[cfg(not(any(target_os = "linux", target_os = "android")))] + #[cfg(not(linux_android))] const DEV_RANDOM: &str = "/dev/random"; let mut proc = new_ucmd!() diff --git a/tests/by-util/test_chgrp.rs b/tests/by-util/test_chgrp.rs index aa2c9192c1c..9e1403d57ec 100644 --- a/tests/by-util/test_chgrp.rs +++ b/tests/by-util/test_chgrp.rs @@ -278,7 +278,7 @@ fn test_big_p() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_big_h() { if getegid() != 0 { assert!( diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 18c180bd05a..36cd04c47ce 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -252,11 +252,11 @@ fn test_chmod_umask_expected() { } fn get_expected_symlink_permissions() -> u32 { - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { 0o120_777 } - #[cfg(not(any(target_os = "linux", target_os = "android")))] + #[cfg(not(linux_android))] { 0o120_755 } diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index 2602aabde06..85f9ce360f2 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (words) agroupthatdoesntexist auserthatdoesntexist cuuser groupname notexisting passgrp -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use uucore::process::geteuid; use uutests::util::{CmdResult, TestScenario, is_ci, run_ucmd_as_root}; use uutests::util_name; @@ -686,7 +686,7 @@ fn test_root_preserve() { result.stderr_contains("chown: it is dangerous to operate recursively"); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_big_p() { if geteuid() != 0 { diff --git a/tests/by-util/test_comm.rs b/tests/by-util/test_comm.rs index dbcee059855..754e70ea612 100644 --- a/tests/by-util/test_comm.rs +++ b/tests/by-util/test_comm.rs @@ -674,7 +674,7 @@ fn test_output_lossy_utf8() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_comm_anonymous_pipes() { use std::{io::Write, os::fd::AsRawFd, process}; use uucore::pipes::pipe; diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index dd77ddd61c0..f1bb5dd3c90 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -28,16 +28,16 @@ use std::path::Path; #[cfg(target_os = "linux")] use std::path::PathBuf; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use filetime::FileTime; #[cfg(target_os = "linux")] use std::ffi::OsString; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use std::fs as std_fs; use std::thread::sleep; use std::time::Duration; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[cfg(feature = "truncate")] use uutests::util::PATH; @@ -2366,7 +2366,7 @@ fn test_cp_archive_recursive() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_preserve_timestamps() { let (at, mut ucmd) = at_and_ucmd!(); let ts = time::OffsetDateTime::now_utc(); @@ -2399,7 +2399,7 @@ fn test_cp_preserve_timestamps() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_no_preserve_timestamps() { let (at, mut ucmd) = at_and_ucmd!(); let ts = time::OffsetDateTime::now_utc(); @@ -2444,7 +2444,7 @@ fn test_cp_no_preserve_timestamps() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_target_file_dev_null() { let (at, mut ucmd) = at_and_ucmd!(); let file1 = "/dev/null"; @@ -2602,7 +2602,7 @@ fn test_cp_conflicting_update() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_reflink_insufficient_permission() { let (at, mut ucmd) = at_and_ucmd!(); @@ -2645,7 +2645,7 @@ fn test_closes_file_descriptors() { .succeeds(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_cp_sparse_never_empty() { const BUFFER_SIZE: usize = 4096 * 4; @@ -2665,7 +2665,7 @@ fn test_cp_sparse_never_empty() { ); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_cp_sparse_always_empty() { const BUFFER_SIZE: usize = 4096 * 4; @@ -2685,7 +2685,7 @@ fn test_cp_sparse_always_empty() { } } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_cp_sparse_always_non_empty() { const BUFFER_SIZE: usize = 4096 * 16 + 3; @@ -2711,7 +2711,7 @@ fn test_cp_sparse_always_non_empty() { assert_eq!(at.metadata("dst_file_sparse").blocks(), touched_block_count); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_cp_sparse_invalid_option() { let (at, mut ucmd) = at_and_ucmd!(); @@ -2722,7 +2722,7 @@ fn test_cp_sparse_invalid_option() { .fails(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_cp_sparse_always_reflink_always() { let (at, mut ucmd) = at_and_ucmd!(); @@ -2738,7 +2738,7 @@ fn test_cp_sparse_always_reflink_always() { .fails(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_cp_sparse_never_reflink_always() { let (at, mut ucmd) = at_and_ucmd!(); @@ -2754,7 +2754,7 @@ fn test_cp_sparse_never_reflink_always() { .fails(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[cfg(feature = "truncate")] #[test] fn test_cp_reflink_always_override() { @@ -4366,7 +4366,7 @@ fn test_acl_preserve() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4391,7 +4391,7 @@ fn test_cp_debug_reflink_never_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_empty_file_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4416,7 +4416,7 @@ fn test_cp_debug_reflink_never_empty_file_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_default_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4442,7 +4442,7 @@ fn test_cp_debug_default_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_default_less_than_512_bytes() { let ts = TestScenario::new(util_name!()); @@ -4465,7 +4465,7 @@ fn test_cp_debug_default_less_than_512_bytes() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_default_without_hole() { let ts = TestScenario::new(util_name!()); @@ -4485,7 +4485,7 @@ fn test_cp_debug_default_without_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_default_empty_file_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4511,7 +4511,7 @@ fn test_cp_debug_default_empty_file_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_sparse_always_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4537,7 +4537,7 @@ fn test_cp_debug_reflink_never_sparse_always_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_sparse_always_without_hole() { let ts = TestScenario::new(util_name!()); let empty_bytes = [0_u8; 10000]; @@ -4562,7 +4562,7 @@ fn test_cp_debug_reflink_never_sparse_always_without_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_sparse_always_empty_file_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4607,7 +4607,7 @@ fn test_cp_default_virtual_file() { assert!(dest_size > 0); } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_auto_sparse_always_non_sparse_file_with_long_zero_sequence() { let ts = TestScenario::new(util_name!()); @@ -4649,7 +4649,7 @@ fn test_cp_debug_sparse_never_empty_sparse_file() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_sparse_always_non_sparse_file_with_long_zero_sequence() { let ts = TestScenario::new(util_name!()); @@ -4700,7 +4700,7 @@ fn test_cp_debug_sparse_always_sparse_virtual_file() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_less_than_512_bytes() { let ts = TestScenario::new(util_name!()); @@ -4722,7 +4722,7 @@ fn test_cp_debug_reflink_never_less_than_512_bytes() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_sparse_never_empty_file_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4744,7 +4744,7 @@ fn test_cp_debug_reflink_never_sparse_never_empty_file_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_file_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4767,7 +4767,7 @@ fn test_cp_debug_reflink_never_file_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_sparse_never_less_than_512_bytes() { let ts = TestScenario::new(util_name!()); @@ -4790,7 +4790,7 @@ fn test_cp_debug_sparse_never_less_than_512_bytes() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_sparse_never_without_hole() { let ts = TestScenario::new(util_name!()); @@ -4812,7 +4812,7 @@ fn test_cp_debug_sparse_never_without_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_sparse_never_empty_file_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4834,7 +4834,7 @@ fn test_cp_debug_sparse_never_empty_file_with_hole() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_sparse_never_file_with_hole() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -4905,7 +4905,7 @@ fn test_cp_debug_default_zero_sized_virtual_file() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_cp_debug_reflink_never_without_hole() { let ts = TestScenario::new(util_name!()); let filler_bytes = [0_u8; 1000]; diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index ce0eec3d1a0..46a4c911f4e 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -55,7 +55,7 @@ macro_rules! assert_fixture_exists { }}; } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] macro_rules! assert_fixture_not_exists { ($fname:expr) => {{ let fpath = PathBuf::from(format!("./fixtures/dd/{}", $fname)); @@ -274,7 +274,7 @@ fn test_final_stats_unspec() { .stderr_contains("0.0 B/s"); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_excl_causes_failure_when_present() { let fname = "this-file-exists-excl.txt"; @@ -285,7 +285,7 @@ fn test_excl_causes_failure_when_present() { .fails(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_noatime_does_not_update_infile_atime() { // NOTE: Not all environments support tracking access time. If this @@ -305,7 +305,7 @@ fn test_noatime_does_not_update_infile_atime() { assert_eq!(pre_atime, post_atime); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_noatime_does_not_update_ofile_atime() { // NOTE: Not all environments support tracking access time. If this @@ -325,7 +325,7 @@ fn test_noatime_does_not_update_ofile_atime() { assert_eq!(pre_atime, post_atime); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_nocreat_causes_failure_when_outfile_not_present() { let fname = "this-file-does-not-exist.txt"; @@ -1726,7 +1726,7 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_iflag_directory_fails_when_file_is_passed_via_std_in() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -1740,7 +1740,7 @@ fn test_iflag_directory_fails_when_file_is_passed_via_std_in() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_iflag_directory_passes_when_dir_is_redirected() { new_ucmd!() .args(&["iflag=directory", "count=0"]) @@ -1749,7 +1749,7 @@ fn test_iflag_directory_passes_when_dir_is_redirected() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_iflag_directory_fails_when_file_is_piped_via_std_in() { new_ucmd!() .arg("iflag=directory") @@ -1842,7 +1842,7 @@ fn test_no_dropped_writes() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_oflag_direct_partial_block() { // Test for issue #9003: dd should handle partial blocks with oflag=direct // This reproduces the scenario where writing a partial block with O_DIRECT fails diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index c89cd46678c..309190161b8 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -33,7 +33,7 @@ fn test_du_basics() { let result = ts.ucmd().succeeds(); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &[])); if result_reference.succeeded() { @@ -96,7 +96,7 @@ fn test_du_basics_subdir() { let result = ts.ucmd().arg(SUB_DIR).succeeds(); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR])); if result_reference.succeeded() { @@ -421,7 +421,7 @@ fn test_du_soft_link() { let result = ts.ucmd().arg("subdir/links").succeeds(); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &["subdir/links"])); if result_reference.succeeded() { @@ -539,7 +539,7 @@ fn test_du_d_flag() { let result = ts.ucmd().arg("-d1").succeeds(); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &["-d1"])); if result_reference.succeeded() { @@ -587,7 +587,7 @@ fn test_du_dereference() { let result = ts.ucmd().arg("-L").arg(SUB_DIR_LINKS).succeeds(); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &["-L", SUB_DIR_LINKS])); @@ -741,7 +741,7 @@ fn test_du_inodes() { result.stdout_contains("3\t./subdir/links\n"); result.stdout_contains("3\t.\n"); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &["--separate-dirs", "--inodes"])); @@ -1061,7 +1061,7 @@ fn test_du_no_permission() { let result = ts.ucmd().arg(SUB_DIR_LINKS).fails(); result.stderr_contains("du: cannot read directory 'subdir/links': Permission denied"); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR_LINKS])); if result_reference @@ -1106,7 +1106,7 @@ fn test_du_one_file_system() { let result = ts.ucmd().arg("-x").arg("subdir/deeper").succeeds(); - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { let result_reference = unwrap_or_return!(expected_result(&ts, &["-x", "subdir/deeper"])); if result_reference.succeeded() { diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index ec96e3c23e8..c3a17be40d2 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -152,7 +152,7 @@ fn test_id_real() { } #[test] -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] fn test_id_pretty_print() { // `-p` is BSD only and not supported on GNU's `id` let username = whoami(); @@ -161,7 +161,7 @@ fn test_id_pretty_print() { } #[test] -#[cfg(not(any(target_os = "linux", target_os = "android")))] +#[cfg(not(linux_android))] fn test_id_password_style() { // `-P` is BSD only and not supported on GNU's `id` let username = whoami(); @@ -453,10 +453,7 @@ fn test_id_no_specified_user_posixly() { result.success(); } - #[cfg(all( - any(target_os = "linux", target_os = "android"), - feature = "feat_selinux" - ))] + #[cfg(all(linux_android, feature = "feat_selinux"))] { if uucore::selinux::is_selinux_enabled() { let result = ts.ucmd().succeeds(); diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 7a2ccb87595..b815de4786c 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -12,7 +12,7 @@ use std::os::unix::ffi::OsStringExt; use std::os::unix::fs::{MetadataExt, PermissionsExt}; #[cfg(not(windows))] use std::process::Command; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use std::thread::sleep; use uucore::process::{getegid, geteuid}; #[cfg(feature = "feat_selinux")] @@ -490,7 +490,7 @@ fn test_install_copy_file() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_install_target_file_dev_null() { let (at, mut ucmd) = at_and_ucmd!(); @@ -687,7 +687,7 @@ fn test_install_copy_then_compare_file() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_install_copy_then_compare_file_with_extra_mode() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 41b72af6b04..3ee8b623239 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -472,7 +472,7 @@ fn test_ls_devices() { .stdout_matches(&Regex::new("[^ ] 3, 2 [^ ]").unwrap()); } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] { scene .ucmd() diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 5592f9c1e5c..1045abf6035 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1569,7 +1569,7 @@ fn test_mv_verbose() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either. +#[cfg(linux_android)] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either. #[cfg(feature = "mkdir")] fn test_mv_permission_error() { let scene = TestScenario::new("mkdir"); diff --git a/tests/by-util/test_rmdir.rs b/tests/by-util/test_rmdir.rs index 669884488a0..597da526c41 100644 --- a/tests/by-util/test_rmdir.rs +++ b/tests/by-util/test_rmdir.rs @@ -219,7 +219,7 @@ fn test_rmdir_remove_symlink_file() { } // This behavior is known to happen on Linux but not all Unixes -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_rmdir_remove_symlink_dir() { let (at, mut ucmd) = at_and_ucmd!(); @@ -232,7 +232,7 @@ fn test_rmdir_remove_symlink_dir() { .stderr_is("rmdir: failed to remove 'dl/': Symbolic link not followed\n"); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_rmdir_remove_symlink_dangling() { let (at, mut ucmd) = at_and_ucmd!(); @@ -244,7 +244,7 @@ fn test_rmdir_remove_symlink_dangling() { .stderr_is("rmdir: failed to remove 'dl/': Symbolic link not followed\n"); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_rmdir_remove_symlink_dir_with_trailing_slashes() { // a symlink with trailing slashes should still be printing the 'Symbolic link not followed' diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index e794898a286..484e2b72908 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -1065,7 +1065,7 @@ fn sort_empty_chunk() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_compress() { new_ucmd!() .args(&[ @@ -1081,7 +1081,7 @@ fn test_compress() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_compress_merge() { new_ucmd!() .args(&[ @@ -1192,7 +1192,7 @@ fn test_merge_batch_size() { #[test] // TODO(#7542): Re-enable on Android once we figure out why setting limit is broken. -// #[cfg(any(target_os = "linux", target_os = "android"))] +// #[cfg(linux_android)] #[cfg(target_os = "linux")] fn test_merge_batch_size_with_limit() { use rlimit::Resource; diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 497559aca3e..9573e4c75f7 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -6,7 +6,7 @@ use rand::{Rng, SeedableRng, rng}; use regex::Regex; -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] use rlimit::Resource; #[cfg(not(windows))] use std::env; @@ -1666,7 +1666,7 @@ fn test_round_robin() { #[test] // TODO(#7542): Re-enable on Android once we figure out why rlimit is broken. -// #[cfg(any(target_os = "linux", target_os = "android"))] +// #[cfg(linux_android)] #[cfg(target_os = "linux")] fn test_round_robin_limited_file_descriptors() { new_ucmd!() diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs index 8347d49c795..88a7b059af5 100644 --- a/tests/by-util/test_stat.rs +++ b/tests/by-util/test_stat.rs @@ -25,14 +25,14 @@ fn test_invalid_option() { #[cfg(unix)] const NORMAL_FORMAT_STR: &str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %x %X %y %Y %z %Z"; // avoid "%w %W" (birth/creation) due to `stat` limitations and linux kernel & rust version capability variations -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] const DEV_FORMAT_STR: &str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z"; #[cfg(target_os = "linux")] const FS_FORMAT_STR: &str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f" which can cause test failure due to race conditions #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_terse_fs_format() { let args = ["-f", "-t", "/proc"]; let ts = TestScenario::new(util_name!()); @@ -180,7 +180,7 @@ fn test_char() { // >"(f) (2021-05-20 23:08:03.455598000 +0200) (-)\n" let args = [ "-c", - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] DEV_FORMAT_STR, #[cfg(target_os = "linux")] "/dev/pts/ptmx", @@ -262,7 +262,7 @@ fn test_date() { // Just test the date for the time 0.3 change let args = [ "-c", - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] "%z", #[cfg(target_os = "linux")] "/bin/sh", @@ -277,7 +277,7 @@ fn test_date() { // Just test the date for the time 0.3 change let args = [ "-c", - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(linux_android)] "%z", #[cfg(target_os = "linux")] "/dev/ptmx", diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index c2b8a77e5a2..8d35429eff8 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -325,7 +325,7 @@ fn test_row_column_hex_octal() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn line() { new_ucmd!() .args(&["line"]) diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 9c3df3a1e61..9b159450db5 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -56,7 +56,7 @@ fn test_sync_data_but_not_file() { .stderr_contains("sync: --data needs at least one argument"); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[cfg(feature = "chmod")] #[test] fn test_sync_no_permission_dir() { @@ -91,7 +91,7 @@ fn test_sync_no_permission_file() { ts.ucmd().arg(f).succeeds(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_sync_data_nonblock_flag_reset() { // Test that O_NONBLOCK flag is properly reset when syncing files @@ -109,7 +109,7 @@ fn test_sync_data_nonblock_flag_reset() { ts.ucmd().arg("--data").arg(test_file).succeeds(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_sync_fs_nonblock_flag_reset() { // Test that O_NONBLOCK flag is properly reset when syncing filesystems @@ -126,7 +126,7 @@ fn test_sync_fs_nonblock_flag_reset() { .succeeds(); } -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] #[test] fn test_sync_fdatasync_error_handling() { // Test that fdatasync properly handles file opening errors diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index d62c1da6e8e..a9b3c3ecece 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -476,7 +476,7 @@ fn test_read_from_nonexistent_file() { } #[test] -#[cfg(any(target_os = "linux", target_os = "android"))] +#[cfg(linux_android)] fn test_files_from_pseudo_filesystem() { use pretty_assertions::assert_ne; let result = new_ucmd!().arg("-c").arg("/proc/cpuinfo").succeeds();