Skip to content

Commit

Permalink
wasm-bindgen-test-runner fix run in parallel in same workspace (#3420)
Browse files Browse the repository at this point in the history
  • Loading branch information
lumasepa authored May 11, 2023
1 parent 89219ac commit 205828c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/cli/src/bin/wasm-bindgen-test-runner/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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/...`
Expand All @@ -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";

Expand Down

0 comments on commit 205828c

Please sign in to comment.