Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/toolchain/src/lib.rs')
| -rw-r--r-- | crates/toolchain/src/lib.rs | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/crates/toolchain/src/lib.rs b/crates/toolchain/src/lib.rs index 325b94cc33..8b7bf1a806 100644 --- a/crates/toolchain/src/lib.rs +++ b/crates/toolchain/src/lib.rs @@ -27,14 +27,14 @@ impl Tool { /// /// The current implementation checks three places for an executable to use: /// 1) `$CARGO_HOME/bin/<executable_name>` - /// where $CARGO_HOME defaults to ~/.cargo (see <https://doc.rust-lang.org/cargo/guide/cargo-home.html>) - /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. - /// It seems that this is a reasonable place to try for cargo, rustc, and rustup + /// where $CARGO_HOME defaults to ~/.cargo (see <https://doc.rust-lang.org/cargo/guide/cargo-home.html>) + /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. + /// It seems that this is a reasonable place to try for cargo, rustc, and rustup /// 2) Appropriate environment variable (erroring if this is set but not a usable executable) - /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc + /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc /// 3) $PATH/`<executable_name>` - /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the - /// first that exists + /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the + /// first that exists /// 4) If all else fails, we just try to use the executable name directly pub fn prefer_proxy(self) -> Utf8PathBuf { invoke(&[cargo_proxy, lookup_as_env_var, lookup_in_path], self.name()) @@ -44,14 +44,14 @@ impl Tool { /// /// The current implementation checks three places for an executable to use: /// 1) Appropriate environment variable (erroring if this is set but not a usable executable) - /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc + /// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc /// 2) $PATH/`<executable_name>` - /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the - /// first that exists + /// example: for cargo, this tries all paths in $PATH with appended `cargo`, returning the + /// first that exists /// 3) `$CARGO_HOME/bin/<executable_name>` - /// where $CARGO_HOME defaults to ~/.cargo (see <https://doc.rust-lang.org/cargo/guide/cargo-home.html>) - /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. - /// It seems that this is a reasonable place to try for cargo, rustc, and rustup + /// where $CARGO_HOME defaults to ~/.cargo (see <https://doc.rust-lang.org/cargo/guide/cargo-home.html>) + /// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset. + /// It seems that this is a reasonable place to try for cargo, rustc, and rustup /// 4) If all else fails, we just try to use the executable name directly pub fn path(self) -> Utf8PathBuf { invoke(&[lookup_as_env_var, lookup_in_path, cargo_proxy], self.name()) @@ -71,11 +71,22 @@ impl Tool { } } -pub fn command(cmd: impl AsRef<OsStr>, working_directory: impl AsRef<Path>) -> Command { +#[allow(clippy::disallowed_types)] /* generic parameter allows for FxHashMap */ +pub fn command<H>( + cmd: impl AsRef<OsStr>, + working_directory: impl AsRef<Path>, + extra_env: &std::collections::HashMap<String, Option<String>, H>, +) -> Command { // we are `toolchain::command`` #[allow(clippy::disallowed_methods)] let mut cmd = Command::new(cmd); cmd.current_dir(working_directory); + for env in extra_env { + match env { + (key, Some(val)) => cmd.env(key, val), + (key, None) => cmd.env_remove(key), + }; + } cmd } |