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 <jchecahi@redhat.com>
This commit is contained in:
Jieyou Xu 2025-05-09 19:51:03 +08:00
parent a7b1b24587
commit d9f513f0da
No known key found for this signature in database
GPG key ID: 045B995028EA6AFC
3 changed files with 20 additions and 2 deletions

View file

@ -63,6 +63,12 @@ impl Command {
}
}
// Internal-only.
pub(crate) fn into_raw_command(mut self) -> std::process::Command {
self.drop_bomb.defuse();
self.cmd
}
/// Specify a stdin input buffer. This is a convenience helper,
pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
self.stdin_buf = Some(input.as_ref().to_vec().into_boxed_slice());

View file

@ -5,7 +5,7 @@ use crate::command::Command;
use crate::env::env_var;
use crate::util::set_host_compiler_dylib_path;
/// Construct a new `rustdoc` invocation.
/// Construct a new `rustdoc` invocation. This will configure the host compiler runtime libs.
#[track_caller]
pub fn rustdoc() -> Rustdoc {
Rustdoc::new()
@ -28,7 +28,7 @@ fn setup_common() -> Command {
}
impl Rustdoc {
/// Construct a bare `rustdoc` invocation.
/// Construct a bare `rustdoc` invocation. This will configure the host compiler runtime libs.
#[track_caller]
pub fn new() -> Self {
let cmd = setup_common();

View file

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