Skip to content

Commit d9f513f

Browse files
jieyouxuJesus Checa Hidalgo
and
Jesus Checa Hidalgo
committed
run-make-support: support "ejecting" the underlying std command
In rare cases, the test may need access to the underlying `std::process::Command` (e.g. for non-trivial process spawning). Co-authored-by: Jesus Checa Hidalgo <[email protected]>
1 parent a7b1b24 commit d9f513f

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ impl Command {
6363
}
6464
}
6565

66+
// Internal-only.
67+
pub(crate) fn into_raw_command(mut self) -> std::process::Command {
68+
self.drop_bomb.defuse();
69+
self.cmd
70+
}
71+
6672
/// Specify a stdin input buffer. This is a convenience helper,
6773
pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
6874
self.stdin_buf = Some(input.as_ref().to_vec().into_boxed_slice());

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::command::Command;
55
use crate::env::env_var;
66
use crate::util::set_host_compiler_dylib_path;
77

8-
/// Construct a new `rustdoc` invocation.
8+
/// Construct a new `rustdoc` invocation. This will configure the host compiler runtime libs.
99
#[track_caller]
1010
pub fn rustdoc() -> Rustdoc {
1111
Rustdoc::new()
@@ -28,7 +28,7 @@ fn setup_common() -> Command {
2828
}
2929

3030
impl Rustdoc {
31-
/// Construct a bare `rustdoc` invocation.
31+
/// Construct a bare `rustdoc` invocation. This will configure the host compiler runtime libs.
3232
#[track_caller]
3333
pub fn new() -> Self {
3434
let cmd = setup_common();

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

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
macro_rules! impl_common_helpers {
2929
($wrapper: ident) => {
3030
impl $wrapper {
31+
/// In very rare circumstances, you may need a e.g. `bare_rustc()` or `bare_rustdoc()`
32+
/// with host runtime libs configured, but want the underlying raw
33+
/// [`std::process::Command`] (e.g. for manipulating pipes or whatever). This function
34+
/// will consume the command wrapper and extract the underlying
35+
/// [`std::process::Command`].
36+
///
37+
/// Caution: this will mean that you can no longer use the convenience methods on the
38+
/// command wrapper. Use as a last resort.
39+
pub fn into_raw_command(self) -> ::std::process::Command {
40+
self.cmd.into_raw_command()
41+
}
42+
3143
/// Specify an environment variable.
3244
pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Self
3345
where

0 commit comments

Comments
 (0)