Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://doc.rust-lang.org/cargo/reference/build-scripts.html#change-detection>
println!("cargo:rerun-if-changed=build.rs");
Expand Down
16 changes: 16 additions & 0 deletions cfg_aliases.rs
Original file line number Diff line number Diff line change
@@ -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"
) },
}
}
13 changes: 3 additions & 10 deletions src/uu/stty/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
80 changes: 10 additions & 70 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> {
let output = Command::new("locale")
.env("LC_ALL", locale)
Expand All @@ -734,13 +728,7 @@ fn get_system_abmon(locale: &str) -> Option<Vec<String>> {
}

/// 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];
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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.",
Expand Down Expand Up @@ -912,27 +864,15 @@ 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;
};
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(),
Expand Down
48 changes: 6 additions & 42 deletions tests/by-util/test_stty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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();
Expand Down
Loading