Skip to content

Commit

Permalink
Respect wasm file placed in a temp path by rustdoc (#2881)
Browse files Browse the repository at this point in the history
* Respect wasm file placed in a temp path by rustdoc

* fmt
  • Loading branch information
ranile committed May 9, 2022
1 parent 820c5f1 commit 60cbce5
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions crates/cli/src/bin/wasm-bindgen-test-runner/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,25 @@ fn main() -> anyhow::Result<()> {
None => bail!("must have a file to test as first argument"),
};

// Assume a cargo-like directory layout and generate output at
// `target/wasm32-unknown-unknown/wbg-tmp/...`
let tmpdir = 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("wbg-tmp"))
.ok_or_else(|| anyhow!("file to test doesn't follow the expected Cargo conventions"))?;
// wasm_file_to_test may be
// - a cargo-like directory layout and generate output at
// `target/wasm32-unknown-unknown/...`
// - 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<hash> directory
} else {
wasm_file_to_test
.parent() // chop off file name
.and_then(|p| dbg!(p.parent())) // chop off `deps`
.and_then(|p| dbg!(p.parent())) // chop off `debug`
}
.map(|p| p.join("wbg-tmp"))
.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));
Expand Down

0 comments on commit 60cbce5

Please sign in to comment.