Merge pull request #36 from paritytech/fix-wasm-build-new-nightly

Fix wasm build new nightly
This commit is contained in:
Nikolay Volf
2017-11-03 15:28:09 +03:00
committed by GitHub
4 changed files with 48 additions and 22 deletions
+1
View File
@@ -8,3 +8,4 @@ script:
- cargo build --manifest-path gas/Cargo.toml
- cargo build --manifest-path ext/Cargo.toml
- cargo test --verbose
- cargo test --verbose --manifest-path build/Cargo.toml
+3
View File
@@ -12,6 +12,9 @@ clap = "2.24"
glob = "0.2"
byteorder = "1"
[dev-dependencies]
tempdir = "0.3"
[lib]
[[bin]]
+3
View File
@@ -9,5 +9,8 @@ wasm-utils = { path = "../" }
clap = "2.24"
parity-wasm = "0.15"
[dev-dependencies]
tempdir = "0.3"
[[bin]]
name = "wasm-build"
+41 -22
View File
@@ -35,29 +35,15 @@ pub fn wasm_path(target_dir: &str, bin_name: &str) -> String {
}
pub fn process_output(target_dir: &str, bin_name: &str) -> Result<(), Error> {
let mut path = PathBuf::from(target_dir);
let mut cargo_path = PathBuf::from(target_dir);
let wasm_name = bin_name.to_string().replace("-", "_");
path.push("wasm32-unknown-emscripten");
path.push("release");
path.push("deps");
path.push(format!("{}-*.wasm", wasm_name));
cargo_path.push("wasm32-unknown-emscripten");
cargo_path.push("release");
cargo_path.push(format!("{}.wasm", wasm_name));
let mut files = glob::glob(path.to_string_lossy().as_ref()).expect("glob err")
.collect::<Vec<Result<PathBuf, glob::GlobError>>>();
if files.len() == 0 {
return Err(Error::NoSuitableFile(path.to_string_lossy().to_string()));
} else if files.len() > 1 {
return Err(Error::TooManyFiles(
files.into_iter().map(|f| f.expect("glob err").to_string_lossy().to_string())
.fold(String::new(), |mut a, b| { a.push_str(", "); a.push_str(&b); a })
))
} else {
let file = files.drain(..).nth(0).expect("0th element exists").expect("glob err");
let mut path = PathBuf::from(target_dir);
path.push(format!("{}.wasm", bin_name));
fs::copy(file, path)?;
}
let mut target_path = PathBuf::from(target_dir);
target_path.push(format!("{}.wasm", bin_name));
fs::copy(cargo_path, target_path)?;
Ok(())
}
@@ -73,7 +59,7 @@ fn has_ctor(module: &elements::Module) -> bool {
fn main() {
wasm_utils::init_log();
let matches = App::new("wasm-opt")
let matches = App::new("wasm-build")
.arg(Arg::with_name("target")
.index(1)
.required(true)
@@ -147,3 +133,36 @@ fn main() {
}
}
#[cfg(test)]
mod tests {
extern crate tempdir;
use self::tempdir::TempDir;
use std::fs;
use super::process_output;
#[test]
fn processes_cargo_output() {
let tmp_dir = TempDir::new("target").expect("temp dir failed");
let target_path = tmp_dir.path().join("wasm32-unknown-emscripten").join("release");
fs::create_dir_all(target_path.clone()).expect("create dir failed");
{
use std::io::Write;
let wasm_path = target_path.join("example_wasm.wasm");
let mut f = fs::File::create(wasm_path).expect("create fail failed");
f.write(b"\0asm").expect("write file failed");
}
process_output(&tmp_dir.path().to_string_lossy(), "example-wasm").expect("process output failed");
assert!(
fs::metadata(tmp_dir.path().join("example-wasm.wasm")).expect("metadata failed").is_file()
)
}
}