Skip to content

Commit 2031eac

Browse files
committed
run_make_support: rename Command::stdin to stdin_buf and add std{in,out,err} config helpers
Previously `Command::stdin` was actually just a stdin buffer helper, but this is different from `std::process::Command::stdin`. This is needlessly confusing, and blocks support to add `std{in,out,err}` config that tests may want to use to e.g. redirect to `/dev/ptmx`.
1 parent 009e738 commit 2031eac

5 files changed

Lines changed: 67 additions & 22 deletions

File tree

‎src/tools/run-make-support/src/command.rs‎

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,58 @@ use crate::{
2929
#[derive(Debug)]
3030
pubstructCommand{
3131
cmd:StdCommand,
32-
stdin:Option<Box<[u8]>>,
32+
// Convience for providing a quick stdin buffer.
33+
stdin_buf:Option<Box<[u8]>>,
34+
35+
// Configurations for child process's std{in,out,err} handles.
36+
stdin:Option<Stdio>,
37+
stdout:Option<Stdio>,
38+
stderr:Option<Stdio>,
39+
3340
drop_bomb:DropBomb,
3441
}
3542

3643
implCommand{
3744
#[track_caller]
3845
pubfnnew<P:AsRef<OsStr>>(program:P) -> Self{
3946
let program = program.as_ref();
40-
Self{cmd:StdCommand::new(program),stdin:None,drop_bomb:DropBomb::arm(program)}
47+
Self{
48+
cmd:StdCommand::new(program),
49+
stdin_buf:None,
50+
drop_bomb:DropBomb::arm(program),
51+
stdin:None,
52+
stdout:None,
53+
stderr:None,
54+
}
55+
}
56+
57+
/// Specify a stdin input buffer. This is a convenience helper,
58+
pubfnstdin_buf<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
59+
self.stdin_buf = Some(input.as_ref().to_vec().into_boxed_slice());
60+
self
61+
}
62+
63+
/// Configuration for the child process’s standard input (stdin) handle.
64+
///
65+
/// See [`std::process::Command::stdin`].
66+
pubfnstdin<T:Into<Stdio>>(&mutself,cfg:T) -> &mutSelf{
67+
self.stdin = Some(cfg.into());
68+
self
69+
}
70+
71+
/// Configuration for the child process’s standard output (stdout) handle.
72+
///
73+
/// See [`std::process::Command::stdout`].
74+
pubfnstdout<T:Into<Stdio>>(&mutself,cfg:T) -> &mutSelf{
75+
self.stdout = Some(cfg.into());
76+
self
4177
}
4278

43-
/// Specify a stdin input
44-
pubfnstdin<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
45-
self.stdin = Some(input.as_ref().to_vec().into_boxed_slice());
79+
/// Configuration for the child process’s standard error (stderr) handle.
80+
///
81+
/// See [`std::process::Command::stderr`].
82+
pubfnstderr<T:Into<Stdio>>(&mutself,cfg:T) -> &mutSelf{
83+
self.stderr = Some(cfg.into());
4684
self
4785
}
4886

@@ -105,6 +143,8 @@ impl Command {
105143
}
106144

107145
/// Run the constructed command and assert that it is successfully run.
146+
///
147+
/// By default, std{in,out,err} are [`Stdio::piped()`].
108148
#[track_caller]
109149
pubfnrun(&mutself) -> CompletedProcess{
110150
let output = self.command_output();
@@ -115,6 +155,8 @@ impl Command {
115155
}
116156

117157
/// Run the constructed command and assert that it does not successfully run.
158+
///
159+
/// By default, std{in,out,err} are [`Stdio::piped()`].
118160
#[track_caller]
119161
pubfnrun_fail(&mutself) -> CompletedProcess{
120162
let output = self.command_output();
@@ -124,10 +166,10 @@ impl Command {
124166
output
125167
}
126168

127-
/// Run the command but do not check its exit status.
128-
/// Only use if you explicitly don't care about the exit status.
129-
/// Prefer to use [`Self::run`] and [`Self::run_fail`]
130-
/// whenever possible.
169+
/// Run the command but do not check its exit status. Only use if you explicitly don't care
170+
/// about the exit status.
171+
///
172+
/// Prefer to use [`Self::run`] and [`Self::run_fail`] whenever possible.
131173
#[track_caller]
132174
pubfnrun_unchecked(&mutself) -> CompletedProcess{
133175
self.command_output()
@@ -137,11 +179,11 @@ impl Command {
137179
fncommand_output(&mutself) -> CompletedProcess{
138180
self.drop_bomb.defuse();
139181
// let's make sure we piped all the input and outputs
140-
self.cmd.stdin(Stdio::piped());
141-
self.cmd.stdout(Stdio::piped());
142-
self.cmd.stderr(Stdio::piped());
182+
self.cmd.stdin(self.stdin.take().unwrap_or(Stdio::piped()));
183+
self.cmd.stdout(self.stdout.take().unwrap_or(Stdio::piped()));
184+
self.cmd.stderr(self.stderr.take().unwrap_or(Stdio::piped()));
143185

144-
let output = ifletSome(input) = &self.stdin{
186+
let output = ifletSome(input) = &self.stdin_buf{
145187
letmut child = self.cmd.spawn().unwrap();
146188

147189
{

‎src/tools/run-make-support/src/external_deps/llvm.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ impl LlvmFilecheck {
227227
Self{ cmd }
228228
}
229229

230-
/// Pipe a read file into standard input containing patterns that will be matched against the .patterns(path) call.
231-
pubfnstdin<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
232-
self.cmd.stdin(input);
230+
/// Provide a buffer representing standard input containing patterns that will be matched
231+
/// against the `.patterns(path)` call.
232+
pubfnstdin_buf<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
233+
self.cmd.stdin_buf(input);
233234
self
234235
}
235236

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ impl Rustc {
291291
self
292292
}
293293

294-
/// Specify a stdin input
295-
pubfnstdin<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
296-
self.cmd.stdin(input);
294+
/// Specify a stdin input buffer.
295+
pubfnstdin_buf<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
296+
self.cmd.stdin_buf(input);
297297
self
298298
}
299299

‎src/tools/run-make-support/src/external_deps/rustdoc.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ impl Rustdoc {
8585
self
8686
}
8787

88-
/// Specify a stdin input
89-
pubfnstdin<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
90-
self.cmd.stdin(input);
88+
/// Specify a stdin input buffer.
89+
pubfnstdin_buf<I:AsRef<[u8]>>(&mutself,input:I) -> &mutSelf{
90+
self.cmd.stdin_buf(input);
9191
self
9292
}
9393

‎src/tools/run-make-support/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ pub mod rfs {
3434
}
3535

3636
// Re-exports of third-party library crates.
37+
// tidy-alphabetical-start
3738
pubuse bstr;
3839
pubuse gimli;
3940
pubuse libc;
4041
pubuse object;
4142
pubuse regex;
4243
pubuse serde_json;
4344
pubuse wasmparser;
45+
// tidy-alphabetical-end
4446

4547
// Re-exports of external dependencies.
4648
pubuse external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rustdoc};

0 commit comments

Comments
 (0)