From 205828ce4349f81566e8972e48fdbfddd85db450 Mon Sep 17 00:00:00 2001 From: Sergio Medina Date: Thu, 11 May 2023 13:14:24 +0100 Subject: [PATCH] `wasm-bindgen-test-runner` fix run in parallel in same workspace (#3420) --- .../src/bin/wasm-bindgen-test-runner/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs index 2647104c8a2..63fd48607d8 100644 --- a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs +++ b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs @@ -12,6 +12,7 @@ //! and source code. use anyhow::{anyhow, bail, Context}; +use log::error; use std::env; use std::fs; use std::path::PathBuf; @@ -32,6 +33,16 @@ enum TestMode { Worker { no_modules: bool }, } +struct TmpDirDeleteGuard(PathBuf); + +impl Drop for TmpDirDeleteGuard { + fn drop(&mut self) { + if let Err(e) = fs::remove_dir_all(&self.0) { + error!("failed to remove temporary directory: {}", e); + } + } +} + fn main() -> anyhow::Result<()> { env_logger::init(); let mut args = env::args_os().skip(1); @@ -44,6 +55,11 @@ fn main() -> anyhow::Result<()> { None => bail!("must have a file to test as first argument"), }; + let file_name = wasm_file_to_test + .file_name() + .and_then(|s| s.to_str()) + .context("file to test is not a valid file, can't extract file name")?; + // wasm_file_to_test may be // - a cargo-like directory layout and generate output at // `target/wasm32-unknown-unknown/...` @@ -61,12 +77,13 @@ fn main() -> anyhow::Result<()> { .and_then(|p| p.parent()) // chop off `deps` .and_then(|p| p.parent()) // chop off `debug` } - .map(|p| p.join("wbg-tmp")) + .map(|p| p.join(format!("wbg-tmp-{}", file_name))) .ok_or_else(|| anyhow!("file to test doesn't follow the expected Cargo conventions"))?; // Make sure there's no stale state from before drop(fs::remove_dir_all(&tmpdir)); fs::create_dir(&tmpdir).context("creating temporary directory")?; + let _guard = TmpDirDeleteGuard(tmpdir.clone()); let module = "wasm-bindgen-test";