Skip to content

Commit 524a324

Browse files
committed
tty: Build for Windows
1 parent 5aade31 commit 524a324

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

.github/workflows/make.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ jobs:
322322
set -x
323323
# Check that we exclude unix programs to avoid build failure
324324
make PREFIX=/tmp/usr MULTICALL=y COMPLETIONS=n MANPAGES=n LOCALES=n \
325-
SKIP_UTILS="arch b2sum base32 base64 basename basenc cat cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false fmt fold head hostname join link ln ls md5sum mkdir mktemp more mv nl nproc numfmt od paste pr printenv printf ptx pwd readlink realpath rm rmdir seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf sleep sort split sum sync tac tail tee test touch tr truncate tsort uname unexpand uniq unlink vdir wc whoami yes"
326-
target/debug/coreutils.exe true
325+
SKIP_UTILS="arch b2sum base32 base64 basename basenc cat cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false fmt fold head hostname join link ln ls md5sum mkdir mktemp more mv nl nproc numfmt od paste pathchk pr printenv printf ptx pwd readlink realpath rm rmdir seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf sleep sort split sum sync tac tail tee test touch tr truncate tsort tty uname unexpand uniq unlink vdir wc whoami yes"
326+
target/debug/coreutils.exe ttue
327327
328328
test_busybox:
329329
name: Tests/BusyBox test suite

.github/workflows/wasi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime
3838
run: |
3939
# Get all utilities and exclude ones that don't compile for wasm32-wasip1
40-
EXCLUDE="dd|df|du|env|expr|mktemp|more|tac|test"
40+
EXCLUDE="dd|df|du|env|expr|mktemp|more|tac|test|tty"
4141
UTILS=$(./util/show-utils.sh | tr ' ' '\n' | grep -vE "^($EXCLUDE)$" | sed 's/^/-p uu_/' | tr '\n' ' ')
4242
cargo test --target wasm32-wasip1 --no-default-features $UTILS
4343
- name: Run integration tests via wasmtime

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ feat_common_core = [
156156
"true",
157157
"truncate",
158158
"tsort",
159+
"tty",
159160
"unexpand",
160161
"uniq",
161162
"unlink",
@@ -312,7 +313,6 @@ feat_require_unix_core = [
312313
"stat",
313314
"stty",
314315
"timeout",
315-
"tty",
316316
]
317317
# "feat_require_unix_utmpx" == set of utilities requiring unix utmp/utmpx support
318318
# * ref: <https://wiki.musl-libc.org/faq.html#Q:-Why-is-the-utmp/wtmp-functionality-only-implemented-as-stubs?>
@@ -337,7 +337,6 @@ feat_os_unix_fuchsia = [
337337
"mkfifo",
338338
"mknod",
339339
"nice",
340-
"tty",
341340
"uname",
342341
"unlink",
343342
]

src/uu/tty/src/tty.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use clap::{Arg, ArgAction, Command};
99
use std::io::{IsTerminal, Write};
10-
use uucore::display::OsWrite;
1110
use uucore::error::{UResult, set_exit_code};
1211
use uucore::format_usage;
1312

@@ -38,18 +37,27 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
3837
}
3938

4039
let mut stdout = std::io::stdout();
41-
40+
#[cfg(unix)]
4241
let name = rustix::termios::ttyname(std::io::stdin(), Vec::with_capacity(8));
43-
42+
#[cfg(unix)]
4443
let write_result = if let Ok(name) = name {
4544
use std::os::unix::ffi::OsStrExt;
45+
use uucore::display::OsWrite;
4646
let os_name = std::ffi::OsStr::from_bytes(name.as_bytes());
4747
stdout.write_all_os(os_name)
4848
} else {
4949
set_exit_code(1);
5050
writeln!(stdout, "{}", translate!("tty-not-a-tty"))
5151
};
5252

53+
#[cfg(target_os = "windows")]
54+
let write_result = if std::io::stdin().is_terminal() {
55+
writeln!(stdout, r"\\.\CON")
56+
} else {
57+
set_exit_code(1);
58+
writeln!(stdout, "{}", translate!("tty-not-a-tty"))
59+
};
60+
5361
if write_result.is_err() || stdout.flush().is_err() {
5462
// Don't return to prevent a panic later when another flush is attempted
5563
// because the `uucore_procs::main` macro inserts a flush after execution for every utility.

tests/by-util/test_tty.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fs::File;
77
use uutests::new_ucmd;
88

99
#[test]
10-
#[cfg(not(windows))]
10+
#[cfg(unix)]
1111
fn test_dev_null() {
1212
new_ucmd!()
1313
.set_stdin(File::open("/dev/null").unwrap())
@@ -16,7 +16,7 @@ fn test_dev_null() {
1616
}
1717

1818
#[test]
19-
#[cfg(not(windows))]
19+
#[cfg(unix)]
2020
fn test_dev_null_silent() {
2121
new_ucmd!()
2222
.args(&["-s"])
@@ -26,27 +26,31 @@ fn test_dev_null_silent() {
2626
}
2727

2828
#[test]
29+
#[cfg(unix)]
2930
fn test_close_stdin() {
3031
let mut child = new_ucmd!().run_no_wait();
3132
child.close_stdin();
3233
child.wait().unwrap().code_is(1).stdout_is("not a tty\n");
3334
}
3435

3536
#[test]
37+
#[cfg(unix)]
3638
fn test_close_stdin_silent() {
3739
let mut child = new_ucmd!().arg("-s").run_no_wait();
3840
child.close_stdin();
3941
child.wait().unwrap().code_is(1).no_stdout();
4042
}
4143

4244
#[test]
45+
#[cfg(unix)]
4346
fn test_close_stdin_silent_long() {
4447
let mut child = new_ucmd!().arg("--silent").run_no_wait();
4548
child.close_stdin();
4649
child.wait().unwrap().code_is(1).no_stdout();
4750
}
4851

4952
#[test]
53+
#[cfg(unix)]
5054
fn test_close_stdin_silent_alias() {
5155
let mut child = new_ucmd!().arg("--quiet").run_no_wait();
5256
child.close_stdin();

0 commit comments

Comments
 (0)