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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,11 @@ runcon = { optional = true, version = "0.13.0", package = "uu_runcon", path = "s

[target.'cfg(unix)'.dev-dependencies]
nix = { workspace = true, features = ["fs", "signal"] }
rlimit = { workspace = true }
rustix = { workspace = true, features = ["net", "process"] }

[target.'cfg(all(unix, not(target_os = "fuchsia")))'.dev-dependencies]
rlimit = { workspace = true }

[build-dependencies]
phf_codegen.workspace = true

Expand Down
12 changes: 8 additions & 4 deletions tests/uutests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ all-features = true
[lib]
path = "src/lib/lib.rs"

[dependencies]
ctor = { workspace = true }
[target.'cfg(not(any(target_os = "aix", target_os = "horizon")))'.dependencies]
Comment thread
xtqqczze marked this conversation as resolved.
libc = { workspace = true }
pretty_assertions = { workspace = true }
rand = { workspace = true }
Expand All @@ -35,13 +34,18 @@ uucore = { workspace = true, features = [

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]

[target.'cfg(unix)'.dependencies]
nix = { workspace = true, features = ["fs", "term"] }
[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "fuchsia", target_os = "horizon"))))'.dependencies]
rlimit = { workspace = true }

[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "horizon"))))'.dependencies]
nix = { workspace = true, features = ["fs", "term"] }
rustix = { workspace = true, features = ["pty", "termios"] }

[target.'cfg(any(target_os = "freebsd", target_os = "hurd", target_os = "linux", target_os = "android", target_os = "netbsd"))'.dependencies]
xattr = { workspace = true }

[target.'cfg(not(any(target_os = "aix", target_os = "horizon")))'.dev-dependencies]
ctor = { workspace = true }

[lints]
workspace = true
2 changes: 2 additions & 0 deletions tests/uutests/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#![cfg(not(any(target_os = "aix", target_os = "horizon")))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why compile the whole crate to nothing on aix/horizon? what fails there?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix fails to compile on both:

$ RUSTC_BOOTSTRAP=1 cargo hack clippy -Zbuild-std=std,panic_abort --quiet -p uutests --all-features --lib --target powerpc64-ibm-aix
info: running `cargo clippy -Zbuild-std=std,panic_abort --quiet --all-features --lib --target powerpc64-ibm-aix` on uutests (1/1)
error[E0425]: cannot find type `Pid` in this scope
  --> ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.31.3/src/pty.rs:38:16
   |
38 |         child: Pid,
   |                ^^^ not found in this scope
   |
help: consider importing this struct
   |
 3 + use crate::unistd::Pid;
   |
$ cargo +nightly hack clippy -Zbuild-std=std,panic_abort --quiet -p uutests --all-features --lib --target armv6k-nintendo-3ds
info: running `cargo clippy -Zbuild-std=std,panic_abort --quiet --all-features --lib --target armv6k-nintendo-3ds` on uutests (1/1)
error[E0432]: unresolved import `self::consts`
  --> /Users/matthew/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/nix-0.31.3/src/errno.rs:19:15
   |
19 | pub use self::consts::*;
   |               ^^^^^^ could not find `consts` in `self`


#[macro_use]
pub mod macros;
pub mod random;
Expand Down
62 changes: 32 additions & 30 deletions tests/uutests/src/lib/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
use core::str;
#[cfg(unix)]
use libc::mode_t;
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))]
use nix::pty::OpenptyResult;
#[cfg(unix)]
use nix::sys;
#[cfg(not(windows))]
#[cfg(unix)]
use nix::sys::stat::{self, SFlag};
use pretty_assertions::assert_eq;
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
use rlimit::{Resource, setrlimit};
use std::borrow::Cow;
use std::collections::{BTreeMap, VecDeque};
Expand Down Expand Up @@ -353,8 +353,16 @@ impl CmdResult {
///
/// # Platform specific behavior
///
/// This assertion method is only available on unix systems, except for fuchsia.
#[cfg(all(unix, not(target_os = "fuchsia")))]
/// This assertion method is only available on unix systems, except for fuchsia, haiku and hurd.
#[cfg(all(
unix,
not(any(
target_os = "dragonfly",
target_os = "fuchsia",
target_os = "haiku",
target_os = "hurd"
))
))]
#[track_caller]
pub fn signal_name_is(&self, name: &str) -> &Self {
use uucore::signals::signal_by_name_or_value;
Expand Down Expand Up @@ -1216,7 +1224,7 @@ impl AtPath {
File::create(self.plus(file)).unwrap();
}

#[cfg(not(windows))]
#[cfg(unix)]
pub fn mkfifo(&self, fifo: &str) {
// rustix::fs::mkfifoat is linux only
use nix::sys::stat::Mode;
Expand All @@ -1234,13 +1242,13 @@ impl AtPath {
UnixListener::bind(full_path).expect("Socket file creation failed.");
}

#[cfg(not(windows))]
#[cfg(unix)]
pub fn is_fifo(&self, fifo: &str) -> bool {
stat::stat(&self.plus(fifo))
.is_ok_and(|s| SFlag::from_bits_truncate(s.st_mode).contains(SFlag::S_IFIFO))
}

#[cfg(not(windows))]
#[cfg(unix)]
pub fn is_char_device(&self, char_dev: &str) -> bool {
stat::stat(&self.plus(char_dev))
.is_ok_and(|s| SFlag::from_bits_truncate(s.st_mode).contains(SFlag::S_IFCHR))
Expand All @@ -1258,6 +1266,7 @@ impl AtPath {
hard_link(self.plus(original), self.plus(link)).unwrap();
}

#[cfg(any(unix, windows))]
pub fn symlink_file(&self, original: &str, link: &str) {
log_info(
"symlink",
Expand All @@ -1270,6 +1279,7 @@ impl AtPath {
symlink_file(self.plus(original), self.plus(link)).unwrap();
}

#[cfg(any(unix, windows))]
pub fn relative_symlink_file(&self, original: &str, link: &str) {
#[cfg(windows)]
let original = original.replace('/', MAIN_SEPARATOR_STR);
Expand All @@ -1280,6 +1290,7 @@ impl AtPath {
symlink_file(original, self.plus(link)).unwrap();
}

#[cfg(any(unix, windows))]
pub fn symlink_dir(&self, original: &str, link: &str) {
log_info(
"symlink",
Expand All @@ -1292,6 +1303,7 @@ impl AtPath {
symlink_dir(self.plus(original), self.plus(link)).unwrap();
}

#[cfg(any(unix, windows))]
pub fn relative_symlink_dir(&self, original: &str, link: &str) {
#[cfg(windows)]
let original = original.replace('/', MAIN_SEPARATOR_STR);
Expand Down Expand Up @@ -1403,7 +1415,7 @@ impl AtPath {
///
/// This function panics if there is an error loading the metadata
/// or setting the permissions of the file.
#[cfg(not(windows))]
#[cfg(unix)]
pub fn set_mode(&self, filename: &str, mode: u32) {
let path = self.plus(filename);
let mut perms = fs::metadata(&path).unwrap().permissions();
Expand Down Expand Up @@ -1562,7 +1574,7 @@ pub struct UCommand {
stdout: Option<Stdio>,
stderr: Option<Stdio>,
bytes_into_stdin: Option<Vec<u8>>,
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
limits: Vec<(Resource, u64, u64)>,
#[cfg(unix)]
ignore_sigxfsz: bool,
Expand Down Expand Up @@ -1727,7 +1739,7 @@ impl UCommand {
self
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
pub fn limit(&mut self, resource: Resource, soft_limit: u64, hard_limit: u64) -> &mut Self {
self.limits.push((resource, soft_limit, hard_limit));
self
Expand Down Expand Up @@ -2000,9 +2012,9 @@ impl UCommand {

let mut captured_stdout = None;
let mut captured_stderr = None;
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))]
let mut stdin_pty: Option<File> = None;
#[cfg(not(all(unix, not(target_os = "redox"))))]
#[cfg(not(all(unix, not(any(target_os = "fuchsia", target_os = "redox")))))]
let stdin_pty: Option<File> = None;
if self.stderr_to_stdout {
let mut output = CapturedOutput::default();
Expand Down Expand Up @@ -2037,7 +2049,7 @@ impl UCommand {
.stderr(stderr);
}

#[cfg(all(unix, not(target_os = "redox")))]
#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))]
if let Some(simulated_terminal) = &self.terminal_simulation {
let terminal_size = simulated_terminal.size.unwrap_or(libc::winsize {
ws_col: 80,
Expand Down Expand Up @@ -2086,7 +2098,7 @@ impl UCommand {
}
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
if !self.limits.is_empty() {
// just to be safe: move a copy of the limits list into the closure.
// this way the closure is fully self-contained.
Expand Down Expand Up @@ -3050,14 +3062,9 @@ pub fn whoami() -> String {

/// Open a PTY whose two ends are close-on-exec, so that commands started by
/// other tests in the meantime don't inherit them.
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))]
fn open_pty(size: Option<&libc::winsize>) -> OpenptyResult {
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
Comment thread
xtqqczze marked this conversation as resolved.
{
use rustix::fs::{Mode, OFlags, open};
use rustix::pty::{OpenptFlags, grantpt, openpt, ptsname, unlockpt};
Expand Down Expand Up @@ -3088,12 +3095,7 @@ fn open_pty(size: Option<&libc::winsize>) -> OpenptyResult {

// Elsewhere a PTY can't be opened close-on-exec, so a command started
// between openpty and fcntl can still inherit it.
#[cfg(not(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd"
)))]
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "freebsd")))]
{
use nix::fcntl::{FcntlArg, FdFlag, fcntl};

Expand All @@ -3111,7 +3113,7 @@ fn open_pty(size: Option<&libc::winsize>) -> OpenptyResult {
/// - path: The filesystem path to the PTY replica device
/// - controller: The controller file
/// - replica: The replica file
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg(all(unix, not(any(target_os = "fuchsia", target_os = "redox"))))]
pub fn pty_path() -> (String, File, File) {
use nix::unistd::ttyname;
let pty = open_pty(None);
Expand Down Expand Up @@ -3768,7 +3770,7 @@ mod tests {
.stdout_is("unlimited\nunlimited\n");
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "fuchsia")))]
#[test]
fn test_application_of_process_resource_limits_limited_file_size() {
let unit_size_bytes = if cfg!(target_vendor = "apple") {
Expand Down
Loading