feat(bidngen): we don't need to read stdout to know it will fail

master
Ashley Williams 6 years ago
parent fdde7291ca
commit a3541196c7
  1. 21
      src/bindgen.rs
  2. 30
      src/child.rs

@ -69,29 +69,10 @@ pub fn wasm_bindgen_build(
cmd.arg("--keep-debug"); cmd.arg("--keep-debug");
} }
let result = child::run(cmd, "wasm-bindgen"); child::run(cmd, "wasm-bindgen").context("Running the wasm-bindgen CLI")?;
let result: Result<(), failure::Error> = match result {
Ok(r) => Ok(r),
Err(e) => process_error(&bindgen_path, e),
};
result.context("Running the wasm-bindgen CLI")?;
Ok(()) Ok(())
} }
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'") => {
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. /// Check if the `wasm-bindgen` dependency is locally satisfied.
fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str) -> bool { fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str) -> bool {
wasm_bindgen_get_version(bindgen_path) wasm_bindgen_get_version(bindgen_path)

@ -3,6 +3,7 @@
//! This module helps us ensure that all child processes that we spawn get //! This module helps us ensure that all child processes that we spawn get
//! properly logged and their output is logged as well. //! properly logged and their output is logged as well.
use failure::Error;
use install::Tool; use install::Tool;
use log::info; use log::info;
use std::io::Error as StdError; use std::io::Error as StdError;
@ -54,26 +55,19 @@ impl CommandError {
} }
/// Run the given command and return on success. /// Run the given command and return on success.
pub fn run(mut command: Command, command_name: &str) -> Result<(), CommandError> { pub fn run(mut command: Command, command_name: &str) -> Result<(), Error> {
info!("Running {:?}", command); info!("Running {:?}", command);
let cmd_output = command let status = command.status()?;
.stdin(Stdio::inherit())
.stdout(Stdio::inherit()) if status.success() {
.output(); Ok(())
match cmd_output { } else {
Ok(output) => { bail!(
if output.status.success() { "failed to execute `{}`: exited with {}",
Ok(()) command_name,
} else { status
Err(CommandError::from_status( )
command_name,
output.status,
Some(String::from_utf8_lossy(&output.stderr).into_owned()),
))
}
}
Err(e) => Err(CommandError::from_error(command_name, e)),
} }
} }

Loading…
Cancel
Save