Execute a command in a working directory and verify it succeeds. On Windows, commands are wrapped in `cmd /C` to support `.bat` and `.cmd` files (e.g., `emcc.bat`, `emcmake.cmd`), which don't work with direct execution. Returns an error if the command fails (non-zero exit code).
(prog: &str, args: &[S], cwd: &Path)
| 11 | /// |
| 12 | /// Returns an error if the command fails (non-zero exit code). |
| 13 | fn run_command<S: AsRef<str>>(prog: &str, args: &[S], cwd: &Path) -> anyhow::Result<()> { |
| 14 | #[cfg(windows)] |
| 15 | { |
| 16 | let mut pieces: Vec<String> = Vec::with_capacity(1 + args.len()); |
| 17 | pieces.push(prog.to_string()); |
| 18 | pieces.extend(args.iter().map(|s| s.as_ref().to_string())); |
| 19 | duct::cmd("cmd", std::iter::once("/C").chain(pieces.iter().map(String::as_str))) |
| 20 | .dir(cwd) |
| 21 | .run() |
| 22 | .with_context(|| format!("failed running `{prog}`"))?; |
| 23 | } |
| 24 | #[cfg(not(windows))] |
| 25 | { |
| 26 | duct::cmd(prog, args.iter().map(|s| s.as_ref())) |
| 27 | .dir(cwd) |
| 28 | .run() |
| 29 | .with_context(|| format!("failed running `{prog}`"))?; |
| 30 | } |
| 31 | Ok(()) |
| 32 | } |
| 33 | |
| 34 | pub(crate) fn build_cpp(project_path: &Path, build_debug: bool) -> anyhow::Result<PathBuf> { |
| 35 | // Verify required tools are in PATH |
no test coverage detected
searching dependent graphs…