diff --git a/Cargo.lock b/Cargo.lock index 478e55e0b08..a818a10faca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -542,6 +542,7 @@ name = "coreutils" version = "0.6.0" dependencies = [ "bytecount", + "cfg_aliases", "clap", "clap_complete", "clap_mangen", @@ -3296,6 +3297,7 @@ dependencies = [ name = "uu_cp" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "codspeed-divan-compat", "exacl", @@ -3563,6 +3565,7 @@ dependencies = [ name = "uu_id" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "selinux", @@ -3573,6 +3576,7 @@ dependencies = [ name = "uu_install" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "file_diff", "filetime", @@ -3639,6 +3643,7 @@ name = "uu_ls" version = "0.6.0" dependencies = [ "ansi-width", + "cfg_aliases", "clap", "codspeed-divan-compat", "fluent", @@ -3668,6 +3673,7 @@ dependencies = [ name = "uu_mkdir" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "uucore", @@ -3677,6 +3683,7 @@ dependencies = [ name = "uu_mkfifo" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "nix", @@ -3687,6 +3694,7 @@ dependencies = [ name = "uu_mknod" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "nix", @@ -3720,6 +3728,7 @@ dependencies = [ name = "uu_mv" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "codspeed-divan-compat", "fluent", @@ -4073,6 +4082,7 @@ dependencies = [ name = "uu_stat" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "thiserror 2.0.18", @@ -4083,6 +4093,7 @@ dependencies = [ name = "uu_stdbuf" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "tempfile", @@ -4385,6 +4396,7 @@ dependencies = [ "blake2b_simd", "blake3", "bstr", + "cfg_aliases", "clap", "codspeed-divan-compat", "crc-fast", diff --git a/Cargo.toml b/Cargo.toml index 1aa3892798e..5362b4cdb3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -318,6 +318,7 @@ binary-heap-plus = "0.5.0" bstr = "1.9.1" bytecount = "0.6.8" byteorder = "1.5.0" +cfg_aliases = "0.2.1" clap = { version = "4.5", features = ["wrap_help", "cargo", "color"] } clap_complete = "4.4" clap_mangen = "0.2" @@ -416,6 +417,10 @@ uu_base32 = { version = "0.6.0", path = "src/uu/base32" } uu_checksum_common = { version = "0.6.0", path = "src/uu/checksum_common" } uutests = { version = "0.6.0", package = "uutests", path = "tests/uutests" } +[build-dependencies] +cfg_aliases.workspace = true +phf_codegen.workspace = true + [dependencies] clap_complete = { workspace = true, optional = true } clap_mangen = { workspace = true, optional = true } @@ -588,9 +593,6 @@ nix = { workspace = true, features = [ rlimit = { workspace = true } -[build-dependencies] -phf_codegen.workspace = true - [[bin]] name = "coreutils" path = "src/bin/coreutils.rs" diff --git a/build.rs b/build.rs index 9534a79b80d..4c9754df47d 100644 --- a/build.rs +++ b/build.rs @@ -10,7 +10,14 @@ use std::fs::File; use std::io::Write; use std::path::Path; +use cfg_aliases::cfg_aliases; + pub fn main() { + cfg_aliases! { + external_libstdbuf: { feature = "feat_external_libstdbuf" }, + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + } + const ENV_FEATURE_PREFIX: &str = "CARGO_FEATURE_"; const FEATURE_PREFIX: &str = "feat_"; const OVERRIDE_PREFIX: &str = "uu_"; diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 520fd775028..a3764139978 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -1933,6 +1933,7 @@ dependencies = [ "bigdecimal", "blake2b_simd", "blake3", + "cfg_aliases", "clap", "crc-fast", "data-encoding", diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index 79e00d6bb0b..c7b35aa7219 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/cp.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } filetime = { workspace = true } diff --git a/src/uu/cp/build.rs b/src/uu/cp/build.rs new file mode 100644 index 00000000000..540db12d085 --- /dev/null +++ b/src/uu/cp/build.rs @@ -0,0 +1,13 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + acl: { feature = "feat_acl" }, + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index 8241d1310b4..72655842849 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -26,7 +26,7 @@ use uucore::translate; use uucore::uio_error; use walkdir::{DirEntry, WalkDir}; -#[cfg(all(feature = "selinux", target_os = "linux"))] +#[cfg(selinux)] use crate::set_selinux_context; use crate::{ CopyMode, CopyResult, CpError, Options, aligned_ancestors, context_for, copy_attributes, @@ -562,7 +562,7 @@ pub(crate) fn copy_directory( options.set_selinux_context, )?; - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(&dir.dest, options.context.as_ref())?; } @@ -582,7 +582,7 @@ pub(crate) fn copy_directory( options.set_selinux_context, )?; - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(y, options.context.as_ref())?; } diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 3c3b057098e..d34a99bb2da 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -896,11 +896,11 @@ impl Attributes { mode: Preserve::Yes { required: true }, timestamps: Preserve::Yes { required: true }, context: { - #[cfg(feature = "feat_selinux")] + #[cfg(selinux)] { Preserve::Yes { required: false } } - #[cfg(not(feature = "feat_selinux"))] + #[cfg(not(selinux))] { Preserve::No { explicit: false } } @@ -1141,7 +1141,7 @@ impl Options { } } - #[cfg(not(feature = "selinux"))] + #[cfg(not(selinux))] if let Preserve::Yes { required } = attributes.context { let selinux_disabled_error = CpError::Error(translate!("cp-error-selinux-not-enabled")); if required { @@ -1692,7 +1692,7 @@ fn handle_preserve CopyResult<()>>(p: Preserve, f: F) -> CopyResult<( Ok(()) } -#[cfg(all(feature = "selinux", target_os = "linux"))] +#[cfg(selinux)] pub(crate) fn set_selinux_context(path: &Path, context: Option<&String>) -> CopyResult<()> { if !uucore::selinux::is_selinux_enabled() { return Ok(()); @@ -1825,7 +1825,7 @@ pub(crate) fn copy_attributes( fs::set_permissions(dest, source_metadata.permissions()) .map_err(|e| CpError::IoErrContext(e, context.to_owned()))?; // FIXME: Implement this for windows as well - #[cfg(feature = "feat_acl")] + #[cfg(acl)] exacl::getfacl(source, None) .and_then(|acl| exacl::setfacl(&[dest], &acl, None)) .map_err(|err| CpError::Error(err.to_string()))?; @@ -1846,7 +1846,7 @@ pub(crate) fn copy_attributes( Ok(()) })?; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] 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) { @@ -2658,7 +2658,7 @@ fn copy_file( fs::File::create(dest).map(|f| f.set_len(0)).ok(); })?; - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(dest, options.context.as_ref())?; } diff --git a/src/uu/id/Cargo.toml b/src/uu/id/Cargo.toml index ce31a65f5e9..8e585ff4f6b 100644 --- a/src/uu/id/Cargo.toml +++ b/src/uu/id/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/id.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["entries", "process"] } diff --git a/src/uu/id/build.rs b/src/uu/id/build.rs new file mode 100644 index 00000000000..919eba80b65 --- /dev/null +++ b/src/uu/id/build.rs @@ -0,0 +1,13 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "feat_smack", target_os = "linux") }, + } +} diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index d15101a46a4..b6814a6f92e 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -63,9 +63,9 @@ macro_rules! cstr2cow { } fn get_context_help_text() -> String { - #[cfg(not(any(feature = "selinux", feature = "smack")))] + #[cfg(not(any(selinux, smack)))] return translate!("id-context-help-disabled"); - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] return translate!("id-context-help-enabled"); } @@ -99,9 +99,9 @@ struct State { rflag: bool, // --real zflag: bool, // --zero cflag: bool, // --context - #[cfg(feature = "selinux")] + #[cfg(selinux)] selinux_supported: bool, - #[cfg(feature = "smack")] + #[cfg(smack)] smack_supported: bool, ids: Option, // The behavior for calling GNU's `id` and calling GNU's `id $USER` is similar but different. @@ -141,9 +141,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { zflag: matches.get_flag(options::OPT_ZERO), cflag: matches.get_flag(options::OPT_CONTEXT), - #[cfg(feature = "selinux")] + #[cfg(selinux)] selinux_supported: uucore::selinux::is_selinux_enabled(), - #[cfg(feature = "smack")] + #[cfg(smack)] smack_supported: uucore::smack::is_smack_enabled(), user_specified: !users.is_empty(), ids: None, @@ -179,7 +179,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if state.cflag { // SELinux context - #[cfg(feature = "selinux")] + #[cfg(selinux)] if state.selinux_supported { if let Ok(context) = selinux::SecurityContext::current(false) { let bytes = context.as_bytes(); @@ -193,7 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // SMACK label - #[cfg(feature = "smack")] + #[cfg(smack)] if state.smack_supported { match uucore::smack::get_smack_label_for_self() { Ok(label) => { @@ -702,7 +702,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { .join(",") )?; - #[cfg(feature = "selinux")] + #[cfg(selinux)] if state.selinux_supported && !state.user_specified && std::env::var_os("POSIXLY_CORRECT").is_none() @@ -714,7 +714,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { } } - #[cfg(feature = "smack")] + #[cfg(smack)] if state.smack_supported && !state.user_specified && std::env::var_os("POSIXLY_CORRECT").is_none() diff --git a/src/uu/install/Cargo.toml b/src/uu/install/Cargo.toml index 41d1af3d1eb..7b41254ecf1 100644 --- a/src/uu/install/Cargo.toml +++ b/src/uu/install/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/install.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } filetime = { workspace = true } diff --git a/src/uu/install/build.rs b/src/uu/install/build.rs new file mode 100644 index 00000000000..33210df4a9a --- /dev/null +++ b/src/uu/install/build.rs @@ -0,0 +1,12 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 1277e822a42..1aa583bb7c0 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(selinux)] use selinux::SecurityContext; use std::ffi::OsString; use std::fmt::Debug; @@ -30,7 +30,7 @@ use uucore::perms::{Verbosity, VerbosityLevel, wrap_chown}; use uucore::process::{getegid, geteuid}; #[cfg(unix)] use uucore::safe_traversal::{DirFd, SymlinkBehavior, create_dir_all_safe}; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] use uucore::selinux::{ SeLinuxError, contexts_differ, get_selinux_security_context, is_selinux_enabled, selinux_error_description, set_selinux_security_context, @@ -121,7 +121,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(selinux)] #[error("{}", .0)] SelinuxContextFailed(String), } @@ -492,7 +492,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if should_set_selinux_context(b) { let context = get_context_for_selinux(b); set_selinux_context_for_directories_install(path_to_create.as_path(), context); @@ -517,7 +517,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> { show_if_err!(chown_optional_user_group(path, b)); // Set SELinux context for directory if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if b.default_context { show_if_err!(set_selinux_default_context(path)); } else if b.context.is_some() { @@ -689,7 +689,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if should_set_selinux_context(b) { let context = get_context_for_selinux(b); set_selinux_context_for_directories_install(to_create, context); @@ -723,7 +723,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if should_set_selinux_context(b) { let context = get_context_for_selinux(b); set_selinux_context_for_directories_install(to_create, context); @@ -1096,7 +1096,7 @@ fn finalize_installed_file( preserve_timestamps(from, to)?; } - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if !b.unprivileged { if b.preserve_context { uucore::selinux::preserve_security_context(from, to) @@ -1155,7 +1155,7 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> { finalize_installed_file(from, to, b, backup_path) } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] fn get_context_for_selinux(b: &Behavior) -> Option<&String> { if b.default_context { None @@ -1164,7 +1164,7 @@ fn get_context_for_selinux(b: &Behavior) -> Option<&String> { } } -#[cfg(all(feature = "selinux", target_os = "linux"))] +#[cfg(selinux)] fn should_set_selinux_context(b: &Behavior) -> bool { !b.unprivileged && (b.context.is_some() || b.default_context) } @@ -1259,7 +1259,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool { return true; } - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if !b.unprivileged && b.preserve_context && contexts_differ(from, to) { return true; } @@ -1290,7 +1290,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool { false } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Sets the `SELinux` security context for install's -Z flag behavior. /// /// This function implements the specific behavior needed for install's -Z flag, @@ -1324,7 +1324,7 @@ pub fn set_selinux_default_context(path: &Path) -> Result<(), SeLinuxError> { } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// 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 @@ -1380,7 +1380,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(selinux)] /// Derives an appropriate `SELinux` context based on a parent directory context. /// /// This is a heuristic function that attempts to generate an appropriate @@ -1418,7 +1418,7 @@ fn derive_context_from_parent(parent_context: &str) -> String { } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Helper function to collect paths that need `SELinux` context setting. /// /// Traverses from the given starting path up to existing parent directories. @@ -1432,7 +1432,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(selinux)] /// Sets the `SELinux` security context for a directory hierarchy. /// /// This function traverses from the given starting path up to existing parent directories @@ -1472,7 +1472,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(selinux)] /// Sets `SELinux` context for created directories using install's -Z default behavior. /// /// Similar to `set_selinux_context_for_directories` but uses install's @@ -1496,10 +1496,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(selinux)] use super::derive_context_from_parent; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] #[test] fn test_derive_context_from_parent() { // Test cases: (input_context, file_type, expected_output, description) diff --git a/src/uu/ls/Cargo.toml b/src/uu/ls/Cargo.toml index a82ad13c397..4ab2d3bb1da 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -20,6 +20,9 @@ workspace = true [lib] path = "src/ls.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] ansi-width = { workspace = true } clap = { workspace = true, features = ["env"] } diff --git a/src/uu/ls/build.rs b/src/uu/ls/build.rs new file mode 100644 index 00000000000..919eba80b65 --- /dev/null +++ b/src/uu/ls/build.rs @@ -0,0 +1,13 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "feat_smack", target_os = "linux") }, + } +} diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index afbd8f307a1..1c695618184 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -375,9 +375,9 @@ 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(selinux)] selinux_supported: bool, - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] smack_supported: bool, group_directories_first: bool, line_ending: LineEnding, @@ -1237,9 +1237,9 @@ impl Config { time_format_recent, time_format_older, context, - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] selinux_supported: uucore::selinux::is_selinux_enabled(), - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] smack_supported: uucore::smack::is_smack_enabled(), group_directories_first: options.get_flag(options::GROUP_DIRECTORIES_FIRST), line_ending: LineEnding::from_zero_flag(options.get_flag(options::ZERO)), @@ -3595,7 +3595,7 @@ fn get_security_context<'a>( } } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if config.selinux_supported { match selinux::SecurityContext::of_path(path, must_dereference, false) { Err(_r) => { @@ -3633,7 +3633,7 @@ fn get_security_context<'a>( } } - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] if config.smack_supported { // For SMACK, use the path to get the label // If must_dereference is true, we follow the symlink diff --git a/src/uu/mkdir/Cargo.toml b/src/uu/mkdir/Cargo.toml index 6e2e082d044..5495c10c1d3 100644 --- a/src/uu/mkdir/Cargo.toml +++ b/src/uu/mkdir/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/mkdir.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["fs", "mode", "fsxattr"] } diff --git a/src/uu/mkdir/build.rs b/src/uu/mkdir/build.rs new file mode 100644 index 00000000000..919eba80b65 --- /dev/null +++ b/src/uu/mkdir/build.rs @@ -0,0 +1,13 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "feat_smack", target_os = "linux") }, + } +} diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 3d0a9bc33c9..9bdc5467493 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -333,7 +333,7 @@ fn create_single_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<( } // Apply SELinux context if requested - #[cfg(feature = "selinux")] + #[cfg(selinux)] if config.set_security_context && uucore::selinux::is_selinux_enabled() { if let Err(e) = uucore::selinux::set_selinux_security_context(path, config.context) { @@ -343,7 +343,7 @@ fn create_single_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<( } // Apply SMACK context if requested - #[cfg(feature = "smack")] + #[cfg(smack)] if config.set_security_context { uucore::smack::set_smack_label_and_cleanup(path, config.context, |p| { std::fs::remove_dir(p) diff --git a/src/uu/mkfifo/Cargo.toml b/src/uu/mkfifo/Cargo.toml index 594b91ae764..e9ec8320e26 100644 --- a/src/uu/mkfifo/Cargo.toml +++ b/src/uu/mkfifo/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/mkfifo.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["fs", "mode"] } diff --git a/src/uu/mkfifo/build.rs b/src/uu/mkfifo/build.rs new file mode 100644 index 00000000000..919eba80b65 --- /dev/null +++ b/src/uu/mkfifo/build.rs @@ -0,0 +1,13 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "feat_smack", target_os = "linux") }, + } +} diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index a70d140c7c6..ede515beb5c 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(selinux)] { // Extract the SELinux related flags and options let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); @@ -83,7 +83,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // Apply SMACK context if requested - #[cfg(feature = "smack")] + #[cfg(smack)] { let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); let context = matches.get_one::(options::CONTEXT); diff --git a/src/uu/mknod/Cargo.toml b/src/uu/mknod/Cargo.toml index 2bdcfe5ad91..59bd12242b3 100644 --- a/src/uu/mknod/Cargo.toml +++ b/src/uu/mknod/Cargo.toml @@ -19,6 +19,9 @@ workspace = true name = "uu_mknod" path = "src/mknod.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["mode", "fs"] } diff --git a/src/uu/mknod/build.rs b/src/uu/mknod/build.rs new file mode 100644 index 00000000000..919eba80b65 --- /dev/null +++ b/src/uu/mknod/build.rs @@ -0,0 +1,13 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "feat_smack", target_os = "linux") }, + } +} diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 9b6ab45f648..37c08cf173c 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -57,11 +57,11 @@ struct Config { dev: u64, /// Set security context (SELinux/SMACK). - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] set_security_context: bool, /// Specific security context (SELinux/SMACK). - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] context: Option, } @@ -96,7 +96,7 @@ fn mknod(file_name: &str, config: Config) -> i32 { } // Apply SELinux context if requested - #[cfg(feature = "selinux")] + #[cfg(selinux)] if config.set_security_context { if let Err(e) = uucore::selinux::set_selinux_security_context( std::path::Path::new(file_name), @@ -110,7 +110,7 @@ fn mknod(file_name: &str, config: Config) -> i32 { } // Apply SMACK context if requested - #[cfg(feature = "smack")] + #[cfg(smack)] if config.set_security_context { if let Err(e) = uucore::smack::set_smack_label_and_cleanup(file_name, config.context.as_ref(), |p| { @@ -146,9 +146,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .expect("Missing argument 'NAME'"); // Extract the security context related flags and options - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] let context = matches.get_one::(options::CONTEXT).cloned(); let dev = match ( @@ -177,9 +177,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { file_type: file_type.clone(), use_umask, dev, - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] set_security_context: set_security_context || context.is_some(), - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] context, }; diff --git a/src/uu/mv/Cargo.toml b/src/uu/mv/Cargo.toml index 5cba2d472ae..84d5f0ffbef 100644 --- a/src/uu/mv/Cargo.toml +++ b/src/uu/mv/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/mv.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } fs_extra = { workspace = true } diff --git a/src/uu/mv/build.rs b/src/uu/mv/build.rs new file mode 100644 index 00000000000..33210df4a9a --- /dev/null +++ b/src/uu/mv/build.rs @@ -0,0 +1,12 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 42e1a9f127e..85b0da724cc 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -47,7 +47,7 @@ use uucore::fs::{ }; #[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))] use uucore::fsxattr; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] use uucore::selinux::set_selinux_security_context; use uucore::translate; use uucore::update_control; @@ -770,7 +770,7 @@ fn rename( rename_with_fallback(from, to, display_manager, opts.verbose, None, None)?; } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if let Some(ref context) = opts.context { set_selinux_security_context(to, Some(context)) .map_err(|e| io::Error::other(e.to_string()))?; diff --git a/src/uu/stat/Cargo.toml b/src/uu/stat/Cargo.toml index d01a713ec3c..d777ec95ccc 100644 --- a/src/uu/stat/Cargo.toml +++ b/src/uu/stat/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/stat.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = [ diff --git a/src/uu/stat/build.rs b/src/uu/stat/build.rs new file mode 100644 index 00000000000..33210df4a9a --- /dev/null +++ b/src/uu/stat/build.rs @@ -0,0 +1,12 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index a565f008631..0f1207c681c 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -1033,8 +1033,8 @@ impl Stater { file: &OsString, file_type: FileType, from_user: bool, - #[cfg(feature = "selinux")] follow_symbolic_links: bool, - #[cfg(not(feature = "selinux"))] _: bool, + #[cfg(selinux)] follow_symbolic_links: bool, + #[cfg(not(selinux))] _: bool, ) -> Result<(), i32> { match *t { Token::Byte(byte) => write_raw_byte(byte), @@ -1060,10 +1060,7 @@ impl Stater { 'B' => OutputType::Unsigned(512), // SELinux security context string 'C' => { - #[cfg(all( - feature = "selinux", - any(target_os = "linux", target_os = "android") - ))] + #[cfg(selinux)] { if uucore::selinux::is_selinux_enabled() { match uucore::selinux::get_selinux_security_context( @@ -1079,10 +1076,7 @@ impl Stater { OutputType::Str(translate!("stat-selinux-unsupported-system")) } } - #[cfg(not(all( - feature = "selinux", - any(target_os = "linux", target_os = "android") - )))] + #[cfg(not(selinux))] { OutputType::Str(translate!("stat-selinux-unsupported-os")) } diff --git a/src/uu/stdbuf/Cargo.toml b/src/uu/stdbuf/Cargo.toml index b0742e89db5..5d5dfe326de 100644 --- a/src/uu/stdbuf/Cargo.toml +++ b/src/uu/stdbuf/Cargo.toml @@ -19,6 +19,9 @@ workspace = true [lib] path = "src/stdbuf.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } libstdbuf = { package = "uu_stdbuf_libstdbuf", version = "0.6.0", path = "src/libstdbuf" } diff --git a/src/uu/stdbuf/build.rs b/src/uu/stdbuf/build.rs index 43eea3f38b9..c4069d548c7 100644 --- a/src/uu/stdbuf/build.rs +++ b/src/uu/stdbuf/build.rs @@ -9,6 +9,8 @@ use std::fs; use std::path::Path; use std::process::Command; +use cfg_aliases::cfg_aliases; + #[cfg(any( target_os = "linux", target_os = "android", @@ -32,6 +34,10 @@ mod platform { } fn main() { + cfg_aliases! { + external_libstdbuf: { feature = "feat_external_libstdbuf" }, + } + println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=src/libstdbuf/src/libstdbuf.rs"); diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index b5a8965cc72..dd10f7150e4 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -30,7 +30,7 @@ mod options { } #[cfg(all( - not(feature = "feat_external_libstdbuf"), + not(external_libstdbuf), any( target_os = "linux", target_os = "android", @@ -42,10 +42,10 @@ mod options { ))] const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so")); -#[cfg(all(not(feature = "feat_external_libstdbuf"), target_vendor = "apple"))] +#[cfg(all(not(external_libstdbuf), target_vendor = "apple"))] const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.dylib")); -#[cfg(all(not(feature = "feat_external_libstdbuf"), target_os = "cygwin"))] +#[cfg(all(not(external_libstdbuf), target_os = "cygwin"))] const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.dll")); enum BufferType { @@ -158,7 +158,7 @@ fn set_command_env(command: &mut process::Command, buffer_name: &str, buffer_typ } } -#[cfg(not(feature = "feat_external_libstdbuf"))] +#[cfg(not(external_libstdbuf))] fn get_preload_env(tmp_dir: &TempDir) -> UResult<(String, PathBuf)> { use std::fs::File; use std::io::Write; @@ -172,7 +172,7 @@ fn get_preload_env(tmp_dir: &TempDir) -> UResult<(String, PathBuf)> { Ok((preload.to_owned(), inject_path)) } -#[cfg(feature = "feat_external_libstdbuf")] +#[cfg(external_libstdbuf)] fn get_preload_env(_tmp_dir: &TempDir) -> UResult<(String, PathBuf)> { let (preload, extension) = preload_strings()?; diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 29a7189d444..66f3dd19416 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -22,6 +22,9 @@ workspace = true [lib] path = "src/lib/lib.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] bstr = { workspace = true, optional = true } clap = { workspace = true } diff --git a/src/uucore/build.rs b/src/uucore/build.rs index 15068f28aab..cb654dfc618 100644 --- a/src/uucore/build.rs +++ b/src/uucore/build.rs @@ -3,12 +3,22 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +// spell-checker:ignore logind + use std::env; use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; +use cfg_aliases::cfg_aliases; + pub fn main() -> Result<(), Box> { + cfg_aliases! { + selinux: { all(feature = "feat_selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "feat_smack", target_os = "linux") }, + systemd_logind: { all(feature = "feat_systemd_logind", target_os = "linux") }, + } + 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..86c7a2d2f7c 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -81,13 +81,13 @@ pub mod tty; pub mod fsxattr; #[cfg(feature = "hardware")] pub mod hardware; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] pub mod selinux; #[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))] pub mod signals; -#[cfg(all(target_os = "linux", feature = "smack"))] +#[cfg(smack)] pub mod smack; -#[cfg(feature = "feat_systemd_logind")] +#[cfg(systemd_logind)] pub mod systemd_logind; #[cfg(all( unix, diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 8360a59c182..f491dce145b 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -41,7 +41,7 @@ use std::path::Path; use std::ptr; use std::sync::{Mutex, MutexGuard}; -#[cfg(feature = "feat_systemd_logind")] +#[cfg(systemd_logind)] use crate::features::systemd_logind; pub use self::ut::*; @@ -313,13 +313,13 @@ impl Utmpx { /// Only one instance of [`UtmpxIter`] may be active at a time. This /// function will block as long as one is still active. Beware! pub fn iter_all_records() -> UtmpxIter { - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] { // Use systemd-logind instead of traditional utmp when feature is enabled UtmpxIter::new_systemd() } - #[cfg(not(feature = "feat_systemd_logind"))] + #[cfg(not(systemd_logind))] { let iter = UtmpxIter::new(); unsafe { @@ -345,7 +345,7 @@ impl Utmpx { /// /// The same caveats as for [`Utmpx::iter_all_records`] apply. pub fn iter_all_records_from>(path: P) -> UtmpxIter { - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] { // Use systemd-logind for default utmp file when feature is enabled if path.as_ref() == Path::new(DEFAULT_FILE) { @@ -389,7 +389,7 @@ pub struct UtmpxIter { /// Ensure UtmpxIter is !Send. Technically redundant because MutexGuard /// is also !Send. phantom: PhantomData>, - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] systemd_iter: Option, } @@ -402,12 +402,12 @@ impl UtmpxIter { Self { guard, phantom: PhantomData, - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] systemd_iter: None, } } - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] fn new_systemd() -> Self { // PoisonErrors can safely be ignored let guard = LOCK @@ -432,7 +432,7 @@ impl UtmpxIter { /// Wrapper type that can hold either traditional utmpx records or systemd records pub enum UtmpxRecord { Traditional(Box), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Systemd(systemd_logind::SystemdUtmpxCompat), } @@ -441,7 +441,7 @@ impl UtmpxRecord { pub fn record_type(&self) -> i16 { match self { Self::Traditional(utmpx) => utmpx.record_type(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.record_type(), } } @@ -450,7 +450,7 @@ impl UtmpxRecord { pub fn pid(&self) -> i32 { match self { Self::Traditional(utmpx) => utmpx.pid(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.pid(), } } @@ -459,7 +459,7 @@ impl UtmpxRecord { pub fn terminal_suffix(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.terminal_suffix(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.terminal_suffix(), } } @@ -468,7 +468,7 @@ impl UtmpxRecord { pub fn user(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.user(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.user(), } } @@ -477,7 +477,7 @@ impl UtmpxRecord { pub fn host(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.host(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.host(), } } @@ -486,7 +486,7 @@ impl UtmpxRecord { pub fn tty_device(&self) -> String { match self { Self::Traditional(utmpx) => utmpx.tty_device(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.tty_device(), } } @@ -495,7 +495,7 @@ impl UtmpxRecord { pub fn login_time(&self) -> time::OffsetDateTime { match self { Self::Traditional(utmpx) => utmpx.login_time(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.login_time(), } } @@ -506,7 +506,7 @@ impl UtmpxRecord { pub fn exit_status(&self) -> (i16, i16) { match self { Self::Traditional(utmpx) => utmpx.exit_status(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.exit_status(), } } @@ -515,7 +515,7 @@ impl UtmpxRecord { pub fn is_user_process(&self) -> bool { match self { Self::Traditional(utmpx) => utmpx.is_user_process(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => systemd.is_user_process(), } } @@ -524,7 +524,7 @@ impl UtmpxRecord { pub fn canon_host(&self) -> IOResult { match self { Self::Traditional(utmpx) => utmpx.canon_host(), - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] Self::Systemd(systemd) => Ok(systemd.canon_host()), } } @@ -533,7 +533,7 @@ impl UtmpxRecord { impl Iterator for UtmpxIter { type Item = UtmpxRecord; fn next(&mut self) -> Option { - #[cfg(feature = "feat_systemd_logind")] + #[cfg(systemd_logind)] { if let Some(ref mut systemd_iter) = self.systemd_iter { // We have a systemd iterator - use it exclusively (never fall back to traditional utmp) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 4b2cb9b502b..11dd43790fe 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -75,7 +75,7 @@ pub use crate::features::ranges; pub use crate::features::ringbuffer; #[cfg(feature = "sum")] pub use crate::features::sum; -#[cfg(feature = "feat_systemd_logind")] +#[cfg(systemd_logind)] pub use crate::features::systemd_logind; #[cfg(feature = "time")] pub use crate::features::time; @@ -122,10 +122,10 @@ 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(selinux)] pub use crate::features::selinux; -#[cfg(all(target_os = "linux", feature = "smack"))] +#[cfg(smack)] pub use crate::features::smack; //## core functions diff --git a/tests/by-util/test_chcon.rs b/tests/by-util/test_chcon.rs index 12c8c6e85ba..b59f927040d 100644 --- a/tests/by-util/test_chcon.rs +++ b/tests/by-util/test_chcon.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (jargon) xattributes #![allow(clippy::missing_errors_doc, clippy::similar_names)] -#![cfg(feature = "feat_selinux")] +#![cfg(selinux)] use std::ffi::CString; use std::path::Path; diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 95eb9670ced..e5532472c93 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -6,7 +6,7 @@ // spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs neve ROOTDIR USERDIR outfile uufs xattrs // spell-checker:ignore bdfl hlsl IRWXO IRWXG nconfined matchpathcon libselinux-devel prwx doesnotexist reftests subdirs mksocket srwx use uucore::display::Quotable; -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] use uucore::selinux::get_getfattr_output; use uutests::util::TestScenario; use uutests::{at_and_ucmd, new_ucmd, path_concat, util_name}; @@ -1801,7 +1801,7 @@ fn test_cp_preserve_xattr() { } #[test] -#[cfg(all(target_os = "linux", not(feature = "feat_selinux")))] +#[cfg(all(target_os = "linux", not(selinux)))] fn test_cp_preserve_all_context_fails_on_non_selinux() { new_ucmd!() .arg(TEST_COPY_FROM_FOLDER_FILE) @@ -6630,7 +6630,7 @@ fn test_cp_from_stream_permission() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_selinux() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -6655,7 +6655,7 @@ fn test_cp_selinux() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_selinux_invalid() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -6679,7 +6679,7 @@ fn test_cp_selinux_invalid() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_preserve_selinux() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -6717,7 +6717,7 @@ fn test_cp_preserve_selinux() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_preserve_selinux_admin_context() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -6776,7 +6776,7 @@ fn test_cp_preserve_selinux_admin_context() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_selinux_context_priority() { // This test verifies that -Z takes priority over --context @@ -6856,7 +6856,7 @@ fn test_cp_selinux_context_priority() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_selinux_empty_context() { // This test verifies that --context without a value works like -Z @@ -6902,7 +6902,7 @@ fn test_cp_selinux_empty_context() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_selinux_recursive() { // Test SELinux context preservation in recursive directory copies @@ -6956,7 +6956,7 @@ fn test_cp_selinux_recursive() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_preserve_context_root() { use uutests::util::run_ucmd_as_root; let scene = TestScenario::new(util_name!()); @@ -7659,7 +7659,7 @@ fn test_cp_gnu_preserve_mode() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_a_z_overrides_context() { // Verifies -aZ succeeds (-Z overrides implicit --preserve=context from -a) use std::path::Path; @@ -7677,7 +7677,7 @@ fn test_cp_a_z_overrides_context() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_a_preserves_context() { use std::path::Path; use uucore::selinux::{get_selinux_security_context, set_selinux_security_context}; @@ -7700,7 +7700,7 @@ fn test_cp_a_preserves_context() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_cp_preserve_context_with_z_fails() { let (at, mut ucmd) = at_and_ucmd!(); at.touch("src"); diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index 828a1e04311..2aae0b2aa79 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -7,7 +7,7 @@ use uutests::at_and_ucmd; use uutests::new_ucmd; use uutests::util::TestScenario; -#[cfg(all(unix, not(feature = "feat_selinux")))] +#[cfg(all(unix, not(selinux)))] use uutests::util::run_ucmd_as_root_with_stdin_stdout; #[cfg(all(not(windows), feature = "printf"))] use uutests::util::{UCommand, get_tests_binary}; @@ -1585,8 +1585,7 @@ fn test_nocache_file() { } #[test] -#[cfg(unix)] -#[cfg(not(feature = "feat_selinux"))] +#[cfg(all(unix, not(selinux)))] // Disabled on SELinux for now fn test_skip_past_dev() { // NOTE: This test intends to trigger code which can only be reached with root permissions. @@ -1610,8 +1609,7 @@ fn test_skip_past_dev() { } #[test] -#[cfg(unix)] -#[cfg(not(feature = "feat_selinux"))] +#[cfg(all(unix, not(selinux)))] fn test_seek_past_dev() { // NOTE: This test intends to trigger code which can only be reached with root permissions. let ts = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index c1cf50d2518..49facdccead 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -328,8 +328,10 @@ fn test_type_option() { } #[test] -#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "windows")))] // FIXME: fix test for FreeBSD, OpenBSD & Win -#[cfg(not(feature = "feat_selinux"))] +#[cfg(all( + not(any(target_os = "freebsd", target_os = "openbsd", target_os = "windows")), // FIXME: fix test for FreeBSD, OpenBSD & Win + not(selinux) +))] fn test_type_option_with_file() { let fs_type = new_ucmd!() .args(&["--output=fstype", "."]) diff --git a/tests/by-util/test_id.rs b/tests/by-util/test_id.rs index ec96e3c23e8..412d1d4fa4c 100644 --- a/tests/by-util/test_id.rs +++ b/tests/by-util/test_id.rs @@ -34,7 +34,7 @@ fn test_id_no_specified_user() { let exp_result = unwrap_or_return!(expected_result(&ts, &[])); let mut exp_stdout = exp_result.stdout_str().to_string(); - #[cfg(not(feature = "feat_selinux"))] + #[cfg(not(selinux))] { // NOTE: strip 'context' part from exp_stdout if selinux not enabled: // example: @@ -383,7 +383,7 @@ fn test_id_zero() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_id_context() { if !uucore::selinux::is_selinux_enabled() { println!("test skipped: Kernel has no support for SElinux context"); @@ -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(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 83e4353da58..184adce28f5 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -15,7 +15,7 @@ use std::process; #[cfg(any(target_os = "linux", target_os = "android"))] use std::thread::sleep; use uucore::process::{getegid, geteuid}; -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] use uucore::selinux::get_getfattr_output; use uutests::at_and_ucmd; use uutests::new_ucmd; @@ -2334,7 +2334,7 @@ fn test_install_no_target_basic() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_selinux() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -2383,7 +2383,7 @@ fn test_selinux() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_selinux_invalid_args() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -2416,7 +2416,7 @@ fn test_selinux_invalid_args() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_selinux_default_context() { 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 d5e12f2340c..21b0716fedd 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -30,7 +30,7 @@ use uutests::new_ucmd; #[cfg(unix)] use uutests::unwrap_or_return; use uutests::util::TestScenario; -#[cfg(any(unix, feature = "feat_selinux"))] +#[cfg(unix)] use uutests::util::expected_result; use uutests::{at_and_ucmd, util_name}; @@ -1145,9 +1145,8 @@ fn test_ls_long() { } } -#[cfg(not(windows))] #[test] -#[cfg(not(feature = "feat_selinux"))] +#[cfg(all(unix, not(selinux)))] // Disabled on the SELinux runner for now fn test_ls_long_format() { let scene = TestScenario::new(util_name!()); @@ -1703,7 +1702,7 @@ fn test_ls_long_total_size() { } #[test] -#[cfg(not(feature = "feat_selinux"))] +#[cfg(not(selinux))] // Disabled on the SELinux runner for now fn test_ls_long_formats() { let scene = TestScenario::new(util_name!()); @@ -3231,9 +3230,8 @@ fn test_ls_color() { assert_eq!(result.stdout_str(), expected); } -#[cfg(unix)] #[test] -#[cfg(not(feature = "feat_selinux"))] +#[cfg(all(unix, not(selinux)))] // Disabled on the SELinux runner for now fn test_ls_inode() { let scene = TestScenario::new(util_name!()); @@ -4626,7 +4624,7 @@ fn test_ls_dangling_symlinks() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_ls_context1() { if !uucore::selinux::is_selinux_enabled() { println!("test skipped: Kernel has no support for SElinux context"); @@ -4641,7 +4639,7 @@ fn test_ls_context1() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_ls_context2() { if !uucore::selinux::is_selinux_enabled() { println!("test skipped: Kernel has no support for SElinux context"); @@ -4657,7 +4655,7 @@ fn test_ls_context2() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_ls_context_long() { if !uucore::selinux::is_selinux_enabled() { return; @@ -4676,7 +4674,7 @@ fn test_ls_context_long() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_ls_context_format() { if !uucore::selinux::is_selinux_enabled() { println!("test skipped: Kernel has no support for SElinux context"); @@ -4706,7 +4704,7 @@ fn test_ls_context_format() { } /// Helper function to validate `SELinux` context format -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn validate_selinux_context(context: &str) { assert!( context.contains(':'), @@ -4721,7 +4719,7 @@ fn validate_selinux_context(context: &str) { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_ls_selinux_context_format() { if !uucore::selinux::is_selinux_enabled() { println!("test skipped: Kernel has no support for SElinux context"); @@ -4754,7 +4752,7 @@ fn test_ls_selinux_context_format() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_ls_selinux_context_indicator() { if !uucore::selinux::is_selinux_enabled() { println!("test skipped: Kernel has no support for SElinux context"); @@ -6157,9 +6155,8 @@ fn test_acl_display() { // files. Specifically, it should use the NORMAL setting to format non-file name // output and file names that don't have a designated color (unless the FILE // setting is also configured). -#[cfg(unix)] #[test] -#[cfg(not(feature = "feat_selinux"))] +#[cfg(all(unix, not(selinux)))] // Disabled on the SELinux runner for now fn test_ls_color_norm() { let scene = TestScenario::new(util_name!()); diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index 231fe3495d3..129a0e73c09 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -11,7 +11,7 @@ use libc::mode_t; #[cfg(not(windows))] use std::os::unix::fs::PermissionsExt; -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] use uucore::selinux::get_getfattr_output; #[cfg(not(windows))] use uutests::at_and_ucmd; @@ -451,7 +451,7 @@ fn test_empty_argument() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_selinux() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -475,7 +475,7 @@ fn test_selinux() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_selinux_invalid() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; diff --git a/tests/by-util/test_mkfifo.rs b/tests/by-util/test_mkfifo.rs index 4d19da636a2..8f3762733a5 100644 --- a/tests/by-util/test_mkfifo.rs +++ b/tests/by-util/test_mkfifo.rs @@ -5,7 +5,7 @@ // spell-checker:ignore nconfined -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] use uucore::selinux::get_getfattr_output; use uutests::new_ucmd; use uutests::util::TestScenario; @@ -167,7 +167,7 @@ fn test_create_fifo_permission_denied() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_mkfifo_selinux() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -191,7 +191,7 @@ fn test_mkfifo_selinux() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_mkfifo_selinux_invalid() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; diff --git a/tests/by-util/test_mknod.rs b/tests/by-util/test_mknod.rs index 1bcae7ea31a..c61371bbc31 100644 --- a/tests/by-util/test_mknod.rs +++ b/tests/by-util/test_mknod.rs @@ -7,7 +7,7 @@ use std::os::unix::fs::PermissionsExt; -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] use uucore::selinux::get_getfattr_output; use uutests::new_ucmd; use uutests::util::TestScenario; @@ -184,7 +184,7 @@ fn test_mknod_mode_comma_separated() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_mknod_selinux() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; @@ -215,7 +215,7 @@ fn test_mknod_selinux() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_mknod_selinux_invalid() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; @@ -242,7 +242,7 @@ fn test_mknod_selinux_invalid() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_mknod_selinux_invalid_cleanup() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 266c812df59..166cda39f47 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -10,7 +10,7 @@ use rstest::rstest; use std::io::Write; #[cfg(not(windows))] use std::path::Path; -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] use uucore::selinux::get_getfattr_output; use uutests::new_ucmd; #[cfg(unix)] @@ -2640,7 +2640,7 @@ fn test_mv_cross_device_permission_denied() { } #[test] -#[cfg(feature = "selinux")] +#[cfg(selinux)] fn test_mv_selinux_context() { let test_cases = [ ("-Z", None), diff --git a/tests/by-util/test_runcon.rs b/tests/by-util/test_runcon.rs index 39a73d8832e..1b18d1a5d33 100644 --- a/tests/by-util/test_runcon.rs +++ b/tests/by-util/test_runcon.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore (jargon) xattributes -#![cfg(feature = "feat_selinux")] +#![cfg(selinux)] use uutests::new_ucmd; @@ -84,7 +84,7 @@ fn invalid() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn plain_context() { let ctx = "unconfined_u:unconfined_r:unconfined_t:s0-s0"; new_ucmd!().args(&[ctx, "/bin/true"]).succeeds(); @@ -103,7 +103,7 @@ fn plain_context() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn custom_context() { let t_ud = "unconfined_t"; let u_ud = "unconfined_u"; diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs index 8347d49c795..1afb8beffc4 100644 --- a/tests/by-util/test_stat.rs +++ b/tests/by-util/test_stat.rs @@ -502,7 +502,7 @@ fn test_printf_invalid_directive() { } #[test] -#[cfg(feature = "feat_selinux")] +#[cfg(selinux)] fn test_stat_selinux() { let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; diff --git a/tests/by-util/test_stdbuf.rs b/tests/by-util/test_stdbuf.rs index 0b60ef4648f..00bcb2b90e3 100644 --- a/tests/by-util/test_stdbuf.rs +++ b/tests/by-util/test_stdbuf.rs @@ -15,7 +15,7 @@ fn invalid_input() { new_ucmd!().arg("-/").fails_with_code(125); } -#[cfg(not(feature = "feat_external_libstdbuf"))] +#[cfg(not(external_libstdbuf))] #[test] fn test_permission() { new_ucmd!() @@ -27,7 +27,7 @@ fn test_permission() { // LD_DEBUG is not available on macOS, OpenBSD, Android, or musl #[cfg(all( - feature = "feat_external_libstdbuf", + external_libstdbuf, not(target_os = "windows"), not(target_os = "openbsd"), not(target_os = "macos"), @@ -121,7 +121,7 @@ fn test_stdbuf_search_order_exe_dir_first() { ); } -#[cfg(not(feature = "feat_external_libstdbuf"))] +#[cfg(not(external_libstdbuf))] #[test] fn test_no_such() { new_ucmd!() diff --git a/tests/by-util/test_tail.rs b/tests/by-util/test_tail.rs index f2875e7b1e3..3f37d1e3e54 100644 --- a/tests/by-util/test_tail.rs +++ b/tests/by-util/test_tail.rs @@ -2113,7 +2113,7 @@ fn test_follow_name_truncate3() { #[cfg(all( not(target_vendor = "apple"), not(target_os = "windows"), - not(feature = "feat_selinux") // flaky + not(selinux) // flaky ))] // FIXME: for currently not working platforms fn test_follow_name_truncate4() { // Truncating a file with the same content it already has should not trigger a truncate event @@ -4567,7 +4567,7 @@ fn test_args_when_directory_given_shorthand_big_f_together_with_retry() { not(target_os = "windows"), not(target_os = "freebsd"), not(target_os = "openbsd"), - not(feature = "feat_selinux") // flaky + not(selinux) // flaky ))] fn test_follow_when_files_are_pointing_to_same_relative_file_and_file_stays_same_size() { let scene = TestScenario::new(util_name!());