diff --git a/src/common/mod.rs b/src/common/mod.rs index 5a91739e..0dd85dab 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -160,14 +160,19 @@ pub fn strip_prefix(target: &Path) -> &Path { /// Run a global command with the given arguments and make sure it completes successfully. If it /// fails an error is returned. -#[tracing::instrument(level = "trace", skip(name, path, args))] +#[tracing::instrument(level = "trace", skip(name, args))] pub async fn run_command( name: &str, - path: &Path, + path: impl AsRef + Debug, args: &[impl AsRef + Debug], + working_dir: impl AsRef + Debug, ) -> Result<()> { tracing::debug!(?args, "{name} args"); + + let path = path.as_ref(); + let status = Command::new(path) + .current_dir(working_dir.as_ref()) .args(args) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -181,12 +186,14 @@ pub async fn run_command( .wait() .await .with_context(|| format!("error during {name} call"))?; + if !status.success() { bail!( "{name} call to executable '{}' with args: '{args:?}' returned a bad status: {status}", path.display() ); } + Ok(()) } diff --git a/src/pipelines/rust/mod.rs b/src/pipelines/rust/mod.rs index cf05d6fd..f011fed5 100644 --- a/src/pipelines/rust/mod.rs +++ b/src/pipelines/rust/mod.rs @@ -399,7 +399,7 @@ impl RustApp { } } - let build_res = common::run_command("cargo", Path::new("cargo"), &args) + let build_res = common::run_command("cargo", "cargo", &args, &self.cfg.working_directory) .await .context("error during cargo build execution"); @@ -423,6 +423,7 @@ impl RustApp { tracing::debug!("fetching cargo artifacts"); args.push("--message-format=json"); let artifacts_out = Command::new("cargo") + .current_dir(&self.cfg.core.working_directory) .args(args.as_slice()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -536,9 +537,14 @@ impl RustApp { // Invoke wasm-bindgen. tracing::debug!("calling wasm-bindgen for {}", self.name); - common::run_command(wasm_bindgen_name, &wasm_bindgen, &args) - .await - .map_err(|err| check_target_not_found_err(err, wasm_bindgen_name))?; + common::run_command( + wasm_bindgen_name, + &wasm_bindgen, + &args, + &self.cfg.working_directory, + ) + .await + .map_err(|err| check_target_not_found_err(err, wasm_bindgen_name))?; // Copy the generated WASM & JS loader to the dist dir. tracing::debug!("copying generated wasm-bindgen artifacts"); @@ -875,7 +881,7 @@ impl RustApp { // Invoke wasm-opt. tracing::debug!("calling wasm-opt"); - common::run_command(wasm_opt_name, &wasm_opt, &args) + common::run_command(wasm_opt_name, &wasm_opt, &args, &self.cfg.working_directory) .await .map_err(|err| check_target_not_found_err(err, wasm_opt_name))?; diff --git a/src/pipelines/sass.rs b/src/pipelines/sass.rs index 57fd785f..c9fa24a1 100644 --- a/src/pipelines/sass.rs +++ b/src/pipelines/sass.rs @@ -131,7 +131,13 @@ impl Sass { let rel_path = common::strip_prefix(&self.asset.path); tracing::debug!(path = ?rel_path, "compiling sass/scss"); - common::run_command(Application::Sass.name(), &sass, args).await?; + common::run_command( + Application::Sass.name(), + &sass, + args, + &self.cfg.working_directory, + ) + .await?; let css = fs::read_to_string(&temp_target_file_path) .await diff --git a/src/pipelines/tailwind_css.rs b/src/pipelines/tailwind_css.rs index eef58969..728376e8 100644 --- a/src/pipelines/tailwind_css.rs +++ b/src/pipelines/tailwind_css.rs @@ -104,7 +104,13 @@ impl TailwindCss { let rel_path = common::strip_prefix(&self.asset.path); tracing::debug!(path = ?rel_path, "compiling tailwind css"); - common::run_command(Application::TailwindCss.name(), &tailwind, &args).await?; + common::run_command( + Application::TailwindCss.name(), + &tailwind, + &args, + &self.cfg.working_directory, + ) + .await?; let css = fs::read_to_string(&file_path).await?; fs::remove_file(&file_path).await?;