| 1 | use std::{ |
| 2 | ffi::OsString, |
| 3 | path::{Path, PathBuf}, |
| 4 | process::Command, |
| 5 | }; |
| 6 | |
| 7 | /// `Tool` found by `find-msvc-tools` |
| 8 | #[derive(Clone, Debug)] |
| 9 | pub struct Tool { |
| 10 | pub(crate) tool: PathBuf, |
| 11 | pub(crate) is_clang_cl: bool, |
| 12 | pub(crate) env: Vec<(OsString, OsString)>, |
| 13 | } |
| 14 | |
| 15 | impl Tool { |
| 16 | /// Converts this compiler into a `Command` that's ready to be run. |
| 17 | /// |
| 18 | /// This is useful for when the compiler needs to be executed and the |
| 19 | /// command returned will already have the initial arguments and environment |
| 20 | /// variables configured. |
| 21 | pub fn to_command(&self) -> Command { |
| 22 | let mut cmd = Command::new(&self.tool); |
| 23 | |
| 24 | for (k, v) in self.env.iter() { |
| 25 | cmd.env(k, v); |
| 26 | } |
| 27 | |
| 28 | cmd |
| 29 | } |
| 30 | |
| 31 | /// Check is the tool clang-cl related |
| 32 | pub fn is_clang_cl(&self) -> bool { |
| 33 | self.is_clang_cl |
| 34 | } |
| 35 | |
| 36 | /// Get path to the tool |
| 37 | pub fn path(&self) -> &Path { |
| 38 | &self.tool |
| 39 | } |
| 40 | |
| 41 | /// Get environment variables for the tools |
| 42 | pub fn env(&self) -> impl IntoIterator<Item = &(OsString, OsString)> { |
| 43 | &self.env |
| 44 | } |
| 45 | } |