From ada4d7c942321f23a570215bb74f50baa18cfdfc Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 30 Jan 2024 12:11:56 +0100 Subject: [PATCH] Fixed temporary folder detection on MacOS --- CHANGELOG.md | 3 +++ .../src/bin/wasm-bindgen-test-runner/main.rs | 25 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da0f386a3c5..d03b4bc7ce0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,9 @@ * Fixed UB when freeing strings received from JS if not using the default allocator. [#3808](https://github.com/rustwasm/wasm-bindgen/pull/3808) +* Fixed temporary folder detection by `wasm-bindgen-test-runner` on MacOS. + [#3817](https://github.com/rustwasm/wasm-bindgen/pull/3817) + ## [0.2.90](https://github.com/rustwasm/wasm-bindgen/compare/0.2.89...0.2.90) Released 2024-01-06 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 88d5bc686d9..06d386119ed 100644 --- a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs +++ b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs @@ -88,19 +88,18 @@ fn main() -> anyhow::Result<()> { // - a tmp directory, generated by rustdoc // we would like a directory we have write access to. if we assume cargo-like directories, // we end up with the path `/wbg-out` - let tmpdir = if wasm_file_to_test - .to_string_lossy() - .starts_with("/tmp/rustdoc") - { - wasm_file_to_test.parent() // chop off the file name and give us the /tmp/rustdoc directory - } else { - wasm_file_to_test - .parent() // chop off file name - .and_then(|p| p.parent()) // chop off `deps` - .and_then(|p| p.parent()) // chop off `debug` - } - .map(|p| p.join(format!("wbg-tmp-{}", file_name))) - .ok_or_else(|| anyhow!("file to test doesn't follow the expected Cargo conventions"))?; + let wasm_file_str = wasm_file_to_test.to_string_lossy(); + let tmpdir = + if wasm_file_str.starts_with("/tmp/rustdoc") || wasm_file_str.starts_with("/var/folders") { + wasm_file_to_test.parent() // chop off the file name and give us the /tmp/rustdoc directory + } else { + wasm_file_to_test + .parent() // chop off file name + .and_then(|p| p.parent()) // chop off `deps` + .and_then(|p| p.parent()) // chop off `debug` + } + .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));