Skip to content

Commit df8d4ba

Browse files
committed
WIP
1 parent 21bf896 commit df8d4ba

File tree

2 files changed

+52
-12
lines changed
  • src/tools/run-make-support/src/external_deps
  • tests/run-make/emit-to-stdout

2 files changed

+52
-12
lines changed

src/tools/run-make-support/src/external_deps/rustc.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ffi::{OsStr, OsString};
22
use std::path::Path;
3+
use std::process::Stdio;
34

45
use crate::command::Command;
56
use crate::env::env_var;
@@ -294,6 +295,14 @@ impl Rustc {
294295
self
295296
}
296297

298+
/// Configuration for the child process’s standard output (stdout) handle.
299+
///
300+
/// See [`std::process::Command::stdout`].
301+
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self {
302+
self.cmd.stdout(cfg);
303+
self
304+
}
305+
297306
/// Specify a stdin input buffer.
298307
pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
299308
self.cmd.stdin_buf(input);

tests/run-make/emit-to-stdout/rmake.rs

+43-12
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,29 @@
55
// trigger an error too, as they will all be mixed together.
66
// See https://github.com/rust-lang/rust/pull/111626
77

8+
use std::io::IsTerminal;
9+
810
use run_make_support::{diff, rfs, rustc};
911

1012
fn main() {
1113
rfs::create_dir("out");
14+
15+
#[cfg(not(windows))]
16+
let stdout = std::fs::File::options().write(true).open("/dev/ptmx").unwrap();
17+
// FIXME: If this test fails and the compiler does print to the console, then this will produce a lot of output.
18+
// We should spawn a new console instead to print stdout.
19+
#[cfg(windows)]
20+
let stdout = std::fs::File::options().read(true).write(true).open(r"\\.\CONOUT$").unwrap();
21+
22+
assert!(stdout.is_terminal());
1223
test_asm();
1324
test_llvm_ir();
1425
test_dep_info();
1526
test_mir();
16-
test_llvm_bc();
17-
test_obj();
18-
test_metadata();
19-
test_link();
27+
test_llvm_bc(&stdout);
28+
test_obj(&stdout);
29+
test_metadata(&stdout);
30+
test_link(&stdout);
2031
test_multiple_types();
2132
test_multiple_types_option_o();
2233
}
@@ -50,26 +61,46 @@ fn test_mir() {
5061
}
5162

5263
// FIXME: ptmx
53-
fn test_llvm_bc() {
54-
let emit = rustc().emit("llvm-bc=-").input("test.rs").run().stderr_utf8();
64+
fn test_llvm_bc(stdout: &std::fs::File) {
65+
let emit = rustc()
66+
.emit("llvm-bc=-")
67+
.stdout(stdout.try_clone().unwrap())
68+
.input("test.rs")
69+
.run_fail()
70+
.stderr_utf8();
5571
diff().expected_file("emit-llvm-bc.stderr").actual_text("actual", &emit).run();
5672
}
5773

5874
// FIXME: ptmx
59-
fn test_obj() {
60-
let emit = rustc().emit("obj=-").input("test.rs").run().stderr_utf8();
75+
fn test_obj(stdout: &std::fs::File) {
76+
let emit = rustc()
77+
.emit("obj=-")
78+
.stdout(stdout.try_clone().unwrap())
79+
.input("test.rs")
80+
.run_fail()
81+
.stderr_utf8();
6182
diff().expected_file("emit-obj.stderr").actual_text("actual", &emit).run();
6283
}
6384

6485
// FIXME: ptmx
65-
fn test_metadata() {
66-
let emit = rustc().emit("metadata=-").input("test.rs").run().stderr_utf8();
86+
fn test_metadata(stdout: &std::fs::File) {
87+
let emit = rustc()
88+
.emit("metadata=-")
89+
.input("test.rs")
90+
.stdout(stdout.try_clone().unwrap())
91+
.run_fail()
92+
.stderr_utf8();
6793
diff().expected_file("emit-metadata.stderr").actual_text("actual", &emit).run();
6894
}
6995

7096
// FIXME: ptmx
71-
fn test_link() {
72-
let emit = rustc().emit("link=-").input("test.rs").run().stderr_utf8();
97+
fn test_link(stdout: &std::fs::File) {
98+
let emit = rustc()
99+
.emit("link=-")
100+
.input("test.rs")
101+
.stdout(stdout.try_clone().unwrap())
102+
.run_fail()
103+
.stderr_utf8();
73104
diff().expected_file("emit-link.stderr").actual_text("actual", &emit).run();
74105
}
75106

0 commit comments

Comments
 (0)