Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
Check if testsuite exists, set target dir
Browse files Browse the repository at this point in the history
  • Loading branch information
marmistrz authored and sunfishcode committed Aug 24, 2019
1 parent 7e0e8da commit 8db57bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ authors = [
edition = "2018"
license = "Apache-2.0 WITH LLVM-exception"
description = "WASI implementation in Rust"
exclude = ["misc_testsuite/*.wasm"]

[dependencies]
wasi-common-cbindgen = { path = "wasi-common-cbindgen" }
Expand Down
30 changes: 21 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,31 @@ use std::process::{Command, Stdio};
fn main() {
let out_dir =
PathBuf::from(env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"));
println!("OUT_DIR is {:?}", out_dir);
let mut out = File::create(out_dir.join("misc_testsuite_tests.rs"))
.expect("error generating test source file");

build_tests("misc_testsuite").expect("building tests");
test_directory(&mut out, "misc_testsuite").expect("generating tests");
build_tests("misc_testsuite", &out_dir).expect("building tests");
test_directory(&mut out, "misc_testsuite", &out_dir).expect("generating tests");
}

fn build_tests(testsuite: &str) -> io::Result<()> {
fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
// if the submodule has not been checked out, the build will stall
if !Path::new(&format!("{}/Cargo.toml", testsuite)).exists() {
panic!("Testsuite {} not checked out", testsuite);
}

let mut cmd = Command::new("cargo");
cmd.args(&["build", "--release", "--target=wasm32-wasi"])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(testsuite);
cmd.args(&[
"build",
"--release",
"--target=wasm32-wasi",
"--target-dir",
out_dir.to_str().unwrap(),
])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(testsuite);
let output = cmd.output()?;

let status = output.status;
Expand All @@ -41,8 +53,8 @@ fn build_tests(testsuite: &str) -> io::Result<()> {
Ok(())
}

fn test_directory(out: &mut File, testsuite: &str) -> io::Result<()> {
let mut dir_entries: Vec<_> = read_dir(format!("{}/target/wasm32-wasi/release", testsuite))
fn test_directory(out: &mut File, testsuite: &str, out_dir: &Path) -> io::Result<()> {
let mut dir_entries: Vec<_> = read_dir(out_dir.join("wasm32-wasi/release"))
.expect("reading testsuite directory")
.map(|r| r.expect("reading testsuite directory entry"))
.filter(|dir_entry| {
Expand Down

0 comments on commit 8db57bd

Please sign in to comment.