Get the wasm-bindgen version and display it in the error message

master
Kirk Turner 6 years ago
parent 97fdc94d53
commit 64f835c0f2
  1. 45
      src/bindgen.rs

@ -204,7 +204,7 @@ pub fn wasm_bindgen_build(
Target::Bundler => "--browser",
};
let bindgen_path = bindgen.binary("wasm-bindgen")?;
let mut cmd = Command::new(bindgen_path);
let mut cmd = Command::new(&bindgen_path);
cmd.arg(&wasm_path)
.arg("--out-dir")
.arg(out_dir)
@ -229,42 +229,47 @@ pub fn wasm_bindgen_build(
let result = child::run(cmd, "wasm-bindgen");
let result: Result<(), failure::Error> = match result {
Ok(r) => Ok(r),
Err(e) => process_error(e),
Err(e) => process_error(&bindgen_path, e),
};
result.context("Running the wasm-bindgen CLI")?;
Ok(())
}
fn process_error(e: child::CommandError) -> Result<(), failure::Error> {
fn process_error(bindgen_path: &PathBuf, e: child::CommandError) -> Result<(), failure::Error> {
match &e.stderr {
Some(err) if err.trim().starts_with("Unknown flag: '--web'") =>
bail!("Failed to execute `wasm-bindgen`: --web is not supported. Upgrade wasm-bindgen to a more recent version."),
Some(err) if err.trim().starts_with("Unknown flag: '--web'") => {
let v = wasm_bindgen_get_version(bindgen_path).unwrap_or(String::from("unknown"));
bail!("Failed to execute `wasm-bindgen`: --web is not supported in version '{}'. Upgrade the wasm-bindgen dependency in Cargo.toml to version 0.2.39 or later.", v)
}
Some(err) => {
eprintln!("{}", err);
bail!("{}", e.to_string())
},
}
_ => bail!("{}", e.to_string()),
}
}
/// Check if the `wasm-bindgen` dependency is locally satisfied.
fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str) -> bool {
wasm_bindgen_get_version(bindgen_path)
.map(|v| {
info!(
"Checking installed `wasm-bindgen` version == expected version: {} == {}",
v, dep_version
);
v == dep_version
})
.unwrap_or(false)
}
/// Get the `wasm-bindgen` version
fn wasm_bindgen_get_version(bindgen_path: &PathBuf) -> Option<String> {
let mut cmd = Command::new(bindgen_path);
cmd.arg("--version");
child::run_capture_stdout(cmd, "wasm-bindgen")
.map(|stdout| {
stdout
.trim()
.split_whitespace()
.nth(1)
.map(|v| {
info!(
"Checking installed `wasm-bindgen` version == expected version: {} == {}",
v, dep_version
);
v == dep_version
})
.unwrap_or(false)
.map(|stdout| match stdout.trim().split_whitespace().nth(1) {
Some(v) => return Some(v.to_owned()),
None => return None,
})
.unwrap_or(false)
.unwrap_or(None)
}

Loading…
Cancel
Save