diff --git a/Cargo.lock b/Cargo.lock index 55082a7..f14e2a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -89,7 +89,7 @@ name = "binary-install" version = "0.0.1" dependencies = [ "curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", - "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -194,7 +194,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -214,7 +214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "clicolors-control 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -231,7 +231,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -296,7 +296,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -307,11 +307,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "dirs" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -457,17 +457,6 @@ dependencies = [ "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "indicatif" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "console 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "is_executable" version = "0.1.2" @@ -497,7 +486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -599,7 +588,7 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.41 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -896,27 +885,15 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex" version = "1.1.0" @@ -929,14 +906,6 @@ dependencies = [ "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex-syntax" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "regex-syntax" version = "0.6.5" @@ -984,7 +953,7 @@ name = "schannel" version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1217,7 +1186,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1308,13 +1277,12 @@ dependencies = [ "console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", "dialoguer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.18 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1448,7 +1416,7 @@ dependencies = [ "checksum curl-sys 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ca79238a79fb294be6173b4057c95b22a718c94c4e38475d5faa82b8383f3502" "checksum dialoguer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ad1c29a0368928e78c551354dbff79f103a962ad820519724ef0d74f1c62fa9" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" -"checksum dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "88972de891f6118092b643d85a0b28e0678e0f948d7f879aa32f2d5aafe97d2a" +"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" "checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" @@ -1466,12 +1434,11 @@ dependencies = [ "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21638c5955a6daf3ecc42cae702335fc37a72a4abcc6959ce457b31a7d43bbdd" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" -"checksum indicatif 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a29b2fa6f00010c268bface64c18bb0310aaa70d46a195d5382d288c477fb016" "checksum is_executable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577" "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" -"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e" "checksum libflate 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "54d1ddf9c52870243c5689d7638d888331c1116aa5b398f3ba1acfa7d8758ca1" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" @@ -1518,10 +1485,8 @@ dependencies = [ "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum redox_users 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "214a97e49be64fd2c86f568dd0cb2c757d2cc53de95b273b6ad0a1c908482f26" -"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" +"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828" "checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" -"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" "checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" diff --git a/Cargo.toml b/Cargo.toml index a031588..2055028 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,6 @@ env_logger = { version = "0.5.13", default-features = false } failure = "0.1.2" human-panic = "1.0.1" glob = "0.2" -indicatif = "0.9.0" -lazy_static = "1.1.0" log = "0.4.6" openssl = { version = '0.10.11', optional = true } parking_lot = "0.6" @@ -39,6 +37,7 @@ walkdir = "2" [dev-dependencies] assert_cmd = "0.10.2" +lazy_static = "1.1.0" predicates = "1.0.0" tempfile = "3" diff --git a/src/bindgen.rs b/src/bindgen.rs index 630ffec..bf30d78 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -8,7 +8,6 @@ use failure::{self, ResultExt}; use log::debug; use log::{info, warn}; use manifest::CrateData; -use progressbar::Step; use std::env; use std::fs; use std::path::{Path, PathBuf}; @@ -27,7 +26,6 @@ pub fn install_wasm_bindgen( cache: &Cache, version: &str, install_permitted: bool, - step: &Step, ) -> Result { // If `wasm-bindgen` is installed globally and it has the right version, use // that. Assume that other tools are installed next to it. @@ -42,7 +40,7 @@ pub fn install_wasm_bindgen( } let msg = format!("{}Installing wasm-bindgen...", emoji::DOWN_ARROW); - PBAR.step(step, &msg); + PBAR.info(&msg); let dl = download_prebuilt_wasm_bindgen(&cache, version, install_permitted); match dl { @@ -178,11 +176,7 @@ pub fn wasm_bindgen_build( disable_dts: bool, target: &Target, profile: BuildProfile, - step: &Step, ) -> Result<(), failure::Error> { - let msg = format!("{}Running wasm-bindgen...", emoji::RUNNER); - PBAR.step(step, &msg); - let release_or_debug = match profile { BuildProfile::Release | BuildProfile::Profiling => "release", BuildProfile::Dev => "debug", @@ -235,7 +229,7 @@ pub fn wasm_bindgen_build( fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str) -> bool { let mut cmd = Command::new(bindgen_path); cmd.arg("--version"); - child::run(cmd, "wasm-bindgen") + child::run_capture_stdout(cmd, "wasm-bindgen") .map(|stdout| { stdout .trim() diff --git a/src/build.rs b/src/build.rs index 65bc1eb..845e2da 100644 --- a/src/build.rs +++ b/src/build.rs @@ -4,16 +4,13 @@ use child; use command::build::BuildProfile; use emoji; use failure::{Error, ResultExt}; -use progressbar::Step; use std::path::Path; use std::process::Command; use std::str; use PBAR; /// Ensure that `rustc` is present and that it is >= 1.30.0 -pub fn check_rustc_version(step: &Step) -> Result { - let msg = format!("{}Checking `rustc` version...", emoji::CRAB); - PBAR.step(step, &msg); +pub fn check_rustc_version() -> Result { let local_minor_version = rustc_minor_version(); match local_minor_version { Some(mv) => { @@ -51,9 +48,22 @@ fn rustc_minor_version() -> Option { /// Ensure that `rustup` has the `wasm32-unknown-unknown` target installed for /// current toolchain -pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> { - let msg = format!("{}Adding the Wasm target...", emoji::TARGET); - PBAR.step(step, &msg); +pub fn rustup_add_wasm_target() -> Result<(), Error> { + let mut cmd = Command::new("rustc"); + cmd.arg("--print").arg("sysroot"); + let output = + child::run_capture_stdout(cmd, "rustc").context("Learning about rustc's sysroot")?; + let sysroot = Path::new(output.trim()); + + // If this exists then we for sure have a wasm32 target so there's no need + // to progress further. + if sysroot.join("lib/rustlib/wasm32-unknown-unknown").exists() { + return Ok(()); + } + + // ... otherwise fall back to rustup to add the target + let msg = format!("{}Adding Wasm target...", emoji::TARGET); + PBAR.info(&msg); let mut cmd = Command::new("rustup"); cmd.arg("target").arg("add").arg("wasm32-unknown-unknown"); child::run(cmd, "rustup").context("Adding the wasm32-unknown-unknown target with rustup")?; @@ -64,11 +74,10 @@ pub fn rustup_add_wasm_target(step: &Step) -> Result<(), Error> { pub fn cargo_build_wasm( path: &Path, profile: BuildProfile, - step: &Step, extra_options: &Vec, ) -> Result<(), Error> { let msg = format!("{}Compiling to Wasm...", emoji::CYCLONE); - PBAR.step(step, &msg); + PBAR.info(&msg); let mut cmd = Command::new("cargo"); cmd.current_dir(path).arg("build").arg("--lib"); match profile { diff --git a/src/child.rs b/src/child.rs index 7246ef6..a5cfce8 100644 --- a/src/child.rs +++ b/src/child.rs @@ -5,21 +5,7 @@ use failure::Error; use log::info; -use std::{ - io::{self, Read}, - mem, - process::{Command, Stdio}, - string, - sync::mpsc, - thread, -}; -use PBAR; - -#[derive(Debug)] -enum OutputFragment { - Stdout(Vec), - Stderr(Vec), -} +use std::process::{Command, Stdio}; /// Return a new Command object pub fn new_command(program: &str) -> Command { @@ -37,151 +23,39 @@ pub fn new_command(program: &str) -> Command { } } -/// Read data from the give reader and send it as an `OutputFragment` over the -/// given sender. -fn read_and_send( - mut reader: R, - sender: &mpsc::Sender, - mut map: F, -) -> io::Result<()> -where - R: Read, - F: FnMut(Vec) -> OutputFragment, -{ - let mut buf = vec![0; 1024]; - loop { - match reader.read(&mut buf) { - Err(e) => { - if e.kind() == io::ErrorKind::Interrupted { - continue; - } else { - return Err(e); - } - } - Ok(0) => return Ok(()), - Ok(n) => { - buf.truncate(n); - let buf = mem::replace(&mut buf, vec![0; 1024]); - sender.send(map(buf)).unwrap(); - } - } - } -} - -/// Accumulates output from a stream of output fragments and calls a callback on -/// each complete line as it is accumulating. -struct OutputAccumulator { - result: String, - in_progress: Vec, - on_each_line: F, -} - -impl OutputAccumulator -where - F: FnMut(&str), -{ - /// Construct a new output accumulator with the given `on_each_line` - /// callback. - fn new(on_each_line: F) -> OutputAccumulator { - OutputAccumulator { - result: String::new(), - in_progress: Vec::new(), - on_each_line, - } - } - - /// Add another fragment of output to the accumulation, calling the - /// `on_each_line` callback for any complete lines we accumulate. - fn push(&mut self, fragment: Vec) -> Result<(), string::FromUtf8Error> { - debug_assert!(!fragment.is_empty()); - self.in_progress.extend(fragment); +/// Run the given command and return its stdout. +pub fn run(mut command: Command, command_name: &str) -> Result<(), Error> { + info!("Running {:?}", command); - if let Some((last_newline, _)) = self - .in_progress - .iter() - .cloned() - .enumerate() - .rev() - .find(|(_, ch)| *ch == b'\n') - { - let next_in_progress: Vec = self.in_progress[last_newline + 1..].to_vec(); - let mut these_lines = mem::replace(&mut self.in_progress, next_in_progress); - these_lines.truncate(last_newline + 1); - let these_lines = String::from_utf8(these_lines)?; - for line in these_lines.lines() { - (self.on_each_line)(line); - } - self.result.push_str(&these_lines); - } + let status = command.status()?; + if status.success() { Ok(()) - } - - /// Finish accumulation, run the `on_each_line` callback on the final line - /// (if any), and return the accumulated output. - fn finish(mut self) -> Result { - if !self.in_progress.is_empty() { - let last_line = String::from_utf8(self.in_progress)?; - (self.on_each_line)(&last_line); - self.result.push_str(&last_line); - } - Ok(self.result) + } else { + bail!( + "failed to execute `{}`: exited with {}", + command_name, + status + ) } } /// Run the given command and return its stdout. -pub fn run(mut command: Command, command_name: &str) -> Result { +pub fn run_capture_stdout(mut command: Command, command_name: &str) -> Result { info!("Running {:?}", command); - let mut child = command - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn()?; - - let stdout = child.stdout.take().unwrap(); - let stderr = child.stderr.take().unwrap(); - - let (send, recv) = mpsc::channel(); - let stdout_send = send.clone(); - let stderr_send = send; - - // Because pipes have a fixed-size buffer, we need to keep reading stdout - // and stderr on a separate thread to avoid potential dead locks with - // waiting on the child process. - - let stdout_handle = - thread::spawn(move || read_and_send(stdout, &stdout_send, OutputFragment::Stdout)); - let stderr_handle = - thread::spawn(move || read_and_send(stderr, &stderr_send, OutputFragment::Stderr)); - - let mut stdout = OutputAccumulator::new(|line| { - info!("{} (stdout): {}", command_name, line); - PBAR.message(line) - }); - let mut stderr = OutputAccumulator::new(|line| { - info!("{} (stderr): {}", command_name, line); - PBAR.message(line) - }); - - for output in recv { - match output { - OutputFragment::Stdout(line) => stdout.push(line)?, - OutputFragment::Stderr(line) => stderr.push(line)?, - }; - } - - let stdout = stdout.finish()?; - let stderr = stderr.finish()?; - - // Join the threads reading the child's output to make sure the finish OK. - stdout_handle.join().unwrap()?; - stderr_handle.join().unwrap()?; + let output = command + .stderr(Stdio::inherit()) + .stdin(Stdio::inherit()) + .output()?; - let exit = child.wait()?; - if exit.success() { - Ok(stdout) + if output.status.success() { + Ok(String::from_utf8_lossy(&output.stdout).into_owned()) } else { - drop((stdout, stderr)); - bail!("failed to execute `{}`: exited with {}", command_name, exit) + bail!( + "failed to execute `{}`: exited with {}", + command_name, + output.status + ) } } diff --git a/src/command/build.rs b/src/command/build.rs index e7feb9b..afa755d 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -7,12 +7,10 @@ use cache; use command::utils::{create_pkg_dir, set_crate_path}; use emoji; use failure::Error; -use indicatif::HumanDuration; use license; use lockfile::Lockfile; use log::info; use manifest; -use progressbar::Step; use readme; use std::path::PathBuf; use std::str::FromStr; @@ -184,7 +182,7 @@ impl Default for BuildOptions { } } -type BuildStep = fn(&mut Build, &Step) -> Result<(), Error>; +type BuildStep = fn(&mut Build) -> Result<(), Error>; impl Build { /// Construct a build command from the given options. @@ -227,25 +225,22 @@ impl Build { pub fn run(&mut self) -> Result<(), Error> { let process_steps = Build::get_process_steps(self.mode); - let mut step_counter = Step::new(process_steps.len()); - let started = Instant::now(); for (_, process_step) in process_steps { - process_step(self, &step_counter)?; - step_counter.inc(); + process_step(self)?; } - let duration = HumanDuration(started.elapsed()); + let duration = crate::command::utils::elapsed(started.elapsed()); info!("Done in {}.", &duration); info!( "Your wasm pkg is ready to publish at {}.", self.out_dir.display() ); - PBAR.message(&format!("{} Done in {}", emoji::SPARKLE, &duration)); + PBAR.info(&format!("{} Done in {}", emoji::SPARKLE, &duration)); - PBAR.message(&format!( + PBAR.info(&format!( "{} Your wasm pkg is ready to publish at {}.", emoji::PACKAGE, self.out_dir.display() @@ -298,31 +293,31 @@ impl Build { } } - fn step_check_rustc_version(&mut self, step: &Step) -> Result<(), Error> { + fn step_check_rustc_version(&mut self) -> Result<(), Error> { info!("Checking rustc version..."); - let version = build::check_rustc_version(step)?; + let version = build::check_rustc_version()?; let msg = format!("rustc version is {}.", version); info!("{}", &msg); Ok(()) } - fn step_check_crate_config(&mut self, step: &Step) -> Result<(), Error> { + fn step_check_crate_config(&mut self) -> Result<(), Error> { info!("Checking crate configuration..."); - self.crate_data.check_crate_config(step)?; + self.crate_data.check_crate_config()?; info!("Crate is correctly configured."); Ok(()) } - fn step_add_wasm_target(&mut self, step: &Step) -> Result<(), Error> { + fn step_add_wasm_target(&mut self) -> Result<(), Error> { info!("Adding wasm-target..."); - build::rustup_add_wasm_target(step)?; + build::rustup_add_wasm_target()?; info!("Adding wasm-target was successful."); Ok(()) } - fn step_build_wasm(&mut self, step: &Step) -> Result<(), Error> { + fn step_build_wasm(&mut self) -> Result<(), Error> { info!("Building wasm..."); - build::cargo_build_wasm(&self.crate_path, self.profile, step, &self.extra_options)?; + build::cargo_build_wasm(&self.crate_path, self.profile, &self.extra_options)?; info!( "wasm built at {:#?}.", @@ -335,21 +330,19 @@ impl Build { Ok(()) } - fn step_create_dir(&mut self, step: &Step) -> Result<(), Error> { + fn step_create_dir(&mut self) -> Result<(), Error> { info!("Creating a pkg directory..."); - create_pkg_dir(&self.out_dir, step)?; + create_pkg_dir(&self.out_dir)?; info!("Created a pkg directory at {:#?}.", &self.crate_path); Ok(()) } - fn step_create_json(&mut self, step: &Step) -> Result<(), Error> { - info!("Writing a package.json..."); + fn step_create_json(&mut self) -> Result<(), Error> { self.crate_data.write_package_json( &self.out_dir, &self.scope, self.disable_dts, &self.target, - step, )?; info!( "Wrote a package.json at {:#?}.", @@ -358,21 +351,21 @@ impl Build { Ok(()) } - fn step_copy_readme(&mut self, step: &Step) -> Result<(), Error> { + fn step_copy_readme(&mut self) -> Result<(), Error> { info!("Copying readme from crate..."); - readme::copy_from_crate(&self.crate_path, &self.out_dir, step)?; + readme::copy_from_crate(&self.crate_path, &self.out_dir)?; info!("Copied readme from crate to {:#?}.", &self.out_dir); Ok(()) } - fn step_copy_license(&mut self, step: &Step) -> Result<(), failure::Error> { + fn step_copy_license(&mut self) -> Result<(), failure::Error> { info!("Copying license from crate..."); - license::copy_from_crate(&self.crate_data, &self.crate_path, &self.out_dir, step)?; + license::copy_from_crate(&self.crate_data, &self.crate_path, &self.out_dir)?; info!("Copied license from crate to {:#?}.", &self.out_dir); Ok(()) } - fn step_install_wasm_bindgen(&mut self, step: &Step) -> Result<(), failure::Error> { + fn step_install_wasm_bindgen(&mut self) -> Result<(), failure::Error> { info!("Identifying wasm-bindgen dependency..."); let lockfile = Lockfile::new(&self.crate_data)?; let bindgen_version = lockfile.require_wasm_bindgen()?; @@ -383,13 +376,13 @@ impl Build { BuildMode::Noinstall => false, }; let bindgen = - bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted, step)?; + bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted)?; self.bindgen = Some(bindgen); info!("Installing wasm-bindgen-cli was successful."); Ok(()) } - fn step_run_wasm_bindgen(&mut self, step: &Step) -> Result<(), Error> { + fn step_run_wasm_bindgen(&mut self) -> Result<(), Error> { info!("Building the wasm bindings..."); bindgen::wasm_bindgen_build( &self.crate_data, @@ -398,7 +391,6 @@ impl Build { self.disable_dts, &self.target, self.profile, - step, )?; info!("wasm bindings were built at {:#?}.", &self.out_dir); Ok(()) diff --git a/src/command/login.rs b/src/command/login.rs index 4c0aa94..6df51f5 100644 --- a/src/command/login.rs +++ b/src/command/login.rs @@ -20,6 +20,6 @@ pub fn login( npm::npm_login(®istry, &scope, always_auth, &auth_type)?; info!("Logged you in!"); - PBAR.message(&"👋 logged you in!".to_string()); + PBAR.info(&"👋 logged you in!".to_string()); Ok(()) } diff --git a/src/command/pack.rs b/src/command/pack.rs index 5ede602..a3a779e 100644 --- a/src/command/pack.rs +++ b/src/command/pack.rs @@ -22,6 +22,6 @@ pub fn pack(path: Option) -> result::Result<(), Error> { npm::npm_pack(&pkg_directory.to_string_lossy())?; info!("Your package is located at {:#?}", crate_path.join("pkg")); - PBAR.message("🎒 packed up your package!"); + PBAR.info("🎒 packed up your package!"); Ok(()) } diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index 019a83b..98b7001 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -77,6 +77,6 @@ pub fn publish( npm::npm_publish(&pkg_directory.to_string_lossy(), access)?; info!("Published your package!"); - PBAR.message("💥 published your package!"); + PBAR.info("💥 published your package!"); Ok(()) } diff --git a/src/command/test.rs b/src/command/test.rs index 43797e7..cbbe529 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -7,17 +7,13 @@ use build; use cache; use command::utils::set_crate_path; use console::style; -use emoji; use failure::Error; -use indicatif::HumanDuration; use lockfile::Lockfile; use log::info; use manifest; -use progressbar::Step; use std::path::PathBuf; use std::time::Instant; use test::{self, webdriver}; -use PBAR; #[derive(Debug, Default, StructOpt)] /// Everything required to configure the `wasm-pack test` command. @@ -103,7 +99,7 @@ pub struct Test { extra_options: Vec, } -type TestStep = fn(&mut Test, &Step) -> Result<(), Error>; +type TestStep = fn(&mut Test) -> Result<(), Error>; impl Test { /// Construct a test command from the given options. @@ -165,14 +161,12 @@ impl Test { /// Execute this test command. pub fn run(mut self) -> Result<(), Error> { let process_steps = self.get_process_steps(); - let mut step_counter = Step::new(process_steps.len()); let started = Instant::now(); for (_, process_step) in process_steps { - process_step(&mut self, &step_counter)?; - step_counter.inc(); + process_step(&mut self)?; } - let duration = HumanDuration(started.elapsed()); + let duration = crate::command::utils::elapsed(started.elapsed()); info!("Done in {}.", &duration); Ok(()) @@ -233,33 +227,30 @@ impl Test { } } - fn step_check_rustc_version(&mut self, step: &Step) -> Result<(), Error> { + fn step_check_rustc_version(&mut self) -> Result<(), Error> { info!("Checking rustc version..."); - let _ = build::check_rustc_version(step)?; + let _ = build::check_rustc_version()?; info!("Rustc version is correct."); Ok(()) } - fn step_add_wasm_target(&mut self, step: &Step) -> Result<(), Error> { + fn step_add_wasm_target(&mut self) -> Result<(), Error> { info!("Adding wasm-target..."); - build::rustup_add_wasm_target(step)?; + build::rustup_add_wasm_target()?; info!("Adding wasm-target was successful."); Ok(()) } - fn step_build_tests(&mut self, step: &Step) -> Result<(), Error> { + fn step_build_tests(&mut self) -> Result<(), Error> { info!("Compiling tests to wasm..."); - let msg = format!("{}Compiling tests to Wasm...", emoji::CYCLONE); - PBAR.step(step, &msg); - build::cargo_build_wasm_tests(&self.crate_path, !self.release)?; info!("Finished compiling tests to wasm."); Ok(()) } - fn step_install_wasm_bindgen(&mut self, step: &Step) -> Result<(), Error> { + fn step_install_wasm_bindgen(&mut self) -> Result<(), Error> { info!("Identifying wasm-bindgen dependency..."); let lockfile = Lockfile::new(&self.crate_data)?; let bindgen_version = lockfile.require_wasm_bindgen()?; @@ -293,8 +284,7 @@ impl Test { } }; - let dl = - bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted, step)?; + let dl = bindgen::install_wasm_bindgen(&self.cache, &bindgen_version, install_permitted)?; self.test_runner_path = Some(dl.binary("wasm-bindgen-test-runner")?); @@ -302,10 +292,9 @@ impl Test { Ok(()) } - fn step_test_node(&mut self, step: &Step) -> Result<(), Error> { + fn step_test_node(&mut self) -> Result<(), Error> { assert!(self.node); info!("Running tests in node..."); - PBAR.step(step, "Running tests in node..."); test::cargo_test_wasm( &self.crate_path, self.release, @@ -319,8 +308,7 @@ impl Test { Ok(()) } - fn step_get_chromedriver(&mut self, step: &Step) -> Result<(), Error> { - PBAR.step(step, "Getting chromedriver..."); + fn step_get_chromedriver(&mut self) -> Result<(), Error> { assert!(self.chrome && self.chromedriver.is_none()); self.chromedriver = Some(webdriver::get_or_install_chromedriver( @@ -330,9 +318,7 @@ impl Test { Ok(()) } - fn step_test_chrome(&mut self, step: &Step) -> Result<(), Error> { - PBAR.step(step, "Running tests in Chrome..."); - + fn step_test_chrome(&mut self) -> Result<(), Error> { let chromedriver = self.chromedriver.as_ref().unwrap().display().to_string(); let chromedriver = chromedriver.as_str(); info!( @@ -361,8 +347,7 @@ impl Test { Ok(()) } - fn step_get_geckodriver(&mut self, step: &Step) -> Result<(), Error> { - PBAR.step(step, "Getting geckodriver..."); + fn step_get_geckodriver(&mut self) -> Result<(), Error> { assert!(self.firefox && self.geckodriver.is_none()); self.geckodriver = Some(webdriver::get_or_install_geckodriver( @@ -372,9 +357,7 @@ impl Test { Ok(()) } - fn step_test_firefox(&mut self, step: &Step) -> Result<(), Error> { - PBAR.step(step, "Running tests in Firefox..."); - + fn step_test_firefox(&mut self) -> Result<(), Error> { let geckodriver = self.geckodriver.as_ref().unwrap().display().to_string(); let geckodriver = geckodriver.as_str(); info!( @@ -403,17 +386,14 @@ impl Test { Ok(()) } - fn step_get_safaridriver(&mut self, step: &Step) -> Result<(), Error> { - PBAR.step(step, "Getting safaridriver..."); + fn step_get_safaridriver(&mut self) -> Result<(), Error> { assert!(self.safari && self.safaridriver.is_none()); self.safaridriver = Some(webdriver::get_safaridriver()?); Ok(()) } - fn step_test_safari(&mut self, step: &Step) -> Result<(), Error> { - PBAR.step(step, "Running tests in Safari..."); - + fn step_test_safari(&mut self) -> Result<(), Error> { let safaridriver = self.safaridriver.as_ref().unwrap().display().to_string(); let safaridriver = safaridriver.as_str(); info!( diff --git a/src/command/utils.rs b/src/command/utils.rs index 5a29a74..337bdc5 100644 --- a/src/command/utils.rs +++ b/src/command/utils.rs @@ -1,12 +1,10 @@ //! Utility functions for commands. -use emoji; use failure; -use progressbar::Step; use std::fs; use std::path::{Path, PathBuf}; +use std::time::Duration; use walkdir::WalkDir; -use PBAR; /// If an explicit path is given, then use it, otherwise assume the current /// directory is the crate path. @@ -15,9 +13,7 @@ pub fn set_crate_path(path: Option) -> Result } /// Construct our `pkg` directory in the crate. -pub fn create_pkg_dir(out_dir: &Path, step: &Step) -> Result<(), failure::Error> { - let msg = format!("{}Creating a pkg directory...", emoji::FOLDER); - PBAR.step(step, &msg); +pub fn create_pkg_dir(out_dir: &Path) -> Result<(), failure::Error> { fs::create_dir_all(&out_dir)?; fs::write(out_dir.join(".gitignore"), "*")?; Ok(()) @@ -39,3 +35,14 @@ pub fn find_pkg_directory(path: &Path) -> Option { fn is_pkg_directory(path: &Path) -> bool { path.exists() && path.is_dir() && path.ends_with("pkg") } + +/// Render a `Duration` to a form suitable for display on a console +pub fn elapsed(duration: Duration) -> String { + let secs = duration.as_secs(); + + if secs >= 60 { + format!("{}m {:02}s", secs / 60, secs % 60) + } else { + format!("{}.{:02}s", secs, duration.subsec_nanos() / 10_000_000) + } +} diff --git a/src/lib.rs b/src/lib.rs index 97b136f..e8b7ceb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,12 +8,9 @@ extern crate strsim; #[macro_use] extern crate failure; extern crate glob; -extern crate indicatif; -extern crate which; -#[macro_use] -extern crate lazy_static; extern crate parking_lot; extern crate serde; +extern crate which; #[macro_use] extern crate serde_derive; extern crate serde_ignored; @@ -43,10 +40,8 @@ pub mod test; use progressbar::ProgressOutput; -lazy_static! { - /// The global progress bar and user-facing message output. - pub static ref PBAR: ProgressOutput = { ProgressOutput::new() }; -} +/// The global progress bar and user-facing message output. +pub static PBAR: ProgressOutput = ProgressOutput; /// 📦 ✨ pack and publish your wasm! #[derive(Debug, StructOpt)] diff --git a/src/license.rs b/src/license.rs index ee5f20b..4297344 100644 --- a/src/license.rs +++ b/src/license.rs @@ -4,10 +4,8 @@ use failure; use std::fs; use std::path::Path; -use emoji; use glob::glob; use manifest::CrateData; -use progressbar::Step; use PBAR; fn glob_license_files(path: &Path) -> Result, failure::Error> { @@ -45,7 +43,6 @@ pub fn copy_from_crate( crate_data: &CrateData, path: &Path, out_dir: &Path, - step: &Step, ) -> Result<(), failure::Error> { assert!( fs::metadata(path).ok().map_or(false, |m| m.is_dir()), @@ -59,8 +56,6 @@ pub fn copy_from_crate( match (crate_data.crate_license(), crate_data.crate_license_file()) { (Some(_), _) => { - let msg = format!("{}Copying over your LICENSE...", emoji::DANCERS); - PBAR.step(step, &msg); let license_files = glob_license_files(path); match license_files { @@ -87,9 +82,7 @@ pub fn copy_from_crate( PBAR.info("origin crate has no LICENSE"); } } - (None, None) => { - PBAR.step(step, "No LICENSE found in Cargo.toml, skipping..."); - } + (None, None) => {} }; Ok(()) diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index ea376a4..617af86 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -12,9 +12,7 @@ use self::npm::{ }; use cargo_metadata::Metadata; use command::build::{BuildProfile, Target}; -use emoji; use failure::{Error, ResultExt}; -use progressbar::Step; use serde::{self, Deserialize}; use serde_json; use std::collections::BTreeSet; @@ -312,9 +310,7 @@ impl CrateData { } /// Check that the crate the given path is properly configured. - pub fn check_crate_config(&self, step: &Step) -> Result<(), Error> { - let msg = format!("{}Checking crate configuration...", emoji::WRENCH); - PBAR.step(&step, &msg); + pub fn check_crate_config(&self) -> Result<(), Error> { self.check_crate_type()?; Ok(()) } @@ -378,11 +374,7 @@ impl CrateData { scope: &Option, disable_dts: bool, target: &Target, - step: &Step, ) -> Result<(), Error> { - let msg = format!("{}Writing a package.json...", emoji::MEMO); - - PBAR.step(step, &msg); let pkg_file_path = out_dir.join("package.json"); let npm_data = match target { Target::Nodejs => self.to_commonjs(scope, disable_dts, out_dir), diff --git a/src/progressbar.rs b/src/progressbar.rs index 228e9c6..50eea02 100644 --- a/src/progressbar.rs +++ b/src/progressbar.rs @@ -2,72 +2,20 @@ use console::style; use emoji; -use indicatif::{ProgressBar, ProgressStyle}; -use parking_lot::RwLock; -use std::fmt; /// Synchronized progress bar and status message printing. -pub struct ProgressOutput { - spinner: RwLock, - messages: RwLock, -} +pub struct ProgressOutput; impl ProgressOutput { - /// Construct a new `ProgressOutput`. - pub fn new() -> Self { - Self { - spinner: RwLock::new(ProgressBar::new_spinner()), - messages: RwLock::new(String::from("")), - } - } - - /// Inform the user that the given `step` is being executed, with details in - /// `message`. - pub fn step(&self, step: &Step, message: &str) { - let msg = format!("{} {}", style(step).bold().dim(), message); - self.message(&msg) - } - - fn finish(&self) { - let spinner = self.spinner.read(); - spinner.finish(); - - let mut message = self.messages.write(); - print!("{}", *message); - message.clear(); - } - /// Print the given message. - pub fn message(&self, message: &str) { - self.finish(); - - let mut spinner = self.spinner.write(); - *spinner = Self::progressbar(message); - - if !atty::is(atty::Stream::Stderr) { - // `indicatif` won't print any output if `stderr` is not a tty, so - // to ensure that our output is still emitted, we print it manually - // here. - eprintln!("{}", message) - } - } - - fn add_message(&self, msg: &str) { - let mut message = self.messages.write(); - message.push_str(" "); - message.push_str(msg); - message.push('\n'); + fn message(&self, message: &str) { + eprintln!("{}", message); } /// Add an informational message. pub fn info(&self, message: &str) { - let info = format!( - "{} {}: {}", - emoji::INFO, - style("[INFO]").bold().dim(), - message - ); - self.add_message(&info); + let info = format!("{}: {}", style("[INFO]").bold().dim(), message,); + self.message(&info); } /// Add a warning message. @@ -78,7 +26,7 @@ impl ProgressOutput { style("[WARN]").bold().dim(), message ); - self.add_message(&warn); + self.message(&warn); } /// Add an error message. @@ -89,62 +37,12 @@ impl ProgressOutput { style("[ERR]").bold().dim(), message ); - self.add_message(&err); - } - - fn progressbar(msg: &str) -> ProgressBar { - let pb = ProgressBar::new_spinner(); - pb.enable_steady_tick(200); - pb.set_style( - ProgressStyle::default_spinner() - .tick_chars("/|\\- ") - .template("{spinner:.dim.bold} {wide_msg}"), - ); - pb.set_message(&msg); - pb - } - - /// After having built up a series of messages, print all of them out. - pub fn done(&self) { - self.finish(); - } -} - -/// For processes that can be broken down into N fractional steps, with messages -/// added for each step along the way like -/// -/// > [2/5] Doing the second step out of five. -pub struct Step { - current: usize, - total: usize, -} - -impl Step { - /// Construct a `Step` where there are `total` number of steps. - pub fn new(total: usize) -> Step { - Step { current: 1, total } - } - - /// Increment the current step. - pub fn inc(&mut self) { - self.current += 1; - } -} - -impl fmt::Display for Step { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "[{}/{}]", self.current, self.total) - } -} - -impl Drop for ProgressOutput { - fn drop(&mut self) { - self.done(); + self.message(&err); } } impl Default for ProgressOutput { fn default() -> Self { - Self::new() + ProgressOutput } } diff --git a/src/readme.rs b/src/readme.rs index 2eec060..6e1c57f 100644 --- a/src/readme.rs +++ b/src/readme.rs @@ -1,15 +1,13 @@ //! Generating `README` files for the packaged wasm. -use failure; +use failure::{self, ResultExt}; use std::fs; use std::path::Path; -use emoji; -use progressbar::Step; use PBAR; /// Copy the crate's README into the `pkg` directory. -pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), failure::Error> { +pub fn copy_from_crate(path: &Path, out_dir: &Path) -> Result<(), failure::Error> { assert!( fs::metadata(path).ok().map_or(false, |m| m.is_dir()), "crate directory should exist" @@ -19,11 +17,11 @@ pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), f "crate's pkg directory should exist" ); - let msg = format!("{}Copying over your README...", emoji::DANCERS); - PBAR.step(step, &msg); let crate_readme_path = path.join("README.md"); let new_readme_path = out_dir.join("README.md"); - if fs::copy(&crate_readme_path, &new_readme_path).is_err() { + if crate_readme_path.exists() { + fs::copy(&crate_readme_path, &new_readme_path).context("failed to copy README")?; + } else { PBAR.warn("origin crate has no README"); } Ok(()) diff --git a/src/test/webdriver.rs b/src/test/webdriver.rs index 1dfe1a1..a5201ec 100644 --- a/src/test/webdriver.rs +++ b/src/test/webdriver.rs @@ -5,6 +5,25 @@ use command::build::BuildMode; use failure; use std::path::PathBuf; use target; +use PBAR; + +fn get_and_notify( + cache: &Cache, + installation_allowed: bool, + name: &str, + url: &str, +) -> Result, failure::Error> { + if let Some(dl) = cache.download(false, name, &[name], &url)? { + return Ok(Some(dl.binary(name)?)); + } + if installation_allowed { + PBAR.info(&format!("Getting {}...", name)); + } + match cache.download(installation_allowed, name, &[name], &url)? { + Some(dl) => Ok(Some(dl.binary(name)?)), + None => Ok(None), + } +} /// Get the path to an existing `chromedriver`, or install it if no existing /// binary is found. @@ -41,13 +60,8 @@ pub fn install_chromedriver( "https://chromedriver.storage.googleapis.com/2.46/chromedriver_{}.zip", target ); - match cache.download( - installation_allowed, - "chromedriver", - &["chromedriver"], - &url, - )? { - Some(dl) => Ok(dl.binary("chromedriver")?), + match get_and_notify(cache, installation_allowed, "chromedriver", &url)? { + Some(path) => Ok(path), None => bail!( "No cached `chromedriver` binary found, and could not find a global \ `chromedriver` on the `$PATH`. Not installing `chromedriver` because of noinstall \ @@ -96,8 +110,8 @@ pub fn install_geckodriver( target, ext, ); - match cache.download(installation_allowed, "geckodriver", &["geckodriver"], &url)? { - Some(dl) => Ok(dl.binary("geckodriver")?), + match get_and_notify(cache, installation_allowed, "geckodriver", &url)? { + Some(path) => Ok(path), None => bail!( "No cached `geckodriver` binary found, and could not find a global `geckodriver` \ on the `$PATH`. Not installing `geckodriver` because of noinstall mode." diff --git a/tests/all/license.rs b/tests/all/license.rs index 75dcd5c..f56f650 100644 --- a/tests/all/license.rs +++ b/tests/all/license.rs @@ -14,8 +14,7 @@ fn it_copies_a_license_default_path() { fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path); - let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok()); let crate_license_path = fixture.path.join("LICENSE"); let pkg_license_path = out_dir.join("LICENSE"); @@ -40,8 +39,7 @@ fn it_copies_a_license_provided_path() { fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path); - let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok()); let crate_license_path = fixture.path.join("LICENSE"); let pkg_license_path = out_dir.join("LICENSE"); println!( @@ -64,8 +62,7 @@ fn it_copies_all_licenses_default_path() { fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path); - let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok()); let crate_license_path = fixture.path.join("LICENSE-WTFPL"); let pkg_license_path = out_dir.join("LICENSE-WTFPL"); @@ -100,8 +97,7 @@ fn it_copies_all_licenses_provided_path() { fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path); - let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok()); let crate_license_path = fixture.path.join("LICENSE-WTFPL"); let pkg_license_path = out_dir.join("LICENSE-WTFPL"); @@ -137,8 +133,7 @@ fn it_copies_a_non_standard_license_provided_path() { fs::create_dir(&out_dir).expect("should create pkg directory OK"); let crate_data = CrateData::new(&fixture.path); - let step = wasm_pack::progressbar::Step::new(1); - assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir, &step).is_ok()); + assert!(license::copy_from_crate(&crate_data.unwrap(), &fixture.path, &out_dir).is_ok()); let crate_license_path = fixture.path.join(license_file); let pkg_license_path = out_dir.join(license_file); diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 6c274d2..a68cf27 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -27,8 +27,7 @@ fn it_checks_has_cdylib_default_path() { // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - assert!(crate_data.check_crate_config(&step).is_err()); + assert!(crate_data.check_crate_config().is_err()); } #[test] @@ -37,16 +36,14 @@ fn it_checks_has_cdylib_provided_path() { // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - crate_data.check_crate_config(&step).unwrap(); + crate_data.check_crate_config().unwrap(); } #[test] fn it_checks_has_cdylib_wrong_crate_type() { let fixture = fixture::bad_cargo_toml(); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - assert!(crate_data.check_crate_config(&step).is_err()); + assert!(crate_data.check_crate_config().is_err()); } #[test] @@ -55,8 +52,7 @@ fn it_recognizes_a_map_during_depcheck() { // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - crate_data.check_crate_config(&step).unwrap(); + crate_data.check_crate_config().unwrap(); } #[test] @@ -64,10 +60,9 @@ fn it_creates_a_package_json_default_path() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); assert!(crate_data - .write_package_json(&out_dir, &None, false, &Target::Bundler, &step) + .write_package_json(&out_dir, &None, false, &Target::Bundler) .is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -100,10 +95,9 @@ fn it_creates_a_package_json_provided_path() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); assert!(crate_data - .write_package_json(&out_dir, &None, false, &Target::Bundler, &step) + .write_package_json(&out_dir, &None, false, &Target::Bundler) .is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -129,16 +123,9 @@ fn it_creates_a_package_json_provided_path_with_scope() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); assert!(crate_data - .write_package_json( - &out_dir, - &Some("test".to_string()), - false, - &Target::Bundler, - &step - ) + .write_package_json(&out_dir, &Some("test".to_string()), false, &Target::Bundler,) .is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -164,10 +151,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); assert!(crate_data - .write_package_json(&out_dir, &None, false, &Target::Nodejs, &step) + .write_package_json(&out_dir, &None, false, &Target::Nodejs) .is_ok()); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -200,10 +186,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); assert!(crate_data - .write_package_json(&out_dir, &None, false, &Target::NoModules, &step) + .write_package_json(&out_dir, &None, false, &Target::NoModules) .is_ok()); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -235,10 +220,9 @@ fn it_creates_a_pkg_json_in_out_dir() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("./custom/out"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); assert!(crate_data - .write_package_json(&out_dir, &None, false, &Target::Bundler, &step) + .write_package_json(&out_dir, &None, false, &Target::Bundler) .is_ok()); let package_json_path = &fixture.path.join(&out_dir).join("package.json"); @@ -251,10 +235,9 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); assert!(crate_data - .write_package_json(&out_dir, &None, true, &Target::Bundler, &step) + .write_package_json(&out_dir, &None, true, &Target::Bundler) .is_ok()); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -280,8 +263,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { fn it_errors_when_wasm_bindgen_is_not_declared() { let fixture = fixture::bad_cargo_toml(); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - assert!(crate_data.check_crate_config(&step).is_err()); + assert!(crate_data.check_crate_config().is_err()); } #[test] @@ -314,10 +296,9 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(2); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); crate_data - .write_package_json(&out_dir, &None, true, &Target::Bundler, &step) + .write_package_json(&out_dir, &None, true, &Target::Bundler) .unwrap(); let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -331,10 +312,9 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() { let out_dir = fixture.path.join("pkg"); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(2); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); crate_data - .write_package_json(&out_dir, &None, true, &Target::Bundler, &step) + .write_package_json(&out_dir, &None, true, &Target::Bundler) .unwrap(); let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -347,8 +327,7 @@ fn it_does_not_error_when_wasm_bindgen_is_declared() { // Ensure that there is a `Cargo.lock`. fixture.cargo_check(); let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(1); - crate_data.check_crate_config(&step).unwrap(); + crate_data.check_crate_config().unwrap(); } #[test] @@ -420,7 +399,7 @@ fn parse_crate_data_returns_unused_keys_in_cargo_toml() { .arg("build") .assert() .success() - .stdout(predicates::str::contains( + .stderr(predicates::str::contains( "[WARN]: \"package.metadata.wasm-pack.profile.production\" is an unknown key and will \ be ignored. Please check your Cargo.toml.", )); @@ -433,11 +412,10 @@ fn it_lists_license_files_in_files_field_of_package_json() { let crate_data = manifest::CrateData::new(&fixture.path).unwrap(); - let step = wasm_pack::progressbar::Step::new(3); - wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); - license::copy_from_crate(&crate_data, &fixture.path, &out_dir, &step).unwrap(); + wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap(); + license::copy_from_crate(&crate_data, &fixture.path, &out_dir).unwrap(); crate_data - .write_package_json(&out_dir, &None, false, &Target::Bundler, &step) + .write_package_json(&out_dir, &None, false, &Target::Bundler) .unwrap(); let package_json_path = &fixture.path.join("pkg").join("package.json"); diff --git a/tests/all/readme.rs b/tests/all/readme.rs index af2fbcd..8576f33 100644 --- a/tests/all/readme.rs +++ b/tests/all/readme.rs @@ -12,8 +12,7 @@ fn it_copies_a_readme_default_path() { let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); - let step = wasm_pack::progressbar::Step::new(1); - assert!(readme::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + assert!(readme::copy_from_crate(&fixture.path, &out_dir).is_ok()); let crate_readme_path = fixture.path.join("README.md"); let pkg_readme_path = out_dir.join("README.md"); @@ -37,8 +36,7 @@ fn it_copies_a_readme_provided_path() { let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); - let step = wasm_pack::progressbar::Step::new(1); - assert!(readme::copy_from_crate(&fixture.path, &out_dir, &step).is_ok()); + assert!(readme::copy_from_crate(&fixture.path, &out_dir).is_ok()); let crate_readme_path = fixture.path.join("README.md"); let pkg_readme_path = out_dir.join("README.md"); println!( diff --git a/tests/all/test.rs b/tests/all/test.rs index 04f1210..e0e204a 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -331,9 +331,9 @@ fn test_output_is_printed_once_in_both_stdout_and_failures() { .arg("--node") .assert() .failure() - .stderr(predicate::function(|err: &str| { - // but the err string will capture both stdout and failures, + .stdout(predicate::function(|out: &str| { + // but the out string will capture both stdout and failures, // so we will get a log that count twice - err.matches("YABBA DABBA DOO").count() == log_cnt * 2 + out.matches("YABBA DABBA DOO").count() == log_cnt * 2 })); }