Struct cargo::util::process_builder::ProcessBuilder
source · [−]pub struct ProcessBuilder { /* private fields */ }
Expand description
A builder object for an external process, similar to std::process::Command
.
Implementations
sourceimpl ProcessBuilder
impl ProcessBuilder
sourcepub fn program<T: AsRef<OsStr>>(&mut self, program: T) -> &mut ProcessBuilder
pub fn program<T: AsRef<OsStr>>(&mut self, program: T) -> &mut ProcessBuilder
(chainable) Sets the executable for the process.
sourcepub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut ProcessBuilder
pub fn arg<T: AsRef<OsStr>>(&mut self, arg: T) -> &mut ProcessBuilder
(chainable) Adds arg
to the args list.
sourcepub fn args<T: AsRef<OsStr>>(&mut self, args: &[T]) -> &mut ProcessBuilder
pub fn args<T: AsRef<OsStr>>(&mut self, args: &[T]) -> &mut ProcessBuilder
(chainable) Adds multiple args
to the args list.
sourcepub fn args_replace<T: AsRef<OsStr>>(
&mut self,
args: &[T]
) -> &mut ProcessBuilder
pub fn args_replace<T: AsRef<OsStr>>(
&mut self,
args: &[T]
) -> &mut ProcessBuilder
(chainable) Replaces the args list with the given args
.
sourcepub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut ProcessBuilder
pub fn cwd<T: AsRef<OsStr>>(&mut self, path: T) -> &mut ProcessBuilder
(chainable) Sets the current working directory of the process.
sourcepub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut ProcessBuilder
pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut ProcessBuilder
(chainable) Sets an environment variable for the process.
sourcepub fn env_remove(&mut self, key: &str) -> &mut ProcessBuilder
pub fn env_remove(&mut self, key: &str) -> &mut ProcessBuilder
(chainable) Unsets an environment variable for the process.
sourcepub fn get_program(&self) -> &OsString
pub fn get_program(&self) -> &OsString
Gets the executable name.
sourcepub fn get_env(&self, var: &str) -> Option<OsString>
pub fn get_env(&self, var: &str) -> Option<OsString>
Gets an environment variable as the process will see it (will inherit from environment unless explicitally unset).
sourcepub fn get_envs(&self) -> &BTreeMap<String, Option<OsString>>
pub fn get_envs(&self) -> &BTreeMap<String, Option<OsString>>
Gets all environment variables explicitly set or unset for the process (not inherited vars).
sourcepub fn inherit_jobserver(&mut self, jobserver: &Client) -> &mut Self
pub fn inherit_jobserver(&mut self, jobserver: &Client) -> &mut Self
Sets the make
jobserver. See the jobserver crate for
more information.
sourcepub fn display_env_vars(&mut self) -> &mut Self
pub fn display_env_vars(&mut self) -> &mut Self
Enables environment variable display.
sourcepub fn exec(&self) -> CargoResult<()>
pub fn exec(&self) -> CargoResult<()>
Runs the process, waiting for completion, and mapping non-success exit codes to an error.
sourcepub fn exec_replace(&self) -> CargoResult<()>
pub fn exec_replace(&self) -> CargoResult<()>
Replaces the current process with the target process.
On Unix, this executes the process using the Unix syscall execvp
, which will block
this process, and will only return if there is an error.
On Windows this isn’t technically possible. Instead we emulate it to the best of our ability. One aspect we fix here is that we specify a handler for the Ctrl-C handler. In doing so (and by effectively ignoring it) we should emulate proxying Ctrl-C handling to the application at hand, which will either terminate or handle it itself. According to Microsoft’s documentation at https://docs.microsoft.com/en-us/windows/console/ctrl-c-and-ctrl-break-signals. the Ctrl-C signal is sent to all processes attached to a terminal, which should include our child process. If the child terminates then we’ll reap them in Cargo pretty quickly, and if the child handles the signal then we won’t terminate (and we shouldn’t!) until the process itself later exits.
sourcepub fn exec_with_output(&self) -> CargoResult<Output>
pub fn exec_with_output(&self) -> CargoResult<Output>
Executes the process, returning the stdio output, or an error if non-zero exit status.
sourcepub fn exec_with_streaming(
&self,
on_stdout_line: &mut dyn FnMut(&str) -> CargoResult<()>,
on_stderr_line: &mut dyn FnMut(&str) -> CargoResult<()>,
capture_output: bool
) -> CargoResult<Output>
pub fn exec_with_streaming(
&self,
on_stdout_line: &mut dyn FnMut(&str) -> CargoResult<()>,
on_stderr_line: &mut dyn FnMut(&str) -> CargoResult<()>,
capture_output: bool
) -> CargoResult<Output>
Executes a command, passing each line of stdout and stderr to the supplied callbacks, which can mutate the string data.
If any invocations of these function return an error, it will be propagated.
If capture_output
is true, then all the output will also be buffered
and stored in the returned Output
object. If it is false, no caching
is done, and the callbacks are solely responsible for handling the
output.
sourcepub fn build_command(&self) -> Command
pub fn build_command(&self) -> Command
Converts ProcessBuilder
into a std::process::Command
, and handles the jobserver, if
present.
sourcepub fn wrapped(self, wrapper: Option<impl AsRef<OsStr>>) -> Self
pub fn wrapped(self, wrapper: Option<impl AsRef<OsStr>>) -> Self
Wraps an existing command with the provided wrapper, if it is present and valid.
Examples
use cargo::util::{ProcessBuilder, process};
// Running this would execute `rustc`
let cmd: ProcessBuilder = process("rustc");
// Running this will execute `sccache rustc`
let cmd = cmd.wrapped(Some("sccache"));
Trait Implementations
sourceimpl Clone for ProcessBuilder
impl Clone for ProcessBuilder
sourcefn clone(&self) -> ProcessBuilder
fn clone(&self) -> ProcessBuilder
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for ProcessBuilder
impl Debug for ProcessBuilder
Auto Trait Implementations
impl RefUnwindSafe for ProcessBuilder
impl Send for ProcessBuilder
impl Sync for ProcessBuilder
impl Unpin for ProcessBuilder
impl UnwindSafe for ProcessBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more