Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect wasm file placed in a temp path by rustdoc #2881

Merged
merged 2 commits into from
May 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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