diff --git a/Cargo.lock b/Cargo.lock index bf434e39514..bd1c75d9235 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -505,6 +505,7 @@ name = "coreutils" version = "0.13.0" dependencies = [ "bytecount", + "cfg_aliases", "clap", "clap_complete", "clap_mangen", diff --git a/Cargo.toml b/Cargo.toml index 24b4c700b6e..d198226a396 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -398,6 +398,7 @@ nix = { workspace = true, features = ["fs", "signal"] } rustix = { workspace = true, features = ["net", "process"] } [build-dependencies] +cfg_aliases.workspace = true phf_codegen.workspace = true [features] diff --git a/build.rs b/build.rs index 923b2f44d1a..794eaeae992 100644 --- a/build.rs +++ b/build.rs @@ -10,11 +10,16 @@ use std::fs::File; use std::io::Write; use std::path::Path; +#[path = "cfg_aliases.rs"] +mod cfg_aliases; + pub fn main() { const ENV_FEATURE_PREFIX: &str = "CARGO_FEATURE_"; const FEATURE_PREFIX: &str = "feat_"; const OVERRIDE_PREFIX: &str = "uu_"; + cfg_aliases::register(); + // Do not rebuild build script unless the script itself or the enabled features are modified // See println!("cargo:rerun-if-changed=build.rs"); diff --git a/cfg_aliases.rs b/cfg_aliases.rs new file mode 100644 index 00000000000..6ca2abbe9ef --- /dev/null +++ b/cfg_aliases.rs @@ -0,0 +1,16 @@ +// 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. + +pub fn register() { + cfg_aliases::cfg_aliases! { + bsd: { any( + target_vendor = "apple", + target_os = "freebsd", + target_os = "dragonfly", + target_os = "netbsd", + target_os = "openbsd" + ) }, + } +} diff --git a/src/uu/stty/build.rs b/src/uu/stty/build.rs index 320a109d007..1eb27b004b4 100644 --- a/src/uu/stty/build.rs +++ b/src/uu/stty/build.rs @@ -3,16 +3,9 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use cfg_aliases::cfg_aliases; +#[path = "../../../cfg_aliases.rs"] +mod cfg_aliases; fn main() { - cfg_aliases! { - bsd: { any( - target_vendor = "apple", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - ) }, - }; + cfg_aliases::register(); } diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 4bd8de32e0e..53be3178c68 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -705,13 +705,7 @@ fn test_month_default2() { /// Query the system for abbreviated month names via `locale abmon`. /// Returns a vector of 12 month abbreviations in order (Jan..Dec), /// or None if the command fails or returns unexpected output. -#[cfg(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" -))] +#[cfg(bsd)] fn get_system_abmon(locale: &str) -> Option> { let output = Command::new("locale") .env("LC_ALL", locale) @@ -734,13 +728,7 @@ fn get_system_abmon(locale: &str) -> Option> { } /// Build shuffled input and sorted expected output from month names. -#[cfg(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" -))] +#[cfg(bsd)] fn month_sort_input_expected(months: &[String]) -> (String, String) { // Shuffled order: May, Dec, Jan, Jun, Feb, Mar, Apr, Jul, Aug, Sep, Oct, Nov let shuffle_order = [4, 11, 0, 5, 1, 2, 3, 6, 7, 8, 9, 10]; @@ -764,26 +752,14 @@ fn test_month_sort_french_locale() { // spell-checker:disable // On BSD-like, abbreviated month names vary across OS versions (different CLDR data), // so we query the system dynamically. On other platforms, glibc values are stable. - #[cfg(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - ))] + #[cfg(bsd)] let (input, expected) = { let Some(months) = get_system_abmon(locale) else { return; }; month_sort_input_expected(&months) }; - #[cfg(not(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] let (input, expected) = ( "mai\ndéc.\njanv.\njuin\nfévr.\nmars\navril\njuil.\naoût\nsept.\noct.\nnov.\n".to_string(), "janv.\nfévr.\nmars\navril\nmai\njuin\njuil.\naoût\nsept.\noct.\nnov.\ndéc.\n".to_string(), @@ -805,26 +781,14 @@ fn test_month_sort_hungarian_locale() { return; } // spell-checker:disable - #[cfg(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - ))] + #[cfg(bsd)] let (input, expected) = { let Some(months) = get_system_abmon(locale) else { return; }; month_sort_input_expected(&months) }; - #[cfg(not(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] let (input, expected) = ( "máj\ndec\njan\njún\nfebr\nmárc\nápr\njúl\naug\nszept\nokt\nnov\n".to_string(), "jan\nfebr\nmárc\nápr\nmáj\njún\njúl\naug\nszept\nokt\nnov\ndec\n".to_string(), @@ -851,26 +815,14 @@ fn test_month_sort_french_embedded_blanks() { // Pick three locale months (indices 2=March, 3=April, 5=June) and verify // that inserting blanks into April's name causes a non-match. // On glibc these are "mars", "avril", "juin"; on other systems they vary. - #[cfg(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - ))] + #[cfg(bsd)] let months = { let Some(m) = get_system_abmon(locale) else { return; }; m }; - #[cfg(not(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] let months = vec![ "janv.", "févr.", "mars", "avril", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc.", @@ -912,13 +864,7 @@ fn test_month_sort_japanese_locale() { return; } // On BSD-like, abbreviated month names may differ, so query dynamically. - #[cfg(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - ))] + #[cfg(bsd)] let (input, expected) = { let Some(months) = get_system_abmon(locale) else { return; @@ -926,13 +872,7 @@ fn test_month_sort_japanese_locale() { month_sort_input_expected(&months) }; // Japanese abbreviated months are numeric (1月..12月) on glibc - #[cfg(not(any( - target_vendor = "apple", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] let (input, expected) = ( "5月\n12月\n1月\n6月\n2月\n3月\n4月\n7月\n8月\n9月\n10月\n11月\n".to_string(), "1月\n2月\n3月\n4月\n5月\n6月\n7月\n8月\n9月\n10月\n11月\n12月\n".to_string(), diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index 2161074d9b6..1b106bb6f58 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -153,13 +153,7 @@ fn invalid_setting() { #[test] fn invalid_baud_setting() { - #[cfg(not(any( - target_vendor = "apple", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] new_ucmd!() .args(&["100"]) .fails() @@ -180,25 +174,13 @@ fn invalid_baud_setting() { .fails() .stderr_contains("missing argument to 'ospeed'"); - #[cfg(not(any( - target_vendor = "apple", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] new_ucmd!() .args(&["ispeed", "995"]) .fails() .stderr_contains("invalid ispeed '995'"); - #[cfg(not(any( - target_vendor = "apple", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] new_ucmd!() .args(&["ospeed", "995"]) .fails() @@ -471,13 +453,7 @@ fn grouped_flag_removal() { #[ignore = "Fails because cargo test does not run in a tty"] fn baud_rate_validation() { // Test various baud rate formats - #[cfg(any( - target_vendor = "apple", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - ))] + #[cfg(bsd)] { // BSD accepts numeric baud rates new_ucmd!().args(&["9600"]).fails(); // Fails due to no TTY, but validates parsing @@ -1473,13 +1449,7 @@ fn invalid_baud_rate() { // On non-BSD systems, test invalid numeric baud rate // On BSD systems, any u32 is accepted, so we skip this test - #[cfg(not(any( - target_vendor = "apple", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(bsd))] { new_ucmd!() .args(&["ospeed", "999999999"]) @@ -1632,13 +1602,7 @@ fn test_ispeed_ospeed_valid_speeds() { } #[test] -#[cfg(not(any( - target_vendor = "apple", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "netbsd", - target_os = "openbsd" -)))] +#[cfg(not(bsd))] #[ignore = "Issue: #9547"] fn test_ispeed_ospeed_invalid_speeds() { let (path, _controller, _replica) = pty_path();