From 6f40465aa0ebc558ad6c0d2197cc022c6a26177e Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Mon, 12 Aug 2024 22:48:51 +0100 Subject: [PATCH] prettify build.rs a bit --- crates/librqbit/build.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/librqbit/build.rs b/crates/librqbit/build.rs index 61576eb..1b3779a 100644 --- a/crates/librqbit/build.rs +++ b/crates/librqbit/build.rs @@ -1,7 +1,36 @@ -use anyhow::Context; +use anyhow::{bail, Context}; use std::path::Path; use std::process::Command; +fn run(cwd: &Path, cmd: &str) -> anyhow::Result<()> { + #[cfg(target_os = "windows")] + let (shell, shell_args) = ("powershell", ["-command"].as_slice()); + #[cfg(not(target_os = "windows"))] + let (shell, shell_args) = ("bash", ["-c"].as_slice()); + + // Run "npm install" in the webui directory + let output = Command::new(shell) + .args(shell_args) + .arg(cmd) + .current_dir(cwd) + .output() + .with_context(|| format!("Failed to execute {} in {:?}", cmd, cwd))?; + + if !output.status.success() { + bail!( + "\"{}\" failed\n\nstderr: {}\n\nstdout: {}", + cmd, + String::from_utf8_lossy(&output.stderr), + String::from_utf8_lossy(&output.stdout) + ); + } + + // Optionally print the stdout output if you want to see the build logs + println!("{}", String::from_utf8_lossy(&output.stdout)); + + Ok(()) +} + fn main() { #[cfg(feature = "webui")] {