Skip to content

Commit 3afb7d6

Browse files
clubby789OneiricalChrisDenton
committed
Migrate emit-to-stdout to new run-make
Co-authored-by: Oneirical <[email protected]> Co-authored-by: Chris Denton <[email protected]>
1 parent b577b26 commit 3afb7d6

File tree

4 files changed

+76
-55
lines changed

4 files changed

+76
-55
lines changed

src/tools/run-make-support/src/macros.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ macro_rules! impl_common_helpers {
7373
/// Configuration for the child process’s standard input (stdin) handle.
7474
///
7575
/// See [`std::process::Command::stdin`].
76-
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self {
76+
pub fn stdin<T: Into<::std::process::Stdio>>(&mut self, cfg: T) -> &mut Self {
7777
self.cmd.stdin(cfg);
7878
self
7979
}
8080

8181
/// Configuration for the child process’s standard output (stdout) handle.
8282
///
8383
/// See [`std::process::Command::stdout`].
84-
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self {
84+
pub fn stdout<T: Into<::std::process::Stdio>>(&mut self, cfg: T) -> &mut Self {
8585
self.cmd.stdout(cfg);
8686
self
8787
}
8888

8989
/// Configuration for the child process’s standard error (stderr) handle.
9090
///
9191
/// See [`std::process::Command::stderr`].
92-
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self {
92+
pub fn stderr<T: Into<::std::process::Stdio>>(&mut self, cfg: T) -> &mut Self {
9393
self.cmd.stderr(cfg);
9494
self
9595
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
run-make/branch-protection-check-IBT/Makefile
22
run-make/cat-and-grep-sanity-check/Makefile
3-
run-make/emit-to-stdout/Makefile
43
run-make/extern-fn-reachable/Makefile
54
run-make/incr-add-rust-src-component/Makefile
65
run-make/issue-84395-lto-embed-bitcode/Makefile

tests/run-make/emit-to-stdout/Makefile

-51
This file was deleted.
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//! If `-o -` or `--emit KIND=-` is provided, output should be written to stdout
2+
//! instead. Binary output (`obj`, `llvm-bc`, `link` and `metadata`)
3+
//! being written this way will result in an error if stdout is a tty.
4+
//! Multiple output types going to stdout will trigger an error too,
5+
//! as they would all be mixed together.
6+
//!
7+
//! See <https://github.com/rust-lang/rust/pull/111626>.
8+
9+
use std::fs::File;
10+
11+
use run_make_support::{diff, run_in_tmpdir, rustc};
12+
13+
// Test emitting text outputs to stdout works correctly
14+
fn run_diff(name: &str, file_args: &[&str]) {
15+
rustc().emit(format!("{name}={name}")).input("test.rs").args(file_args).run();
16+
let out = rustc().emit(format!("{name}=-")).input("test.rs").run().stdout_utf8();
17+
diff().expected_file(name).actual_text("stdout", &out).run();
18+
}
19+
20+
// Test that emitting binary formats to a terminal gives the correct error
21+
fn run_terminal_err_diff(name: &str) {
22+
#[cfg(not(windows))]
23+
let terminal = File::create("/dev/ptmx").unwrap();
24+
// FIXME: If this test fails and the compiler does print to the console,
25+
// then this will produce a lot of output.
26+
// We should spawn a new console instead to print stdout.
27+
#[cfg(windows)]
28+
let terminal = File::options().read(true).write(true).open(r"\\.\CONOUT$").unwrap();
29+
30+
let err = File::create(name).unwrap();
31+
rustc().emit(format!("{name}=-")).input("test.rs").stdout(terminal).stderr(err).run_fail();
32+
diff().expected_file(format!("emit-{name}.stderr")).actual_file(name).run();
33+
}
34+
35+
fn main() {
36+
run_in_tmpdir(|| {
37+
run_diff("asm", &[]);
38+
run_diff("llvm-ir", &[]);
39+
run_diff("dep-info", &["-Zdep-info-omit-d-target=yes"]);
40+
run_diff("mir", &[]);
41+
42+
run_terminal_err_diff("llvm-bc");
43+
run_terminal_err_diff("obj");
44+
run_terminal_err_diff("metadata");
45+
run_terminal_err_diff("link");
46+
47+
// Test error for emitting multiple types to stdout
48+
rustc()
49+
.input("test.rs")
50+
.emit("asm=-")
51+
.emit("llvm-ir=-")
52+
.emit("dep-info=-")
53+
.emit("mir=-")
54+
.stderr(File::create("multiple-types").unwrap())
55+
.run_fail();
56+
diff().expected_file("emit-multiple-types.stderr").actual_file("multiple-types").run();
57+
58+
// Same as above, but using `-o`
59+
rustc()
60+
.input("test.rs")
61+
.output("-")
62+
.emit("asm,llvm-ir,dep-info,mir")
63+
.stderr(File::create("multiple-types-option-o").unwrap())
64+
.run_fail();
65+
diff()
66+
.expected_file("emit-multiple-types.stderr")
67+
.actual_file("multiple-types-option-o")
68+
.run();
69+
70+
// Test that `-o -` redirected to a file works correctly (#26719)
71+
rustc().input("test.rs").output("-").stdout(File::create("out-stdout").unwrap()).run();
72+
});
73+
}

0 commit comments

Comments
 (0)