From a4b29a929383d81f89e44b867ded9df36946d598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Mon, 15 Oct 2018 21:14:55 +0200 Subject: [PATCH 01/17] refactor: Move binary installation to it's own crate --- Cargo.lock | 14 ++ Cargo.toml | 4 + binary-install/Cargo.toml | 14 ++ binary-install/src/error.rs | 44 +++++++ binary-install/src/fetch.rs | 47 +++++++ binary-install/src/lib.rs | 143 ++++++++++++++++++++ binary-install/src/path.rs | 76 +++++++++++ binary-install/src/target.rs | 8 ++ src/binaries.rs | 247 ----------------------------------- src/bindgen.rs | 7 +- src/lib.rs | 2 +- src/test/webdriver.rs | 9 +- tests/all/main.rs | 1 + tests/all/test.rs | 4 +- tests/all/utils/fixture.rs | 27 ++-- 15 files changed, 378 insertions(+), 269 deletions(-) create mode 100644 binary-install/Cargo.toml create mode 100644 binary-install/src/error.rs create mode 100644 binary-install/src/fetch.rs create mode 100644 binary-install/src/lib.rs create mode 100644 binary-install/src/path.rs create mode 100644 binary-install/src/target.rs delete mode 100644 src/binaries.rs diff --git a/Cargo.lock b/Cargo.lock index 2494756..704e56d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,6 +50,19 @@ dependencies = [ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "binary-install" +version = "0.1.0" +dependencies = [ + "curl 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tar 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", + "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "1.0.4" @@ -970,6 +983,7 @@ name = "wasm-pack" version = "0.5.1" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "binary-install 0.1.0", "cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 56392cf..b739d3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,9 @@ readme = "README.md" categories = ["wasm"] documentation = "https://rustwasm.github.io/wasm-pack/" +[workspace] +members = [".", "binary-install"] + [dependencies] atty = "0.2.11" cargo_metadata = "0.6.0" @@ -32,6 +35,7 @@ tar = "0.4.16" toml = "0.4" which = "2.0.0" zip = "0.4.2" +binary-install = { version = "0.1.0", path = "./binary-install" } [dev-dependencies] tempfile = "3" diff --git a/binary-install/Cargo.toml b/binary-install/Cargo.toml new file mode 100644 index 0000000..2912fcb --- /dev/null +++ b/binary-install/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "binary-install" +version = "0.1.0" +authors = ["Jesper HÃ¥kansson "] + +[dependencies] +curl = "0.4.13" +failure = "0.1.2" +flate2 = "1.0.2" +slog = "2.3" +tar = "0.4.16" +which = "2.0.0" +zip = "0.4.2" + diff --git a/binary-install/src/error.rs b/binary-install/src/error.rs new file mode 100644 index 0000000..11fa2f0 --- /dev/null +++ b/binary-install/src/error.rs @@ -0,0 +1,44 @@ +//! Code related to error handling for binary-install + +/// Errors that can potentially occur in `binary-install`. +#[derive(Debug, Fail)] +pub enum Error { + #[fail(display = "{}", message)] + /// An error related to an archive that we downloaded. + Archive { + /// Error message. + message: String, + }, + + #[fail(display = "{}", message)] + /// Error related to some HTTP request. + Http { + /// Error message. + message: String, + }, +} + +impl Error { + /// Construct an archive error. + pub fn archive(message: &str) -> Self { + Error::Archive { + message: message.to_string(), + } + } + + /// Construct an http error. + pub fn http(message: &str) -> Self { + Error::Http { + message: message.to_string(), + } + } + + /// Get a string description of this error's type. + pub fn error_type(&self) -> String { + match self { + Error::Archive { .. } => "There was an error related to an archive file. Details:\n\n", + Error::Http { .. } => "There wasn an HTTP error. Details:\n\n", + } + .to_string() + } +} diff --git a/binary-install/src/fetch.rs b/binary-install/src/fetch.rs new file mode 100644 index 0000000..31772ee --- /dev/null +++ b/binary-install/src/fetch.rs @@ -0,0 +1,47 @@ +use error::Error; +use failure; + +pub fn curl(url: &str) -> Result, failure::Error> { + let mut data = Vec::new(); + + let mut easy = curl::easy::Easy::new(); + with_url_context(url, easy.follow_location(true))?; + with_url_context(url, easy.url(url))?; + transfer(url, &mut easy, &mut data)?; + + let status_code = with_url_context(url, easy.response_code())?; + if 200 <= status_code && status_code < 300 { + Ok(data) + } else { + Err(Error::http(&format!( + "received a bad HTTP status code ({}) when requesting {}", + status_code, url + )) + .into()) + } +} + +fn with_url_context(url: &str, r: Result) -> Result +where + Result: failure::ResultExt, +{ + use failure::ResultExt; + r.with_context(|_| format!("when requesting {}", url)) +} + +fn transfer( + url: &str, + easy: &mut curl::easy::Easy, + data: &mut Vec, +) -> Result<(), failure::Error> { + let mut transfer = easy.transfer(); + with_url_context( + url, + transfer.write_function(|part| { + data.extend_from_slice(part); + Ok(part.len()) + }), + )?; + with_url_context(url, transfer.perform())?; + Ok(()) +} diff --git a/binary-install/src/lib.rs b/binary-install/src/lib.rs new file mode 100644 index 0000000..3ff5e4b --- /dev/null +++ b/binary-install/src/lib.rs @@ -0,0 +1,143 @@ +//! Utilities for finding and installing binaries that we depend on. + +extern crate curl; +#[macro_use] +extern crate failure; +extern crate flate2; + +#[macro_use] +extern crate slog; +extern crate tar; +extern crate which; +extern crate zip; + +pub mod error; +pub mod path; + +mod fetch; +mod target; + +use error::Error; +use fetch::curl; +use path::{ensure_local_bin_dir, local_bin_dir}; +use std::collections::HashSet; +use std::ffi; +use std::fs; +use std::io; +use std::path::Path; + +/// Download the `.tar.gz` file at the given URL and unpack the given binaries +/// from it into the given crate. +/// +/// Upon success, every `$BIN` in `binaries` will be at `$CRATE/bin/$BIN`. +pub fn install_binaries_from_targz_at_url<'a, I>( + crate_path: &Path, + url: &str, + binaries: I, +) -> Result<(), failure::Error> +where + I: IntoIterator, +{ + let mut binaries: HashSet<_> = binaries.into_iter().map(ffi::OsStr::new).collect(); + + let tarball = curl(&url).map_err(|e| Error::http(&e.to_string()))?; + let mut archive = tar::Archive::new(flate2::read::GzDecoder::new(&tarball[..])); + + ensure_local_bin_dir(crate_path)?; + let bin = local_bin_dir(crate_path); + + for entry in archive.entries()? { + let mut entry = entry?; + + let dest = match entry.path()?.file_stem() { + Some(f) if binaries.contains(f) => { + binaries.remove(f); + bin.join(entry.path()?.file_name().unwrap()) + } + _ => continue, + }; + + entry.unpack(dest)?; + } + + if binaries.is_empty() { + Ok(()) + } else { + Err(Error::archive(&format!( + "the tarball at {} was missing expected executables: {}", + url, + binaries + .into_iter() + .map(|s| s.to_string_lossy()) + .collect::>() + .join(", "), + )) + .into()) + } +} + +/// Install binaries from within the given zip at the given URL. +/// +/// Upon success, the binaries will be at the `$CRATE/bin/$BIN` path. +pub fn install_binaries_from_zip_at_url<'a, I>( + crate_path: &Path, + url: &str, + binaries: I, +) -> Result<(), failure::Error> +where + I: IntoIterator, +{ + let mut binaries: HashSet<_> = binaries.into_iter().map(ffi::OsStr::new).collect(); + + let data = curl(&url).map_err(|e| Error::http(&e.to_string()))?; + let data = io::Cursor::new(data); + let mut zip = zip::ZipArchive::new(data)?; + + ensure_local_bin_dir(crate_path)?; + let bin = local_bin_dir(crate_path); + + for i in 0..zip.len() { + let mut entry = zip.by_index(i).unwrap(); + let entry_path = entry.sanitized_name(); + match entry_path.file_stem() { + Some(f) if binaries.contains(f) => { + binaries.remove(f); + let mut dest = bin_open_options() + .write(true) + .create_new(true) + .open(bin.join(entry_path.file_name().unwrap()))?; + io::copy(&mut entry, &mut dest)?; + } + _ => continue, + }; + } + + if binaries.is_empty() { + Ok(()) + } else { + Err(Error::archive(&format!( + "the zip at {} was missing expected executables: {}", + url, + binaries + .into_iter() + .map(|s| s.to_string_lossy()) + .collect::>() + .join(", "), + )) + .into()) + } +} + +#[cfg(unix)] +fn bin_open_options() -> fs::OpenOptions { + use std::os::unix::fs::OpenOptionsExt; + + let mut opts = fs::OpenOptions::new(); + opts.mode(0o755); + opts +} + +#[cfg(not(unix))] +fn bin_open_options() -> fs::OpenOptions { + fs::OpenOptions::new() +} diff --git a/binary-install/src/path.rs b/binary-install/src/path.rs new file mode 100644 index 0000000..3f58ec2 --- /dev/null +++ b/binary-install/src/path.rs @@ -0,0 +1,76 @@ +use slog::Logger; +use std::fs; +use std::io; +use std::path::{Path, PathBuf}; +use target; +use which::which; + +/// Get the path for a crate's directory of locally-installed binaries. +/// +/// This does not check whether or ensure that the directory exists. +pub fn local_bin_dir(crate_path: &Path) -> PathBuf { + crate_path.join("bin") +} + +/// Ensure that the crate's directory for locally-installed binaries exists. +pub fn ensure_local_bin_dir(crate_path: &Path) -> io::Result<()> { + fs::create_dir_all(local_bin_dir(crate_path)) +} + +/// Get the path for where `bin` would be if we have a crate-local install for +/// it. +/// +/// This does *not* check whether there is a file at that path or not. +/// +/// This will automatically add the `.exe` extension for windows. +pub fn local_bin_path(crate_path: &Path, bin: &str) -> PathBuf { + let mut p = local_bin_dir(crate_path).join(bin); + if target::WINDOWS { + p.set_extension("exe"); + } + p +} + +/// Get the local (at `$CRATE/bin/$BIN`; preferred) or global (on `$PATH`) path +/// for the given binary. +/// +/// If this function returns `Some(path)`, then a file at that path exists (or +/// at least existed when we checked! In general, we aren't really worried about +/// racing with an uninstall of a tool that we rely on.) +pub fn bin_path(log: &Logger, crate_path: &Path, bin: &str) -> Option { + assert!(!bin.ends_with(".exe")); + debug!(log, "Searching for {} binary...", bin); + + // Return the path to the local binary, if it exists. + let local_path = |crate_path: &Path| -> Option { + let p = local_bin_path(crate_path, bin); + debug!(log, "Checking for local {} binary at {}", bin, p.display()); + if p.is_file() { + Some(p) + } else { + None + } + }; + + // Return the path to the global binary, if it exists. + let global_path = || -> Option { + debug!(log, "Looking for global {} binary on $PATH", bin); + if let Ok(p) = which(bin) { + Some(p) + } else { + None + } + }; + + local_path(crate_path) + .or_else(global_path) + .map(|p| { + let p = p.canonicalize().unwrap_or(p); + debug!(log, "Using {} binary at {}", bin, p.display()); + p + }) + .or_else(|| { + debug!(log, "Could not find {} binary.", bin); + None + }) +} diff --git a/binary-install/src/target.rs b/binary-install/src/target.rs new file mode 100644 index 0000000..e3bfb9c --- /dev/null +++ b/binary-install/src/target.rs @@ -0,0 +1,8 @@ +//! Information about the target wasm-pack is currently being compiled for. +//! +//! That is, whether we are building wasm-pack for windows vs linux, and x86 vs +//! x86-64, etc. + +#![allow(missing_docs)] + +pub const WINDOWS: bool = cfg!(target_os = "windows"); diff --git a/src/binaries.rs b/src/binaries.rs deleted file mode 100644 index ba7a1ec..0000000 --- a/src/binaries.rs +++ /dev/null @@ -1,247 +0,0 @@ -//! Utilities for finding and installing binaries that we depend on. - -use curl; -use error::Error; -use failure; -use flate2; -use slog::Logger; -use std::collections::HashSet; -use std::ffi; -use std::fs; -use std::io; -use std::path::{Path, PathBuf}; -use tar; -use target; -use which::which; -use zip; - -/// Get the path for a crate's directory of locally-installed binaries. -/// -/// This does not check whether or ensure that the directory exists. -pub fn local_bin_dir(crate_path: &Path) -> PathBuf { - crate_path.join("bin") -} - -/// Ensure that the crate's directory for locally-installed binaries exists. -pub fn ensure_local_bin_dir(crate_path: &Path) -> io::Result<()> { - fs::create_dir_all(local_bin_dir(crate_path)) -} - -/// Get the path for where `bin` would be if we have a crate-local install for -/// it. -/// -/// This does *not* check whether there is a file at that path or not. -/// -/// This will automatically add the `.exe` extension for windows. -pub fn local_bin_path(crate_path: &Path, bin: &str) -> PathBuf { - let mut p = local_bin_dir(crate_path).join(bin); - if target::WINDOWS { - p.set_extension("exe"); - } - p -} - -/// Get the local (at `$CRATE/bin/$BIN`; preferred) or global (on `$PATH`) path -/// for the given binary. -/// -/// If this function returns `Some(path)`, then a file at that path exists (or -/// at least existed when we checked! In general, we aren't really worried about -/// racing with an uninstall of a tool that we rely on.) -pub fn bin_path(log: &Logger, crate_path: &Path, bin: &str) -> Option { - assert!(!bin.ends_with(".exe")); - debug!(log, "Searching for {} binary...", bin); - - // Return the path to the local binary, if it exists. - let local_path = |crate_path: &Path| -> Option { - let p = local_bin_path(crate_path, bin); - debug!(log, "Checking for local {} binary at {}", bin, p.display()); - if p.is_file() { - Some(p) - } else { - None - } - }; - - // Return the path to the global binary, if it exists. - let global_path = || -> Option { - debug!(log, "Looking for global {} binary on $PATH", bin); - if let Ok(p) = which(bin) { - Some(p) - } else { - None - } - }; - - local_path(crate_path) - .or_else(global_path) - .map(|p| { - let p = p.canonicalize().unwrap_or(p); - debug!(log, "Using {} binary at {}", bin, p.display()); - p - }) - .or_else(|| { - debug!(log, "Could not find {} binary.", bin); - None - }) -} - -fn with_url_context(url: &str, r: Result) -> Result -where - Result: failure::ResultExt, -{ - use failure::ResultExt; - r.with_context(|_| format!("when requesting {}", url)) -} - -fn transfer( - url: &str, - easy: &mut curl::easy::Easy, - data: &mut Vec, -) -> Result<(), failure::Error> { - let mut transfer = easy.transfer(); - with_url_context( - url, - transfer.write_function(|part| { - data.extend_from_slice(part); - Ok(part.len()) - }), - )?; - with_url_context(url, transfer.perform())?; - Ok(()) -} - -fn curl(url: &str) -> Result, failure::Error> { - let mut data = Vec::new(); - - let mut easy = curl::easy::Easy::new(); - with_url_context(url, easy.follow_location(true))?; - with_url_context(url, easy.url(url))?; - transfer(url, &mut easy, &mut data)?; - - let status_code = with_url_context(url, easy.response_code())?; - if 200 <= status_code && status_code < 300 { - Ok(data) - } else { - Err(Error::http(&format!( - "received a bad HTTP status code ({}) when requesting {}", - status_code, url - )) - .into()) - } -} - -/// Download the `.tar.gz` file at the given URL and unpack the given binaries -/// from it into the given crate. -/// -/// Upon success, every `$BIN` in `binaries` will be at `$CRATE/bin/$BIN`. -pub fn install_binaries_from_targz_at_url<'a, I>( - crate_path: &Path, - url: &str, - binaries: I, -) -> Result<(), failure::Error> -where - I: IntoIterator, -{ - let mut binaries: HashSet<_> = binaries.into_iter().map(ffi::OsStr::new).collect(); - - let tarball = curl(&url).map_err(|e| Error::http(&e.to_string()))?; - let mut archive = tar::Archive::new(flate2::read::GzDecoder::new(&tarball[..])); - - ensure_local_bin_dir(crate_path)?; - let bin = local_bin_dir(crate_path); - - for entry in archive.entries()? { - let mut entry = entry?; - - let dest = match entry.path()?.file_stem() { - Some(f) if binaries.contains(f) => { - binaries.remove(f); - bin.join(entry.path()?.file_name().unwrap()) - } - _ => continue, - }; - - entry.unpack(dest)?; - } - - if binaries.is_empty() { - Ok(()) - } else { - Err(Error::archive(&format!( - "the tarball at {} was missing expected executables: {}", - url, - binaries - .into_iter() - .map(|s| s.to_string_lossy()) - .collect::>() - .join(", "), - )) - .into()) - } -} - -/// Install binaries from within the given zip at the given URL. -/// -/// Upon success, the binaries will be at the `$CRATE/bin/$BIN` path. -pub fn install_binaries_from_zip_at_url<'a, I>( - crate_path: &Path, - url: &str, - binaries: I, -) -> Result<(), failure::Error> -where - I: IntoIterator, -{ - let mut binaries: HashSet<_> = binaries.into_iter().map(ffi::OsStr::new).collect(); - - let data = curl(&url).map_err(|e| Error::http(&e.to_string()))?; - let data = io::Cursor::new(data); - let mut zip = zip::ZipArchive::new(data)?; - - ensure_local_bin_dir(crate_path)?; - let bin = local_bin_dir(crate_path); - - for i in 0..zip.len() { - let mut entry = zip.by_index(i).unwrap(); - let entry_path = entry.sanitized_name(); - match entry_path.file_stem() { - Some(f) if binaries.contains(f) => { - binaries.remove(f); - let mut dest = bin_open_options() - .write(true) - .create_new(true) - .open(bin.join(entry_path.file_name().unwrap()))?; - io::copy(&mut entry, &mut dest)?; - } - _ => continue, - }; - } - - if binaries.is_empty() { - Ok(()) - } else { - Err(Error::archive(&format!( - "the zip at {} was missing expected executables: {}", - url, - binaries - .into_iter() - .map(|s| s.to_string_lossy()) - .collect::>() - .join(", "), - )) - .into()) - } -} - -#[cfg(unix)] -fn bin_open_options() -> fs::OpenOptions { - use std::os::unix::fs::OpenOptionsExt; - - let mut opts = fs::OpenOptions::new(); - opts.mode(0o755); - opts -} - -#[cfg(not(unix))] -fn bin_open_options() -> fs::OpenOptions { - fs::OpenOptions::new() -} diff --git a/src/bindgen.rs b/src/bindgen.rs index 68e9b60..8a95f67 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -1,6 +1,9 @@ //! Functionality related to installing and running `wasm-bindgen`. -use binaries::{self, bin_path, install_binaries_from_targz_at_url}; +use binary_install::{ + install_binaries_from_targz_at_url, + path::{bin_path, local_bin_path}, +}; use child; use emoji; use error::Error; @@ -102,7 +105,7 @@ pub fn cargo_install_wasm_bindgen( .arg(crate_path); child::run(logger, cmd, "cargo install").context("Installing wasm-bindgen with cargo")?; - assert!(binaries::local_bin_path(crate_path, "wasm-bindgen").is_file()); + assert!(local_bin_path(crate_path, "wasm-bindgen").is_file()); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index ed2e390..fdaa447 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ extern crate serde_json; extern crate structopt; #[macro_use] extern crate slog; +extern crate binary_install; extern crate slog_async; extern crate slog_term; extern crate tar; @@ -26,7 +27,6 @@ extern crate toml; extern crate which; extern crate zip; -pub mod binaries; pub mod bindgen; pub mod build; pub mod child; diff --git a/src/test/webdriver.rs b/src/test/webdriver.rs index cac6d39..d8afe00 100644 --- a/src/test/webdriver.rs +++ b/src/test/webdriver.rs @@ -1,7 +1,8 @@ //! Getting WebDriver client binaries. -use binaries::{ - self, bin_path, install_binaries_from_targz_at_url, install_binaries_from_zip_at_url, +use binary_install::{ + install_binaries_from_targz_at_url, install_binaries_from_zip_at_url, + path::{bin_path, local_bin_path}, }; use command::build::BuildMode; use error::Error; @@ -31,7 +32,7 @@ pub fn get_or_install_chromedriver( } fn get_local_chromedriver_path(crate_path: &Path) -> PathBuf { - binaries::local_bin_path(crate_path, "chromedriver") + local_bin_path(crate_path, "chromedriver") } fn get_chromedriver_url() -> Result { @@ -106,7 +107,7 @@ fn get_geckodriver_url() -> Result { } fn get_local_geckodriver_path(crate_path: &Path) -> PathBuf { - binaries::local_bin_path(crate_path, "geckodriver") + local_bin_path(crate_path, "geckodriver") } /// Download and install a pre-built `geckodriver` binary. diff --git a/tests/all/main.rs b/tests/all/main.rs index 553ce1f..2d828c0 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -4,6 +4,7 @@ extern crate serde_derive; extern crate serde_json; #[macro_use] extern crate slog; +extern crate binary_install; extern crate structopt; extern crate tempfile; extern crate wasm_pack; diff --git a/tests/all/test.rs b/tests/all/test.rs index 54d4131..6e3924b 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -1,8 +1,8 @@ +use binary_install; use std::env; use std::fs; use tempfile; use utils::fixture; -use wasm_pack::binaries; use wasm_pack::command::{self, build, test, Command}; use wasm_pack::logger; @@ -116,7 +116,7 @@ fn it_can_find_a_webdriver_on_path() { fixture.install_local_geckodriver(); let geckodriver_dir = tempfile::TempDir::new().unwrap(); - let local_geckodriver = binaries::local_bin_path(&fixture.path, "geckodriver"); + let local_geckodriver = binary_install::path::local_bin_path(&fixture.path, "geckodriver"); fs::copy( &local_geckodriver, geckodriver_dir diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index dc47369..7c58e46 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -1,4 +1,5 @@ use super::logger::null_logger; +use binary_install; use std::env; use std::fs; use std::io; @@ -138,9 +139,9 @@ impl Fixture { static INSTALL_WASM_BINDGEN: Once = ONCE_INIT; let tests = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"); - let shared_wasm_bindgen = wasm_pack::binaries::local_bin_path(&tests, "wasm-bindgen"); + let shared_wasm_bindgen = binary_install::path::local_bin_path(&tests, "wasm-bindgen"); let shared_wasm_bindgen_test_runner = - wasm_pack::binaries::local_bin_path(&tests, "wasm-bindgen-test-runner"); + binary_install::path::local_bin_path(&tests, "wasm-bindgen-test-runner"); INSTALL_WASM_BINDGEN.call_once(|| { if shared_wasm_bindgen.is_file() { @@ -163,17 +164,17 @@ impl Fixture { assert!(shared_wasm_bindgen.is_file()); assert!(shared_wasm_bindgen_test_runner.is_file()); - wasm_pack::binaries::ensure_local_bin_dir(&self.path).unwrap(); + binary_install::path::ensure_local_bin_dir(&self.path).unwrap(); hard_link_or_copy( &shared_wasm_bindgen, - wasm_pack::binaries::local_bin_path(&self.path, "wasm-bindgen"), + binary_install::path::local_bin_path(&self.path, "wasm-bindgen"), ) .expect("could not copy `wasm-bindgen` to fixture directory"); hard_link_or_copy( &shared_wasm_bindgen_test_runner, - wasm_pack::binaries::local_bin_path(&self.path, "wasm-bindgen-test-runner"), + binary_install::path::local_bin_path(&self.path, "wasm-bindgen-test-runner"), ) .expect("could not copy `wasm-bindgen-test` to fixture directory"); @@ -189,10 +190,10 @@ impl Fixture { let tests = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"); - wasm_pack::binaries::ensure_local_bin_dir(&tests) + binary_install::path::ensure_local_bin_dir(&tests) .expect("could not create fixture's `bin` directory"); - let geckodriver = wasm_pack::binaries::local_bin_path(&tests, "geckodriver"); + let geckodriver = binary_install::path::local_bin_path(&tests, "geckodriver"); FETCH_GECKODRIVER.call_once(|| { if geckodriver.is_file() { @@ -203,12 +204,12 @@ impl Fixture { assert!(geckodriver.is_file()); }); - wasm_pack::binaries::ensure_local_bin_dir(&self.path) + binary_install::path::ensure_local_bin_dir(&self.path) .expect("could not create fixture's `bin` directory"); hard_link_or_copy( &geckodriver, - wasm_pack::binaries::local_bin_path(&self.path, "geckodriver"), + binary_install::path::local_bin_path(&self.path, "geckodriver"), ) .expect("could not copy `geckodriver` to fixture directory"); @@ -224,10 +225,10 @@ impl Fixture { let tests = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"); - wasm_pack::binaries::ensure_local_bin_dir(&tests) + binary_install::path::ensure_local_bin_dir(&tests) .expect("could not create fixture's `bin` directory"); - let chromedriver = wasm_pack::binaries::local_bin_path(&tests, "chromedriver"); + let chromedriver = binary_install::path::local_bin_path(&tests, "chromedriver"); FETCH_CHROMEDRIVER.call_once(|| { if chromedriver.is_file() { @@ -238,12 +239,12 @@ impl Fixture { assert!(chromedriver.is_file()); }); - wasm_pack::binaries::ensure_local_bin_dir(&self.path) + binary_install::path::ensure_local_bin_dir(&self.path) .expect("could not create fixture's `bin` directory"); hard_link_or_copy( &chromedriver, - wasm_pack::binaries::local_bin_path(&self.path, "chromedriver"), + binary_install::path::local_bin_path(&self.path, "chromedriver"), ) .expect("could not copy `chromedriver` to fixture directory"); From ac70220610f832815ae3bf94be8ee31ef80ee674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Mon, 15 Oct 2018 21:33:24 +0200 Subject: [PATCH 02/17] Remove authors from binary-install Cargo.toml --- binary-install/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/binary-install/Cargo.toml b/binary-install/Cargo.toml index 2912fcb..a525303 100644 --- a/binary-install/Cargo.toml +++ b/binary-install/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "binary-install" version = "0.1.0" -authors = ["Jesper HÃ¥kansson "] [dependencies] curl = "0.4.13" From 16a169bd525ddb6dcd796d3f7968330bb480d143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Mon, 29 Oct 2018 19:18:29 +0100 Subject: [PATCH 03/17] fix: Exclude target so tests works --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b739d3e..8282b47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ categories = ["wasm"] documentation = "https://rustwasm.github.io/wasm-pack/" [workspace] -members = [".", "binary-install"] +members = ["binary-install"] +exclude = ["target"] [dependencies] atty = "0.2.11" From 65d060cfc417998df1941a1a45dd71aaa7bf8989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Mon, 29 Oct 2018 19:54:46 +0100 Subject: [PATCH 04/17] chore: Run latest rustfmt --- src/error.rs | 5 +--- tests/all/bindgen.rs | 26 +++++++++--------- tests/all/manifest.rs | 63 ++++++++++++++++++++++--------------------- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/error.rs b/src/error.rs index 4fcc513..75c43b3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -49,10 +49,7 @@ pub enum Error { /// An error invoking another CLI tool. #[fail( display = "Process exited with {}: {}.\n\nstdout:{}\n\nstderr:\n\n{}", - exit_status, - message, - stdout, - stderr + exit_status, message, stdout, stderr )] Cli { /// Error message. diff --git a/tests/all/bindgen.rs b/tests/all/bindgen.rs index b79d58c..4892019 100644 --- a/tests/all/bindgen.rs +++ b/tests/all/bindgen.rs @@ -11,20 +11,18 @@ fn can_download_prebuilt_wasm_bindgen() { use std::env; let dir = tempfile::TempDir::new().unwrap(); bindgen::download_prebuilt_wasm_bindgen(dir.path(), "0.2.21").unwrap(); - assert!( - dir.path() - .join("bin") - .join("wasm-bindgen") - .with_extension(env::consts::EXE_EXTENSION) - .is_file() - ); - assert!( - dir.path() - .join("bin") - .join("wasm-bindgen-test-runner") - .with_extension(env::consts::EXE_EXTENSION) - .is_file() - ); + assert!(dir + .path() + .join("bin") + .join("wasm-bindgen") + .with_extension(env::consts::EXE_EXTENSION) + .is_file()); + assert!(dir + .path() + .join("bin") + .join("wasm-bindgen-test-runner") + .with_extension(env::consts::EXE_EXTENSION) + .is_file()); } #[test] diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 1add2b7..459b8ab 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -83,9 +83,9 @@ fn it_creates_a_package_json_default_path() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -109,9 +109,9 @@ fn it_creates_a_package_json_provided_path() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -121,17 +121,15 @@ fn it_creates_a_package_json_provided_path_with_scope() { let out_dir = fixture.path.join("pkg"); let step = wasm_pack::progressbar::Step::new(1); wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); - assert!( - manifest::write_package_json( - &fixture.path, - &out_dir, - &Some("test".to_string()), - false, - "", - &step - ) - .is_ok() - ); + assert!(manifest::write_package_json( + &fixture.path, + &out_dir, + &Some("test".to_string()), + false, + "", + &step + ) + .is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); assert!(fs::metadata(package_json_path).is_ok()); assert!(utils::manifest::read_package_json(&fixture.path, &out_dir).is_ok()); @@ -145,9 +143,9 @@ fn it_creates_a_package_json_provided_path_with_scope() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -180,9 +178,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { "js_hello_world_bg.js", "js_hello_world.d.ts", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -192,10 +190,15 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { let out_dir = fixture.path.join("pkg"); let step = wasm_pack::progressbar::Step::new(1); wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap(); - assert!( - manifest::write_package_json(&fixture.path, &out_dir, &None, false, "no-modules", &step) - .is_ok() - ); + assert!(manifest::write_package_json( + &fixture.path, + &out_dir, + &None, + false, + "no-modules", + &step + ) + .is_ok()); let package_json_path = &out_dir.join("package.json"); assert!(fs::metadata(package_json_path).is_ok()); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -215,9 +218,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { "js_hello_world.js", "js_hello_world.d.ts", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } From 69ee13b3b318adbe2b43eb8495b491029a5d9c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Mon, 29 Oct 2018 20:50:14 +0100 Subject: [PATCH 05/17] test: Add tests for path functions --- Cargo.lock | 2 ++ binary-install/Cargo.toml | 2 ++ binary-install/tests/path.rs | 70 ++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 binary-install/tests/path.rs diff --git a/Cargo.lock b/Cargo.lock index 704e56d..24177a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,8 @@ dependencies = [ "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/binary-install/Cargo.toml b/binary-install/Cargo.toml index a525303..bf51cf1 100644 --- a/binary-install/Cargo.toml +++ b/binary-install/Cargo.toml @@ -7,6 +7,8 @@ curl = "0.4.13" failure = "0.1.2" flate2 = "1.0.2" slog = "2.3" +slog-term = "2.4" +slog-async = "2.3" tar = "0.4.16" which = "2.0.0" zip = "0.4.2" diff --git a/binary-install/tests/path.rs b/binary-install/tests/path.rs new file mode 100644 index 0000000..f6463c1 --- /dev/null +++ b/binary-install/tests/path.rs @@ -0,0 +1,70 @@ +extern crate binary_install; +#[macro_use] +extern crate slog; +extern crate slog_async; +extern crate slog_term; + +use binary_install::path::{bin_path, ensure_local_bin_dir, local_bin_path}; +use slog::Drain; +use std::path::Path; + +fn logger() -> slog::Logger { + let decorator = slog_term::TermDecorator::new().build(); + let drain = slog_term::FullFormat::new(decorator).build().fuse(); + let drain = slog_async::Async::new(drain).build().fuse(); + slog::Logger::root(drain, o!()) +} + +#[test] +fn it_should_get_local_bin_path() { + let crate_path = Path::new(""); + + let expected_path = Path::new("bin/wasm-bindgen"); + + let result = local_bin_path(crate_path, "wasm-bindgen"); + + assert_eq!(expected_path, result); +} + +#[test] +#[cfg(target_os = "windows")] +fn it_should_get_local_bin_path_with_exe_for_windows() { + let crate_path = Path::new(""); + + let expected_path = Path::new("bin/wasm-bindgen.exe"); + + let result = local_bin_path(crate_path, "wasm-bindgen"); + + assert_eq!(expected_path, result); +} + +#[test] +fn it_should_ensure_local_bin_dir_returns_ok_for_folder_that_exists() { + let crate_path = Path::new("random_folder"); + + let result = ensure_local_bin_dir(crate_path); + + assert!(result.is_ok()); +} + +#[test] +fn it_should_return_some_for_bin_path_that_exists() { + let crate_path = Path::new("/usr/bin"); + let bin = "ls"; + + let result = bin_path(&logger(), crate_path, bin); + let expected_bin = Path::new("/usr/bin/ls"); + + assert!(result.is_some()); + assert_eq!(result.unwrap(), expected_bin); +} + +#[test] +fn it_should_return_none_for_bin_path_that_does_not_exists() { + let crate_path = Path::new("random_folder"); + let bin = "wasm-bindgen"; + + let result = bin_path(&logger(), crate_path, bin); + + assert!(result.is_none()); +} From 8150ba39fb06f06b7ef34004f3c446aeb6a1b77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 30 Oct 2018 21:56:21 +0100 Subject: [PATCH 06/17] chore: Run cargo update --- Cargo.lock | 82 +++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dec612c..9cd245f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,10 +5,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "aho-corasick" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -55,8 +55,8 @@ name = "binary-install" version = "0.1.0" dependencies = [ "curl 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -77,7 +77,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.6" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -209,7 +209,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "libz-sys 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.39 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -239,9 +239,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -363,7 +363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libz-sys" -version = "1.0.24" +version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -383,7 +383,7 @@ dependencies = [ [[package]] name = "memchr" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -536,7 +536,7 @@ dependencies = [ [[package]] name = "quote" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", @@ -595,11 +595,11 @@ name = "regex" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.1 (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.1 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -607,11 +607,11 @@ name = "regex" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.2 (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.1 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -619,7 +619,7 @@ name = "regex-syntax" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ucd-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -627,7 +627,7 @@ name = "regex-syntax" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ucd-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -695,8 +695,8 @@ version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -780,28 +780,28 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "syn" -version = "0.15.13" +version = "0.15.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "synstructure" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -848,7 +848,7 @@ name = "term" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -914,7 +914,7 @@ dependencies = [ [[package]] name = "ucd-util" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -937,7 +937,7 @@ dependencies = [ [[package]] name = "utf8-ranges" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1067,14 +1067,14 @@ dependencies = [ [metadata] "checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" -"checksum aho-corasick 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "68f56c7353e5a9547cbd76ed90f7bb5ffc3ba09d4ea9bd1d8c06c8b1142eeb5a" +"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" "checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a" "checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" -"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781" +"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" "checksum bzip2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b" "checksum bzip2-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2c5162604199bbb17690ede847eaa6120a3f33d5ab4dcc8e7c25b16d849ae79b" "checksum cargo_metadata 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1aaa1a9856ae2d188340526d0986feb6899c9ad11c5dfd73453c784fed6e373d" @@ -1105,9 +1105,9 @@ dependencies = [ "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" -"checksum libz-sys 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "4401fe74560a0d46fce3464625ac8aa7a79d291dd28cee021d18852d5191c280" +"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" "checksum lock_api 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775751a3e69bde4df9b38dd00a1b5d6ac13791e4223d4a0506577f0dd27cfb7a" -"checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b" +"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" "checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649" "checksum miniz_oxide 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ad30a47319c16cde58d0314f5d98202a80c9083b5f61178457403dfb14e509c" "checksum miniz_oxide_c_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28edaef377517fd9fe3e085c37d892ce7acd1fbeab9239c5a36eec352d8a8b7e" @@ -1125,7 +1125,7 @@ dependencies = [ "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" "checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee" -"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" +"checksum quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5829244f52738cfee93b3a165c1911388675be000c888d2fae620dee8fa5b" "checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" "checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" @@ -1156,8 +1156,8 @@ dependencies = [ "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum structopt 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "d77af7242f18c40fd19cb270985930f239ee1646cfb482050bbae9da1d18743b" "checksum structopt-derive 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "17ff01fe96de9d16e7372ae5f19dd7ece2c703b51043c3db9ea27f9e393ea311" -"checksum syn 0.15.13 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4439ee8325b4e4b57e59309c3724c9a4478eaeb4eb094b6f3fac180a3b2876" -"checksum synstructure 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec37f4fab4bafaf6b5621c1d54e6aa5d4d059a8f84929e87abfdd7f9f04c6db2" +"checksum syn 0.15.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0b78d53b5e1b6e63129140b1336877c3bddbae398c7956150396bdad0e28676c" +"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum tar 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)" = "83b0d14b53dbfd62681933fadd651e815f99e6084b649e049ab99296e05ab3de" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" @@ -1170,11 +1170,11 @@ dependencies = [ "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" "checksum toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4a2ecc31b0351ea18b3fe11274b8db6e4d82bce861bbb22e6dbed40417902c65" -"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" +"checksum ucd-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0f8bfa9ff0cadcd210129ad9d2c5f145c13e9ced3d3e5d948a6213487d52444" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd70f467df6810094968e2fce0ee1bd0e87157aceb026a8c083bcf5e25b9efe4" +"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e1436e58182935dcd9ce0add9ea0b558e8a87befe01c1a301e6020aeb0876363" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" From 70df15fcca9126a2507fbc19e2946b8b3223d6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 30 Oct 2018 22:17:05 +0100 Subject: [PATCH 07/17] test: Rework and rename path tests --- binary-install/tests/path.rs | 51 +++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/binary-install/tests/path.rs b/binary-install/tests/path.rs index f6463c1..3225fe9 100644 --- a/binary-install/tests/path.rs +++ b/binary-install/tests/path.rs @@ -6,7 +6,10 @@ extern crate slog_term; use binary_install::path::{bin_path, ensure_local_bin_dir, local_bin_path}; use slog::Drain; -use std::path::Path; +use std::env::current_dir; +use std::fs; +use std::io; +use std::path::{Path, PathBuf}; fn logger() -> slog::Logger { let decorator = slog_term::TermDecorator::new().build(); @@ -15,8 +18,13 @@ fn logger() -> slog::Logger { slog::Logger::root(drain, o!()) } +fn get_tests_bin_path() -> PathBuf { + let path = current_dir().unwrap(); + path.join("tests/bin") +} + #[test] -fn it_should_get_local_bin_path() { +fn get_local_bin_path_should_return_a_path() { let crate_path = Path::new(""); let expected_path = Path::new("bin/wasm-bindgen"); @@ -28,7 +36,7 @@ fn it_should_get_local_bin_path() { #[test] #[cfg(target_os = "windows")] -fn it_should_get_local_bin_path_with_exe_for_windows() { +fn get_local_bin_path_should_return_with_exe_for_windows() { let crate_path = Path::new(""); let expected_path = Path::new("bin/wasm-bindgen.exe"); @@ -39,32 +47,33 @@ fn it_should_get_local_bin_path_with_exe_for_windows() { } #[test] -fn it_should_ensure_local_bin_dir_returns_ok_for_folder_that_exists() { - let crate_path = Path::new("random_folder"); +fn ensure_local_bin_dir_should_return_ok_for_folder_that_exists() { + let crate_path = get_tests_bin_path(); - let result = ensure_local_bin_dir(crate_path); + fs::create_dir_all(crate_path.to_owned()).unwrap(); + + let result = ensure_local_bin_dir(&crate_path); assert!(result.is_ok()); + + fs::remove_dir_all(crate_path).unwrap(); } #[test] -fn it_should_return_some_for_bin_path_that_exists() { - let crate_path = Path::new("/usr/bin"); - let bin = "ls"; +fn ensure_local_bin_dir_should_create_folder_if_it_doesnt_exist() { + let crate_path = get_tests_bin_path(); - let result = bin_path(&logger(), crate_path, bin); - let expected_bin = Path::new("/usr/bin/ls"); + // Make sure that the folder doesn't exist + // before we call ensure_local_bin_dir(); + let dir = fs::read_dir(crate_path.to_owned()); + let dir_error = dir.err().unwrap(); + assert_eq!(dir_error.kind(), io::ErrorKind::NotFound); - assert!(result.is_some()); - assert_eq!(result.unwrap(), expected_bin); -} - -#[test] -fn it_should_return_none_for_bin_path_that_does_not_exists() { - let crate_path = Path::new("random_folder"); - let bin = "wasm-bindgen"; + let result = ensure_local_bin_dir(&crate_path); - let result = bin_path(&logger(), crate_path, bin); + assert!(result.is_ok()); - assert!(result.is_none()); + // Make sure that the directory actually exists. + let dir = fs::read_dir(crate_path.to_owned()); + assert!(dir.is_ok()); } From 37dac09ce53035c825093eb158355d083d9241ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Wed, 31 Oct 2018 20:25:50 +0100 Subject: [PATCH 08/17] test: More tests for path functions as well as minor fixes --- binary-install/tests/path.rs | 45 +++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/binary-install/tests/path.rs b/binary-install/tests/path.rs index 3225fe9..b32bbcd 100644 --- a/binary-install/tests/path.rs +++ b/binary-install/tests/path.rs @@ -20,10 +20,11 @@ fn logger() -> slog::Logger { fn get_tests_bin_path() -> PathBuf { let path = current_dir().unwrap(); - path.join("tests/bin") + path.join("tests") } #[test] +#[cfg(not(target_ = "wasm32"))] fn get_local_bin_path_should_return_a_path() { let crate_path = Path::new(""); @@ -48,7 +49,7 @@ fn get_local_bin_path_should_return_with_exe_for_windows() { #[test] fn ensure_local_bin_dir_should_return_ok_for_folder_that_exists() { - let crate_path = get_tests_bin_path(); + let crate_path = get_tests_bin_path().join("bin2"); fs::create_dir_all(crate_path.to_owned()).unwrap(); @@ -61,7 +62,7 @@ fn ensure_local_bin_dir_should_return_ok_for_folder_that_exists() { #[test] fn ensure_local_bin_dir_should_create_folder_if_it_doesnt_exist() { - let crate_path = get_tests_bin_path(); + let crate_path = get_tests_bin_path().join("bin3"); // Make sure that the folder doesn't exist // before we call ensure_local_bin_dir(); @@ -76,4 +77,42 @@ fn ensure_local_bin_dir_should_create_folder_if_it_doesnt_exist() { // Make sure that the directory actually exists. let dir = fs::read_dir(crate_path.to_owned()); assert!(dir.is_ok()); + + fs::remove_dir_all(crate_path).unwrap(); +} + +#[test] +fn bin_path_should_return_some_for_path_that_exists() { + let crate_path = get_tests_bin_path(); + let bin_file = "wasm-bindgen"; + let full_bin_path = crate_path.join("bin"); + let path_with_bin_file = full_bin_path.join(bin_file); + + fs::create_dir_all(full_bin_path.to_owned()).unwrap(); + fs::File::create(path_with_bin_file.to_owned()).unwrap(); + + let result = bin_path(&logger(), &crate_path, bin_file); + + assert!(result.is_some()); + assert_eq!(path_with_bin_file, result.unwrap()); + + fs::remove_dir_all(full_bin_path).unwrap(); +} + +#[test] +fn bin_path_should_return_none_for_path_that_does_not_exists() { + let crate_path = get_tests_bin_path(); + let bin_file = "wasm-binfile"; + let full_bin_path = crate_path.join("bin_path"); + let path_with_bin_file = full_bin_path.join(bin_file); + + // Make sure that the folder doesn't exist + // before we call bin_path(); + let file = fs::File::open(path_with_bin_file.to_owned()); + let file_error = file.err().unwrap(); + assert_eq!(file_error.kind(), io::ErrorKind::NotFound); + + let result = bin_path(&logger(), &crate_path, bin_file); + + assert!(result.is_none()); } From 10080c27944913a6b3aaa2db7a4377ec2e598e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Wed, 31 Oct 2018 20:41:16 +0100 Subject: [PATCH 09/17] fix: not(target_os = "windows") --- binary-install/tests/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binary-install/tests/path.rs b/binary-install/tests/path.rs index b32bbcd..1c0e21d 100644 --- a/binary-install/tests/path.rs +++ b/binary-install/tests/path.rs @@ -24,7 +24,7 @@ fn get_tests_bin_path() -> PathBuf { } #[test] -#[cfg(not(target_ = "wasm32"))] +#[cfg(not(target_os = "windows"))] fn get_local_bin_path_should_return_a_path() { let crate_path = Path::new(""); From d5faedd200c138d95d4ee495bebace07733aedce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Thu, 1 Nov 2018 21:02:27 +0100 Subject: [PATCH 10/17] test: Add initial tests for exposed functions in lib --- binary-install/src/lib.rs | 3 +- binary-install/tests/test.rs | 73 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 binary-install/tests/test.rs diff --git a/binary-install/src/lib.rs b/binary-install/src/lib.rs index 3ff5e4b..728ee12 100644 --- a/binary-install/src/lib.rs +++ b/binary-install/src/lib.rs @@ -47,7 +47,8 @@ where let bin = local_bin_dir(crate_path); for entry in archive.entries()? { - let mut entry = entry?; + let mut entry = + entry.map_err(|_err| Error::archive(&format!("Invalid tarball at {}", url)))?; let dest = match entry.path()?.file_stem() { Some(f) if binaries.contains(f) => { diff --git a/binary-install/tests/test.rs b/binary-install/tests/test.rs new file mode 100644 index 0000000..73f4298 --- /dev/null +++ b/binary-install/tests/test.rs @@ -0,0 +1,73 @@ +extern crate binary_install; +extern crate curl; +extern crate failure; + +use binary_install::{error::Error, install_binaries_from_targz_at_url}; +use std::io::{Read, Write}; +use std::net::TcpListener; +use std::path::Path; +use std::thread; + +const SERVER_URL: &'static str = "localhost:7878"; + +fn start_server() -> thread::JoinHandle { + thread::spawn(|| { + let listener = TcpListener::bind(SERVER_URL).unwrap(); + for stream in listener.incoming() { + let mut stream = stream.unwrap(); + + let mut buffer = [0; 512]; + + stream.read(&mut buffer).unwrap(); + + let response = "HTTP/1.1 200 OK\r\n\r\n"; + + stream.write(response.as_bytes()).unwrap(); + stream.flush().unwrap(); + } + listener + }) +} + +#[test] +fn install_binaries_from_targz_at_url_should_return_http_error_for_bad_url() { + let crate_path = Path::new(""); + let url = ""; + let binaries = vec![""]; + + let result = install_binaries_from_targz_at_url(crate_path, url, binaries); + assert!(result.is_err()); + + let err = result.err().unwrap(); + let err = err.downcast_ref::().unwrap(); + + let expected_message = format!("when requesting {}", url); + + match err { + Error::Http { message } => assert_eq!(&expected_message, message), + _ => panic!("Wrong error returned"), + } +} + +#[test] +fn install_binaries_from_targz_at_url_should_return_archive_error_when_tarball_is_missing() { + let crate_path = Path::new(""); + let url = format!("http://{}", SERVER_URL); + let binaries = vec![""]; + + // Spin up a local TcpListener. + start_server(); + + let result = install_binaries_from_targz_at_url(crate_path, &url, binaries); + assert!(result.is_err()); + + let err = result.err().unwrap(); + let err = err.downcast_ref::().unwrap(); + + let expected_message = format!("Invalid tarball at {}", url); + + match err { + Error::Archive { message } => assert_eq!(&expected_message, message), + _ => panic!("Wrong error returned"), + } +} From 98b405c36605ba2d702091d843f61d1b32548749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Sat, 3 Nov 2018 15:00:50 +0100 Subject: [PATCH 11/17] refactor: Use env::temp_dir() instead of current_dir() for tests --- binary-install/tests/path.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/binary-install/tests/path.rs b/binary-install/tests/path.rs index 1c0e21d..a9c3b95 100644 --- a/binary-install/tests/path.rs +++ b/binary-install/tests/path.rs @@ -6,7 +6,7 @@ extern crate slog_term; use binary_install::path::{bin_path, ensure_local_bin_dir, local_bin_path}; use slog::Drain; -use std::env::current_dir; +use std::env; use std::fs; use std::io; use std::path::{Path, PathBuf}; @@ -19,7 +19,7 @@ fn logger() -> slog::Logger { } fn get_tests_bin_path() -> PathBuf { - let path = current_dir().unwrap(); + let path = env::temp_dir(); path.join("tests") } From fa68a0d91f5c5973b9519b42d09c91d5b71c234a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Mon, 5 Nov 2018 21:54:42 +0100 Subject: [PATCH 12/17] test: Create and return tarball in tests, add more test cases --- binary-install/src/lib.rs | 5 +- binary-install/tests/path.rs | 13 ++-- binary-install/tests/test.rs | 111 ++++++++++++++++++++++++++++++++--- 3 files changed, 112 insertions(+), 17 deletions(-) diff --git a/binary-install/src/lib.rs b/binary-install/src/lib.rs index 728ee12..09f6982 100644 --- a/binary-install/src/lib.rs +++ b/binary-install/src/lib.rs @@ -47,8 +47,9 @@ where let bin = local_bin_dir(crate_path); for entry in archive.entries()? { - let mut entry = - entry.map_err(|_err| Error::archive(&format!("Invalid tarball at {}", url)))?; + let mut entry = entry.map_err(|err| { + Error::archive(&format!("Invalid tarball at {}. Inner error: {}", url, err)) + })?; let dest = match entry.path()?.file_stem() { Some(f) if binaries.contains(f) => { diff --git a/binary-install/tests/path.rs b/binary-install/tests/path.rs index a9c3b95..08139ec 100644 --- a/binary-install/tests/path.rs +++ b/binary-install/tests/path.rs @@ -9,7 +9,7 @@ use slog::Drain; use std::env; use std::fs; use std::io; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; fn logger() -> slog::Logger { let decorator = slog_term::TermDecorator::new().build(); @@ -26,11 +26,10 @@ fn get_tests_bin_path() -> PathBuf { #[test] #[cfg(not(target_os = "windows"))] fn get_local_bin_path_should_return_a_path() { - let crate_path = Path::new(""); - - let expected_path = Path::new("bin/wasm-bindgen"); + let crate_path = get_tests_bin_path(); + let expected_path = crate_path.join("bin/wasm-bindgen"); - let result = local_bin_path(crate_path, "wasm-bindgen"); + let result = local_bin_path(&crate_path, "wasm-bindgen"); assert_eq!(expected_path, result); } @@ -38,9 +37,9 @@ fn get_local_bin_path_should_return_a_path() { #[test] #[cfg(target_os = "windows")] fn get_local_bin_path_should_return_with_exe_for_windows() { - let crate_path = Path::new(""); + let crate_path = get_tests_bin_path(); - let expected_path = Path::new("bin/wasm-bindgen.exe"); + let expected_path = crate_path.join("bin/wasm-bindgen.exe"); let result = local_bin_path(crate_path, "wasm-bindgen"); diff --git a/binary-install/tests/test.rs b/binary-install/tests/test.rs index 73f4298..923688b 100644 --- a/binary-install/tests/test.rs +++ b/binary-install/tests/test.rs @@ -1,18 +1,25 @@ extern crate binary_install; extern crate curl; extern crate failure; +extern crate flate2; +extern crate tar; use binary_install::{error::Error, install_binaries_from_targz_at_url}; -use std::io::{Read, Write}; +use flate2::write::GzEncoder; +use flate2::Compression; +use std::env; +use std::fs::{File, OpenOptions}; +use std::io::{self, Read, Write}; use std::net::TcpListener; use std::path::Path; use std::thread; -const SERVER_URL: &'static str = "localhost:7878"; +const SERVER_HOST: &'static str = "localhost"; + +fn start_server(port: u32, tarball: Option>) -> thread::JoinHandle { + thread::spawn(move || { + let listener = TcpListener::bind(format!("{}:{}", SERVER_HOST, port)).unwrap(); -fn start_server() -> thread::JoinHandle { - thread::spawn(|| { - let listener = TcpListener::bind(SERVER_URL).unwrap(); for stream in listener.incoming() { let mut stream = stream.unwrap(); @@ -23,12 +30,49 @@ fn start_server() -> thread::JoinHandle { let response = "HTTP/1.1 200 OK\r\n\r\n"; stream.write(response.as_bytes()).unwrap(); + + match tarball.to_owned() { + Some(tar) => { + stream.write(tar.as_ref()).unwrap(); + } + None => {} + } + stream.flush().unwrap(); } listener }) } +fn create_tarball(binary_name: &str) -> Result, io::Error> { + let temp_dir = env::temp_dir(); + let tar = OpenOptions::new() + .create(true) + .read(true) + .write(true) + .open(temp_dir.join("foo.tar.gz"))?; + + let mut file = OpenOptions::new() + .create(true) + .read(true) + .write(true) + .open(temp_dir.join(binary_name))?; + + let mut encoder = GzEncoder::new(tar, Compression::default()); + { + let mut archive = tar::Builder::new(&mut encoder); + archive.append_file(binary_name, &mut file)?; + } + + let mut contents = vec![]; + + encoder.finish()?; + + File::open(temp_dir.join("foo.tar.gz"))?.read_to_end(&mut contents)?; + + Ok(contents) +} + #[test] fn install_binaries_from_targz_at_url_should_return_http_error_for_bad_url() { let crate_path = Path::new(""); @@ -51,12 +95,43 @@ fn install_binaries_from_targz_at_url_should_return_http_error_for_bad_url() { #[test] fn install_binaries_from_targz_at_url_should_return_archive_error_when_tarball_is_missing() { + let server_port = 7878; + let url = format!("http://{}:{}", SERVER_HOST, server_port); let crate_path = Path::new(""); - let url = format!("http://{}", SERVER_URL); let binaries = vec![""]; // Spin up a local TcpListener. - start_server(); + start_server(server_port, None); + + let result = install_binaries_from_targz_at_url(crate_path, &url, binaries); + assert!(result.is_err()); + + let err = result.err().unwrap(); + let err = err.downcast_ref::().unwrap(); + + let expected_message = format!( + "Invalid tarball at {}. Inner error: failed to fill whole buffer", + url + ); + + match err { + Error::Archive { message } => assert_eq!(&expected_message, message), + _ => panic!("Wrong error returned"), + } +} + +#[test] +fn install_binaries_from_targz_at_url_should_return_archive_error_when_tarball_does_not_include_all_files( +) { + let server_port = 7879; + let url = format!("http://{}:{}", SERVER_HOST, server_port); + let crate_path = Path::new(""); + let binaries = vec!["wasm-pack"]; + + // Create a temporary tarball. + let tarball = create_tarball("foo.txt").ok(); + // Spin up a local TcpListener. + start_server(server_port, tarball); let result = install_binaries_from_targz_at_url(crate_path, &url, binaries); assert!(result.is_err()); @@ -64,10 +139,30 @@ fn install_binaries_from_targz_at_url_should_return_archive_error_when_tarball_i let err = result.err().unwrap(); let err = err.downcast_ref::().unwrap(); - let expected_message = format!("Invalid tarball at {}", url); + let expected_message = format!( + "the tarball at {} was missing expected executables: {}", + url, "wasm-pack" + ); match err { Error::Archive { message } => assert_eq!(&expected_message, message), _ => panic!("Wrong error returned"), } } + +#[test] +fn install_binaries_from_targz_at_url_should_return_ok_if_binary_is_found() { + let server_port = 7880; + let url = format!("http://{}:{}", SERVER_HOST, server_port); + let binary_name = "wasm-pack"; + let crate_path = Path::new(""); + let binaries = vec![binary_name]; + + // Create a temporary tarball. + let tarball = create_tarball(binary_name).ok(); + // Spin up a local TcpListener. + start_server(server_port, tarball); + + let result = install_binaries_from_targz_at_url(crate_path, &url, binaries); + assert!(result.is_ok()); +} From 714a8a1581bf31fb89c5c849b8b2bc4735d84063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 6 Nov 2018 20:43:37 +0100 Subject: [PATCH 13/17] refactor: Remove unneeded code, since master has changed a lot The modules and tests are no longer relevant since master has changed a lot since the code was split into smalled modules. --- binary-install/src/error.rs | 44 --------- binary-install/src/fetch.rs | 47 ---------- binary-install/src/path.rs | 76 ---------------- binary-install/src/target.rs | 8 -- binary-install/tests/path.rs | 117 ------------------------ binary-install/tests/test.rs | 168 ----------------------------------- 6 files changed, 460 deletions(-) delete mode 100644 binary-install/src/error.rs delete mode 100644 binary-install/src/fetch.rs delete mode 100644 binary-install/src/path.rs delete mode 100644 binary-install/src/target.rs delete mode 100644 binary-install/tests/path.rs delete mode 100644 binary-install/tests/test.rs diff --git a/binary-install/src/error.rs b/binary-install/src/error.rs deleted file mode 100644 index 11fa2f0..0000000 --- a/binary-install/src/error.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Code related to error handling for binary-install - -/// Errors that can potentially occur in `binary-install`. -#[derive(Debug, Fail)] -pub enum Error { - #[fail(display = "{}", message)] - /// An error related to an archive that we downloaded. - Archive { - /// Error message. - message: String, - }, - - #[fail(display = "{}", message)] - /// Error related to some HTTP request. - Http { - /// Error message. - message: String, - }, -} - -impl Error { - /// Construct an archive error. - pub fn archive(message: &str) -> Self { - Error::Archive { - message: message.to_string(), - } - } - - /// Construct an http error. - pub fn http(message: &str) -> Self { - Error::Http { - message: message.to_string(), - } - } - - /// Get a string description of this error's type. - pub fn error_type(&self) -> String { - match self { - Error::Archive { .. } => "There was an error related to an archive file. Details:\n\n", - Error::Http { .. } => "There wasn an HTTP error. Details:\n\n", - } - .to_string() - } -} diff --git a/binary-install/src/fetch.rs b/binary-install/src/fetch.rs deleted file mode 100644 index 31772ee..0000000 --- a/binary-install/src/fetch.rs +++ /dev/null @@ -1,47 +0,0 @@ -use error::Error; -use failure; - -pub fn curl(url: &str) -> Result, failure::Error> { - let mut data = Vec::new(); - - let mut easy = curl::easy::Easy::new(); - with_url_context(url, easy.follow_location(true))?; - with_url_context(url, easy.url(url))?; - transfer(url, &mut easy, &mut data)?; - - let status_code = with_url_context(url, easy.response_code())?; - if 200 <= status_code && status_code < 300 { - Ok(data) - } else { - Err(Error::http(&format!( - "received a bad HTTP status code ({}) when requesting {}", - status_code, url - )) - .into()) - } -} - -fn with_url_context(url: &str, r: Result) -> Result -where - Result: failure::ResultExt, -{ - use failure::ResultExt; - r.with_context(|_| format!("when requesting {}", url)) -} - -fn transfer( - url: &str, - easy: &mut curl::easy::Easy, - data: &mut Vec, -) -> Result<(), failure::Error> { - let mut transfer = easy.transfer(); - with_url_context( - url, - transfer.write_function(|part| { - data.extend_from_slice(part); - Ok(part.len()) - }), - )?; - with_url_context(url, transfer.perform())?; - Ok(()) -} diff --git a/binary-install/src/path.rs b/binary-install/src/path.rs deleted file mode 100644 index 3f58ec2..0000000 --- a/binary-install/src/path.rs +++ /dev/null @@ -1,76 +0,0 @@ -use slog::Logger; -use std::fs; -use std::io; -use std::path::{Path, PathBuf}; -use target; -use which::which; - -/// Get the path for a crate's directory of locally-installed binaries. -/// -/// This does not check whether or ensure that the directory exists. -pub fn local_bin_dir(crate_path: &Path) -> PathBuf { - crate_path.join("bin") -} - -/// Ensure that the crate's directory for locally-installed binaries exists. -pub fn ensure_local_bin_dir(crate_path: &Path) -> io::Result<()> { - fs::create_dir_all(local_bin_dir(crate_path)) -} - -/// Get the path for where `bin` would be if we have a crate-local install for -/// it. -/// -/// This does *not* check whether there is a file at that path or not. -/// -/// This will automatically add the `.exe` extension for windows. -pub fn local_bin_path(crate_path: &Path, bin: &str) -> PathBuf { - let mut p = local_bin_dir(crate_path).join(bin); - if target::WINDOWS { - p.set_extension("exe"); - } - p -} - -/// Get the local (at `$CRATE/bin/$BIN`; preferred) or global (on `$PATH`) path -/// for the given binary. -/// -/// If this function returns `Some(path)`, then a file at that path exists (or -/// at least existed when we checked! In general, we aren't really worried about -/// racing with an uninstall of a tool that we rely on.) -pub fn bin_path(log: &Logger, crate_path: &Path, bin: &str) -> Option { - assert!(!bin.ends_with(".exe")); - debug!(log, "Searching for {} binary...", bin); - - // Return the path to the local binary, if it exists. - let local_path = |crate_path: &Path| -> Option { - let p = local_bin_path(crate_path, bin); - debug!(log, "Checking for local {} binary at {}", bin, p.display()); - if p.is_file() { - Some(p) - } else { - None - } - }; - - // Return the path to the global binary, if it exists. - let global_path = || -> Option { - debug!(log, "Looking for global {} binary on $PATH", bin); - if let Ok(p) = which(bin) { - Some(p) - } else { - None - } - }; - - local_path(crate_path) - .or_else(global_path) - .map(|p| { - let p = p.canonicalize().unwrap_or(p); - debug!(log, "Using {} binary at {}", bin, p.display()); - p - }) - .or_else(|| { - debug!(log, "Could not find {} binary.", bin); - None - }) -} diff --git a/binary-install/src/target.rs b/binary-install/src/target.rs deleted file mode 100644 index e3bfb9c..0000000 --- a/binary-install/src/target.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! Information about the target wasm-pack is currently being compiled for. -//! -//! That is, whether we are building wasm-pack for windows vs linux, and x86 vs -//! x86-64, etc. - -#![allow(missing_docs)] - -pub const WINDOWS: bool = cfg!(target_os = "windows"); diff --git a/binary-install/tests/path.rs b/binary-install/tests/path.rs deleted file mode 100644 index 08139ec..0000000 --- a/binary-install/tests/path.rs +++ /dev/null @@ -1,117 +0,0 @@ -extern crate binary_install; -#[macro_use] -extern crate slog; -extern crate slog_async; -extern crate slog_term; - -use binary_install::path::{bin_path, ensure_local_bin_dir, local_bin_path}; -use slog::Drain; -use std::env; -use std::fs; -use std::io; -use std::path::PathBuf; - -fn logger() -> slog::Logger { - let decorator = slog_term::TermDecorator::new().build(); - let drain = slog_term::FullFormat::new(decorator).build().fuse(); - let drain = slog_async::Async::new(drain).build().fuse(); - slog::Logger::root(drain, o!()) -} - -fn get_tests_bin_path() -> PathBuf { - let path = env::temp_dir(); - path.join("tests") -} - -#[test] -#[cfg(not(target_os = "windows"))] -fn get_local_bin_path_should_return_a_path() { - let crate_path = get_tests_bin_path(); - let expected_path = crate_path.join("bin/wasm-bindgen"); - - let result = local_bin_path(&crate_path, "wasm-bindgen"); - - assert_eq!(expected_path, result); -} - -#[test] -#[cfg(target_os = "windows")] -fn get_local_bin_path_should_return_with_exe_for_windows() { - let crate_path = get_tests_bin_path(); - - let expected_path = crate_path.join("bin/wasm-bindgen.exe"); - - let result = local_bin_path(crate_path, "wasm-bindgen"); - - assert_eq!(expected_path, result); -} - -#[test] -fn ensure_local_bin_dir_should_return_ok_for_folder_that_exists() { - let crate_path = get_tests_bin_path().join("bin2"); - - fs::create_dir_all(crate_path.to_owned()).unwrap(); - - let result = ensure_local_bin_dir(&crate_path); - - assert!(result.is_ok()); - - fs::remove_dir_all(crate_path).unwrap(); -} - -#[test] -fn ensure_local_bin_dir_should_create_folder_if_it_doesnt_exist() { - let crate_path = get_tests_bin_path().join("bin3"); - - // Make sure that the folder doesn't exist - // before we call ensure_local_bin_dir(); - let dir = fs::read_dir(crate_path.to_owned()); - let dir_error = dir.err().unwrap(); - assert_eq!(dir_error.kind(), io::ErrorKind::NotFound); - - let result = ensure_local_bin_dir(&crate_path); - - assert!(result.is_ok()); - - // Make sure that the directory actually exists. - let dir = fs::read_dir(crate_path.to_owned()); - assert!(dir.is_ok()); - - fs::remove_dir_all(crate_path).unwrap(); -} - -#[test] -fn bin_path_should_return_some_for_path_that_exists() { - let crate_path = get_tests_bin_path(); - let bin_file = "wasm-bindgen"; - let full_bin_path = crate_path.join("bin"); - let path_with_bin_file = full_bin_path.join(bin_file); - - fs::create_dir_all(full_bin_path.to_owned()).unwrap(); - fs::File::create(path_with_bin_file.to_owned()).unwrap(); - - let result = bin_path(&logger(), &crate_path, bin_file); - - assert!(result.is_some()); - assert_eq!(path_with_bin_file, result.unwrap()); - - fs::remove_dir_all(full_bin_path).unwrap(); -} - -#[test] -fn bin_path_should_return_none_for_path_that_does_not_exists() { - let crate_path = get_tests_bin_path(); - let bin_file = "wasm-binfile"; - let full_bin_path = crate_path.join("bin_path"); - let path_with_bin_file = full_bin_path.join(bin_file); - - // Make sure that the folder doesn't exist - // before we call bin_path(); - let file = fs::File::open(path_with_bin_file.to_owned()); - let file_error = file.err().unwrap(); - assert_eq!(file_error.kind(), io::ErrorKind::NotFound); - - let result = bin_path(&logger(), &crate_path, bin_file); - - assert!(result.is_none()); -} diff --git a/binary-install/tests/test.rs b/binary-install/tests/test.rs deleted file mode 100644 index 923688b..0000000 --- a/binary-install/tests/test.rs +++ /dev/null @@ -1,168 +0,0 @@ -extern crate binary_install; -extern crate curl; -extern crate failure; -extern crate flate2; -extern crate tar; - -use binary_install::{error::Error, install_binaries_from_targz_at_url}; -use flate2::write::GzEncoder; -use flate2::Compression; -use std::env; -use std::fs::{File, OpenOptions}; -use std::io::{self, Read, Write}; -use std::net::TcpListener; -use std::path::Path; -use std::thread; - -const SERVER_HOST: &'static str = "localhost"; - -fn start_server(port: u32, tarball: Option>) -> thread::JoinHandle { - thread::spawn(move || { - let listener = TcpListener::bind(format!("{}:{}", SERVER_HOST, port)).unwrap(); - - for stream in listener.incoming() { - let mut stream = stream.unwrap(); - - let mut buffer = [0; 512]; - - stream.read(&mut buffer).unwrap(); - - let response = "HTTP/1.1 200 OK\r\n\r\n"; - - stream.write(response.as_bytes()).unwrap(); - - match tarball.to_owned() { - Some(tar) => { - stream.write(tar.as_ref()).unwrap(); - } - None => {} - } - - stream.flush().unwrap(); - } - listener - }) -} - -fn create_tarball(binary_name: &str) -> Result, io::Error> { - let temp_dir = env::temp_dir(); - let tar = OpenOptions::new() - .create(true) - .read(true) - .write(true) - .open(temp_dir.join("foo.tar.gz"))?; - - let mut file = OpenOptions::new() - .create(true) - .read(true) - .write(true) - .open(temp_dir.join(binary_name))?; - - let mut encoder = GzEncoder::new(tar, Compression::default()); - { - let mut archive = tar::Builder::new(&mut encoder); - archive.append_file(binary_name, &mut file)?; - } - - let mut contents = vec![]; - - encoder.finish()?; - - File::open(temp_dir.join("foo.tar.gz"))?.read_to_end(&mut contents)?; - - Ok(contents) -} - -#[test] -fn install_binaries_from_targz_at_url_should_return_http_error_for_bad_url() { - let crate_path = Path::new(""); - let url = ""; - let binaries = vec![""]; - - let result = install_binaries_from_targz_at_url(crate_path, url, binaries); - assert!(result.is_err()); - - let err = result.err().unwrap(); - let err = err.downcast_ref::().unwrap(); - - let expected_message = format!("when requesting {}", url); - - match err { - Error::Http { message } => assert_eq!(&expected_message, message), - _ => panic!("Wrong error returned"), - } -} - -#[test] -fn install_binaries_from_targz_at_url_should_return_archive_error_when_tarball_is_missing() { - let server_port = 7878; - let url = format!("http://{}:{}", SERVER_HOST, server_port); - let crate_path = Path::new(""); - let binaries = vec![""]; - - // Spin up a local TcpListener. - start_server(server_port, None); - - let result = install_binaries_from_targz_at_url(crate_path, &url, binaries); - assert!(result.is_err()); - - let err = result.err().unwrap(); - let err = err.downcast_ref::().unwrap(); - - let expected_message = format!( - "Invalid tarball at {}. Inner error: failed to fill whole buffer", - url - ); - - match err { - Error::Archive { message } => assert_eq!(&expected_message, message), - _ => panic!("Wrong error returned"), - } -} - -#[test] -fn install_binaries_from_targz_at_url_should_return_archive_error_when_tarball_does_not_include_all_files( -) { - let server_port = 7879; - let url = format!("http://{}:{}", SERVER_HOST, server_port); - let crate_path = Path::new(""); - let binaries = vec!["wasm-pack"]; - - // Create a temporary tarball. - let tarball = create_tarball("foo.txt").ok(); - // Spin up a local TcpListener. - start_server(server_port, tarball); - - let result = install_binaries_from_targz_at_url(crate_path, &url, binaries); - assert!(result.is_err()); - - let err = result.err().unwrap(); - let err = err.downcast_ref::().unwrap(); - - let expected_message = format!( - "the tarball at {} was missing expected executables: {}", - url, "wasm-pack" - ); - - match err { - Error::Archive { message } => assert_eq!(&expected_message, message), - _ => panic!("Wrong error returned"), - } -} - -#[test] -fn install_binaries_from_targz_at_url_should_return_ok_if_binary_is_found() { - let server_port = 7880; - let url = format!("http://{}:{}", SERVER_HOST, server_port); - let binary_name = "wasm-pack"; - let crate_path = Path::new(""); - let binaries = vec![binary_name]; - - // Create a temporary tarball. - let tarball = create_tarball(binary_name).ok(); - // Spin up a local TcpListener. - start_server(server_port, tarball); - - let result = install_binaries_from_targz_at_url(crate_path, &url, binaries); - assert!(result.is_ok()); -} From 50e472de05ec29abd5e1a7ce3463308426a5aa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 6 Nov 2018 21:15:42 +0100 Subject: [PATCH 14/17] chore: Remove unused crates and error variants --- Cargo.lock | 11 -------- Cargo.toml | 11 -------- binary-install/Cargo.toml | 4 --- binary-install/src/lib.rs | 5 +--- src/error.rs | 54 --------------------------------------- src/lib.rs | 9 +------ 6 files changed, 2 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc98424..ed8b708 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,11 +77,7 @@ dependencies = [ "flate2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tar 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", - "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1066,11 +1062,7 @@ dependencies = [ "binary-install 0.1.0", "cargo_metadata 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "curl 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", - "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (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.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1079,16 +1071,13 @@ dependencies = [ "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", - "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-term 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "tar 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f3b8538..f3d1659 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,19 +9,11 @@ readme = "README.md" categories = ["wasm"] documentation = "https://rustwasm.github.io/wasm-pack/" -[workspace] -members = ["binary-install"] -exclude = ["target"] - [dependencies] atty = "0.2.11" cargo_metadata = "0.6.0" console = "0.6.1" -curl = "0.4.13" -dirs = "1.0.4" failure = "0.1.2" -flate2 = "1.0.2" -hex = "0.3" human-panic = "1.0.1" indicatif = "0.9.0" lazy_static = "1.1.0" @@ -30,15 +22,12 @@ parking_lot = "0.6" serde = "1.0.74" serde_derive = "1.0.74" serde_json = "1.0.26" -siphasher = "0.2.3" slog = "2.3" slog-term = "2.4" slog-async = "2.3" structopt = "0.2" -tar = "0.4.16" toml = "0.4" which = "2.0.0" -zip = "0.4.2" binary-install = { version = "0.1.0", path = "./binary-install" } [dev-dependencies] diff --git a/binary-install/Cargo.toml b/binary-install/Cargo.toml index 7f93e9c..c78b0dd 100644 --- a/binary-install/Cargo.toml +++ b/binary-install/Cargo.toml @@ -9,9 +9,5 @@ failure = "0.1.2" flate2 = "1.0.2" hex = "0.3" siphasher = "0.2.3" -slog = "2.3" -slog-term = "2.4" -slog-async = "2.3" tar = "0.4.16" -which = "2.0.0" zip = "0.4.2" diff --git a/binary-install/src/lib.rs b/binary-install/src/lib.rs index 89bf4f0..dcef39f 100644 --- a/binary-install/src/lib.rs +++ b/binary-install/src/lib.rs @@ -3,14 +3,11 @@ extern crate curl; #[macro_use] extern crate failure; -extern crate flate2; -#[macro_use] -extern crate slog; extern crate dirs; +extern crate flate2; extern crate hex; extern crate siphasher; extern crate tar; -extern crate which; extern crate zip; use failure::{Error, ResultExt}; diff --git a/src/error.rs b/src/error.rs index 1c2f2c4..1286154 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,11 +1,9 @@ //! Code related to error handling for wasm-pack -use curl; use serde_json; use std::borrow::Cow; use std::io; use std::process::ExitStatus; use toml; -use zip; /// Errors that can potentially occur in `wasm-pack`. #[derive(Debug, Fail)] @@ -22,14 +20,6 @@ pub enum Error { #[fail(display = "{}", _0)] SerdeToml(#[cause] toml::de::Error), - #[fail(display = "{}", _0)] - /// A curl error. - Curl(#[cause] curl::Error), - - #[fail(display = "{}", _0)] - /// An error handling zip archives. - Zip(#[cause] zip::result::ZipError), - #[fail(display = "{}", _0)] /// An error in parsing your rustc version. RustcMissing { @@ -73,13 +63,6 @@ pub enum Error { message: String, }, - #[fail(display = "{}", message)] - /// An error related to an archive that we downloaded. - Archive { - /// Error message. - message: String, - }, - #[fail(display = "{}", message)] /// Error when some operation or feature is unsupported for the current /// target or environment. @@ -87,13 +70,6 @@ pub enum Error { /// Error message. message: String, }, - - #[fail(display = "{}", message)] - /// Error related to some HTTP request. - Http { - /// Error message. - message: String, - }, } impl Error { @@ -114,13 +90,6 @@ impl Error { } } - /// Construct an archive error. - pub fn archive(message: &str) -> Self { - Error::Archive { - message: message.to_string(), - } - } - /// Construct an unsupported error. pub fn unsupported(message: &str) -> Self { Error::Unsupported { @@ -128,13 +97,6 @@ impl Error { } } - /// Construct an http error. - pub fn http(message: &str) -> Self { - Error::Http { - message: message.to_string(), - } - } - /// Construct a rustc version error. pub fn rustc_version_error(message: &str, local_version: &str) -> Self { Error::RustcVersion { @@ -149,7 +111,6 @@ impl Error { Error::Io(_) => "There was an I/O error. Details:\n\n", Error::SerdeJson(_) => "There was an JSON error. Details:\n\n", Error::SerdeToml(_) => "There was an TOML error. Details:\n\n", - Error::Zip(_) => "There was an error handling zip files. Details:\n\n", Error::RustcMissing { message: _, } => "We can't figure out what your Rust version is- which means you might not have Rust installed. Please install Rust version 1.30.0 or higher.", @@ -169,10 +130,7 @@ impl Error { Error::PkgNotFound { message: _, } => "Unable to find the 'pkg' directory at the path, set the path as the parent of the 'pkg' directory \n\n", - Error::Curl(_) => "There was an error making an HTTP request with curl. Details:\n\n", - Error::Archive {..} => "There was an error related to an archive file. Details:\n\n", Error::Unsupported {..} => "There was an unsupported operation attempted. Details:\n\n", - Error::Http {..} => "There wasn an HTTP error. Details:\n\n", }.to_string() } } @@ -183,24 +141,12 @@ impl From for Error { } } -impl From for Error { - fn from(e: curl::Error) -> Self { - Error::Curl(e) - } -} - impl From for Error { fn from(e: serde_json::Error) -> Self { Error::SerdeJson(e) } } -impl From for Error { - fn from(e: zip::result::ZipError) -> Self { - Error::Zip(e) - } -} - impl From for Error { fn from(e: toml::de::Error) -> Self { Error::SerdeToml(e) diff --git a/src/lib.rs b/src/lib.rs index 23280bf..2d6d296 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,20 +4,16 @@ extern crate cargo_metadata; extern crate console; -extern crate curl; -extern crate dirs; #[macro_use] extern crate failure; -extern crate flate2; -extern crate hex; extern crate indicatif; +extern crate which; #[macro_use] extern crate lazy_static; extern crate parking_lot; #[macro_use] extern crate serde_derive; extern crate serde_json; -extern crate siphasher; #[macro_use] extern crate structopt; #[macro_use] @@ -25,10 +21,7 @@ extern crate slog; extern crate binary_install; extern crate slog_async; extern crate slog_term; -extern crate tar; extern crate toml; -extern crate which; -extern crate zip; pub mod bindgen; pub mod build; From 489d3e84c2f53f2d4f8150a8c0c4f5835bb74f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Tue, 6 Nov 2018 21:21:14 +0100 Subject: [PATCH 15/17] refactor: Rename binary-install to wasm-pack-binary-install --- Cargo.lock | 30 +++++++++++++++--------------- Cargo.toml | 2 +- binary-install/Cargo.toml | 2 +- src/bindgen.rs | 2 +- src/command/build.rs | 2 +- src/command/test.rs | 2 +- src/lib.rs | 2 +- src/test/webdriver.rs | 2 +- tests/all/bindgen.rs | 2 +- tests/all/main.rs | 2 +- tests/all/utils/fixture.rs | 2 +- tests/all/webdriver.rs | 2 +- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed8b708..8b5c16c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,20 +67,6 @@ dependencies = [ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "binary-install" -version = "0.1.0" -dependencies = [ - "curl 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", - "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tar 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", - "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "bitflags" version = "1.0.4" @@ -1059,7 +1045,6 @@ name = "wasm-pack" version = "0.5.1" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "binary-install 0.1.0", "cargo_metadata 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "console 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1077,9 +1062,24 @@ dependencies = [ "structopt 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-pack-binary-install 0.1.0", "which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "wasm-pack-binary-install" +version = "0.1.0" +dependencies = [ + "curl 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tar 0.4.17 (registry+https://github.com/rust-lang/crates.io-index)", + "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "which" version = "2.0.0" diff --git a/Cargo.toml b/Cargo.toml index f3d1659..dd1b560 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ slog-async = "2.3" structopt = "0.2" toml = "0.4" which = "2.0.0" -binary-install = { version = "0.1.0", path = "./binary-install" } +wasm-pack-binary-install = { version = "0.1.0", path = "./binary-install" } [dev-dependencies] tempfile = "3" diff --git a/binary-install/Cargo.toml b/binary-install/Cargo.toml index c78b0dd..acdd991 100644 --- a/binary-install/Cargo.toml +++ b/binary-install/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "binary-install" +name = "wasm-pack-binary-install" version = "0.1.0" [dependencies] diff --git a/src/bindgen.rs b/src/bindgen.rs index 6b8b1e7..15be7ec 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -1,6 +1,5 @@ //! Functionality related to installing and running `wasm-bindgen`. -use binary_install::{Cache, Download}; use child; use emoji; use failure::{self, ResultExt}; @@ -11,6 +10,7 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; use target; +use wasm_pack_binary_install::{Cache, Download}; use which::which; use PBAR; diff --git a/src/command/build.rs b/src/command/build.rs index 123e043..7852d8a 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -1,6 +1,5 @@ //! Implementation of the `wasm-pack build` command. -use binary_install::{Cache, Download}; use bindgen; use build; use command::utils::{create_pkg_dir, set_crate_path}; @@ -15,6 +14,7 @@ use slog::Logger; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; +use wasm_pack_binary_install::{Cache, Download}; use PBAR; /// Everything required to configure and run the `wasm-pack init` command. diff --git a/src/command/test.rs b/src/command/test.rs index 5a434e9..bd8d77a 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -1,7 +1,6 @@ //! Implementation of the `wasm-pack test` command. use super::build::BuildMode; -use binary_install::Cache; use bindgen; use build; use command::utils::set_crate_path; @@ -16,6 +15,7 @@ use slog::Logger; use std::path::PathBuf; use std::time::Instant; use test::{self, webdriver}; +use wasm_pack_binary_install::Cache; use PBAR; #[derive(Debug, Default, StructOpt)] diff --git a/src/lib.rs b/src/lib.rs index 2d6d296..d7c641b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,10 +18,10 @@ extern crate serde_json; extern crate structopt; #[macro_use] extern crate slog; -extern crate binary_install; extern crate slog_async; extern crate slog_term; extern crate toml; +extern crate wasm_pack_binary_install; pub mod bindgen; pub mod build; diff --git a/src/test/webdriver.rs b/src/test/webdriver.rs index 9fc3c56..9709c40 100644 --- a/src/test/webdriver.rs +++ b/src/test/webdriver.rs @@ -1,10 +1,10 @@ //! Getting WebDriver client binaries. -use binary_install::Cache; use command::build::BuildMode; use failure; use std::path::PathBuf; use target; +use wasm_pack_binary_install::Cache; /// Get the path to an existing `chromedriver`, or install it if no existing /// binary is found. diff --git a/tests/all/bindgen.rs b/tests/all/bindgen.rs index 032d48b..5f6b481 100644 --- a/tests/all/bindgen.rs +++ b/tests/all/bindgen.rs @@ -1,6 +1,6 @@ -use binary_install::Cache; use tempfile; use wasm_pack::bindgen; +use wasm_pack_binary_install::Cache; #[test] #[cfg(any( diff --git a/tests/all/main.rs b/tests/all/main.rs index c41b090..c79c4f1 100644 --- a/tests/all/main.rs +++ b/tests/all/main.rs @@ -6,10 +6,10 @@ extern crate serde_derive; extern crate serde_json; #[macro_use] extern crate slog; -extern crate binary_install; extern crate structopt; extern crate tempfile; extern crate wasm_pack; +extern crate wasm_pack_binary_install; mod bindgen; mod build; diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index 7c4dfe4..b361865 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -1,5 +1,4 @@ use super::logger::null_logger; -use binary_install::Cache; use std::env; use std::fs; use std::mem::ManuallyDrop; @@ -9,6 +8,7 @@ use std::sync::{MutexGuard, Once, ONCE_INIT}; use std::thread; use tempfile::TempDir; use wasm_pack; +use wasm_pack_binary_install::Cache; /// A test fixture in a temporary directory. pub struct Fixture { diff --git a/tests/all/webdriver.rs b/tests/all/webdriver.rs index d5e8cf6..c0bbaa5 100644 --- a/tests/all/webdriver.rs +++ b/tests/all/webdriver.rs @@ -1,6 +1,6 @@ -use binary_install::Cache; use utils::fixture; use wasm_pack::test::webdriver; +use wasm_pack_binary_install::Cache; #[test] #[cfg(any( From b47dfa3009efe802f3324fea0a414cc73344b8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Wed, 7 Nov 2018 21:10:40 +0100 Subject: [PATCH 16/17] chore: Run latest rustfmt --- tests/all/build.rs | 28 ++++++-------- tests/all/lockfile.rs | 18 +++------ tests/all/manifest.rs | 86 +++++++++++++++++++++++++------------------ 3 files changed, 67 insertions(+), 65 deletions(-) diff --git a/tests/all/build.rs b/tests/all/build.rs index 91a15e0..7cb2136 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -10,17 +10,17 @@ fn build_in_non_crate_directory_doesnt_panic() { "wasm-pack", "build", &fixture.path.display().to_string(), - ]) - .unwrap(); + ]).unwrap(); let result = fixture.run(cli.cmd); assert!( result.is_err(), "running wasm-pack in a non-crate directory should fail, but it should not panic" ); let err = result.unwrap_err(); - assert!(err - .iter_chain() - .any(|e| e.to_string().contains("missing a `Cargo.toml`"))); + assert!( + err.iter_chain() + .any(|e| e.to_string().contains("missing a `Cargo.toml`")) + ); } #[test] @@ -31,8 +31,7 @@ fn it_should_build_js_hello_world_example() { "wasm-pack", "build", &fixture.path.display().to_string(), - ]) - .unwrap(); + ]).unwrap(); fixture.run(cli.cmd).unwrap(); } @@ -46,8 +45,7 @@ fn it_should_build_crates_in_a_workspace() { [workspace] members = ["blah"] "#, - ) - .file( + ).file( Path::new("blah").join("Cargo.toml"), r#" [package] @@ -64,8 +62,7 @@ fn it_should_build_crates_in_a_workspace() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ) - .file( + ).file( Path::new("blah").join("src").join("lib.rs"), r#" extern crate wasm_bindgen; @@ -80,8 +77,7 @@ fn it_should_build_crates_in_a_workspace() { "wasm-pack", "build", &fixture.path.join("blah").display().to_string(), - ]) - .unwrap(); + ]).unwrap(); fixture.run(cli.cmd).unwrap(); } @@ -105,8 +101,7 @@ fn renamed_crate_name_works() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ) - .file( + ).file( "src/lib.rs", r#" extern crate wasm_bindgen; @@ -121,7 +116,6 @@ fn renamed_crate_name_works() { "wasm-pack", "build", &fixture.path.display().to_string(), - ]) - .unwrap(); + ]).unwrap(); fixture.run(cli.cmd).unwrap(); } diff --git a/tests/all/lockfile.rs b/tests/all/lockfile.rs index 01876ba..4c1fb36 100644 --- a/tests/all/lockfile.rs +++ b/tests/all/lockfile.rs @@ -30,8 +30,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { [workspace] members = ["./blah"] "#, - ) - .file( + ).file( "blah/Cargo.toml", r#" [package] @@ -48,8 +47,7 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ) - .file( + ).file( "blah/src/lib.rs", r#" extern crate wasm_bindgen; @@ -75,8 +73,7 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { [workspace] members = ["./parent", "./child"] "#, - ) - .file( + ).file( "child/Cargo.toml", r#" [package] @@ -93,8 +90,7 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ) - .file( + ).file( "child/src/lib.rs", r#" extern crate wasm_bindgen; @@ -103,8 +99,7 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { #[wasm_bindgen] pub fn hello() -> u32 { 42 } "#, - ) - .file( + ).file( "parent/Cargo.toml", r#" [package] @@ -118,8 +113,7 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { [lib] crate-type = ["cdylib"] "#, - ) - .file( + ).file( "parent/src/lib.rs", r#" // Just re-export all of `child`. diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 2c60f78..9734f2c 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -65,9 +65,11 @@ fn it_creates_a_package_json_default_path() { 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(); - assert!(crate_data - .write_package_json(&out_dir, &None, false, "", &step) - .is_ok()); + assert!( + crate_data + .write_package_json(&out_dir, &None, false, "", &step) + .is_ok() + ); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -88,9 +90,9 @@ fn it_creates_a_package_json_default_path() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -101,9 +103,11 @@ fn it_creates_a_package_json_provided_path() { 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(); - assert!(crate_data - .write_package_json(&out_dir, &None, false, "", &step) - .is_ok()); + assert!( + crate_data + .write_package_json(&out_dir, &None, false, "", &step) + .is_ok() + ); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -117,9 +121,9 @@ fn it_creates_a_package_json_provided_path() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -130,9 +134,11 @@ fn it_creates_a_package_json_provided_path_with_scope() { 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(); - assert!(crate_data - .write_package_json(&out_dir, &Some("test".to_string()), false, "", &step) - .is_ok()); + assert!( + crate_data + .write_package_json(&out_dir, &Some("test".to_string()), false, "", &step) + .is_ok() + ); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -146,9 +152,9 @@ fn it_creates_a_package_json_provided_path_with_scope() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -159,9 +165,11 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { 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(); - assert!(crate_data - .write_package_json(&out_dir, &None, false, "nodejs", &step) - .is_ok()); + assert!( + crate_data + .write_package_json(&out_dir, &None, false, "nodejs", &step) + .is_ok() + ); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -182,9 +190,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -195,9 +203,11 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { 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(); - assert!(crate_data - .write_package_json(&out_dir, &None, false, "no-modules", &step) - .is_ok()); + assert!( + crate_data + .write_package_json(&out_dir, &None, false, "no-modules", &step) + .is_ok() + ); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -217,9 +227,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { "js_hello_world.js", "js_hello_world.d.ts", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -230,9 +240,11 @@ fn it_creates_a_pkg_json_in_out_dir() { 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(); - assert!(crate_data - .write_package_json(&out_dir, &None, false, "", &step) - .is_ok()); + assert!( + crate_data + .write_package_json(&out_dir, &None, false, "", &step) + .is_ok() + ); let package_json_path = &fixture.path.join(&out_dir).join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -246,9 +258,11 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { 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(); - assert!(crate_data - .write_package_json(&out_dir, &None, true, "", &step) - .is_ok()); + assert!( + crate_data + .write_package_json(&out_dir, &None, true, "", &step) + .is_ok() + ); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); From 99b9602d3102f350152e6f6c5e7e3fb29ed2c0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Wed, 7 Nov 2018 21:43:50 +0100 Subject: [PATCH 17/17] chore: Run latest rustfmt --- src/bindgen.rs | 6 ++- tests/all/bindgen.rs | 8 ++-- tests/all/build.rs | 28 ++++++++----- tests/all/lockfile.rs | 18 +++++--- tests/all/manifest.rs | 86 ++++++++++++++++---------------------- tests/all/test.rs | 6 ++- tests/all/utils/fixture.rs | 6 ++- 7 files changed, 80 insertions(+), 78 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index 15be7ec..951a104 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -207,6 +207,8 @@ fn wasm_bindgen_version_check(bindgen_path: &PathBuf, dep_version: &str, log: &L dep_version ); v == dep_version - }).unwrap_or(false) - }).unwrap_or(false) + }) + .unwrap_or(false) + }) + .unwrap_or(false) } diff --git a/tests/all/bindgen.rs b/tests/all/bindgen.rs index 5f6b481..e1077c5 100644 --- a/tests/all/bindgen.rs +++ b/tests/all/bindgen.rs @@ -31,9 +31,7 @@ fn downloading_prebuilt_wasm_bindgen_handles_http_errors() { let error = result.err().unwrap(); assert!(error.iter_chain().any(|e| e.to_string().contains("404"))); - assert!( - error - .iter_chain() - .any(|e| e.to_string().contains(bad_version)) - ); + assert!(error + .iter_chain() + .any(|e| e.to_string().contains(bad_version))); } diff --git a/tests/all/build.rs b/tests/all/build.rs index 7cb2136..91a15e0 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -10,17 +10,17 @@ fn build_in_non_crate_directory_doesnt_panic() { "wasm-pack", "build", &fixture.path.display().to_string(), - ]).unwrap(); + ]) + .unwrap(); let result = fixture.run(cli.cmd); assert!( result.is_err(), "running wasm-pack in a non-crate directory should fail, but it should not panic" ); let err = result.unwrap_err(); - assert!( - err.iter_chain() - .any(|e| e.to_string().contains("missing a `Cargo.toml`")) - ); + assert!(err + .iter_chain() + .any(|e| e.to_string().contains("missing a `Cargo.toml`"))); } #[test] @@ -31,7 +31,8 @@ fn it_should_build_js_hello_world_example() { "wasm-pack", "build", &fixture.path.display().to_string(), - ]).unwrap(); + ]) + .unwrap(); fixture.run(cli.cmd).unwrap(); } @@ -45,7 +46,8 @@ fn it_should_build_crates_in_a_workspace() { [workspace] members = ["blah"] "#, - ).file( + ) + .file( Path::new("blah").join("Cargo.toml"), r#" [package] @@ -62,7 +64,8 @@ fn it_should_build_crates_in_a_workspace() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ).file( + ) + .file( Path::new("blah").join("src").join("lib.rs"), r#" extern crate wasm_bindgen; @@ -77,7 +80,8 @@ fn it_should_build_crates_in_a_workspace() { "wasm-pack", "build", &fixture.path.join("blah").display().to_string(), - ]).unwrap(); + ]) + .unwrap(); fixture.run(cli.cmd).unwrap(); } @@ -101,7 +105,8 @@ fn renamed_crate_name_works() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ).file( + ) + .file( "src/lib.rs", r#" extern crate wasm_bindgen; @@ -116,6 +121,7 @@ fn renamed_crate_name_works() { "wasm-pack", "build", &fixture.path.display().to_string(), - ]).unwrap(); + ]) + .unwrap(); fixture.run(cli.cmd).unwrap(); } diff --git a/tests/all/lockfile.rs b/tests/all/lockfile.rs index 4c1fb36..01876ba 100644 --- a/tests/all/lockfile.rs +++ b/tests/all/lockfile.rs @@ -30,7 +30,8 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { [workspace] members = ["./blah"] "#, - ).file( + ) + .file( "blah/Cargo.toml", r#" [package] @@ -47,7 +48,8 @@ fn it_gets_wasm_bindgen_version_in_crate_inside_workspace() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ).file( + ) + .file( "blah/src/lib.rs", r#" extern crate wasm_bindgen; @@ -73,7 +75,8 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { [workspace] members = ["./parent", "./child"] "#, - ).file( + ) + .file( "child/Cargo.toml", r#" [package] @@ -90,7 +93,8 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { [dependencies] wasm-bindgen = "=0.2.21" "#, - ).file( + ) + .file( "child/src/lib.rs", r#" extern crate wasm_bindgen; @@ -99,7 +103,8 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { #[wasm_bindgen] pub fn hello() -> u32 { 42 } "#, - ).file( + ) + .file( "parent/Cargo.toml", r#" [package] @@ -113,7 +118,8 @@ fn it_gets_wasm_bindgen_version_from_dependencies() { [lib] crate-type = ["cdylib"] "#, - ).file( + ) + .file( "parent/src/lib.rs", r#" // Just re-export all of `child`. diff --git a/tests/all/manifest.rs b/tests/all/manifest.rs index 9734f2c..2c60f78 100644 --- a/tests/all/manifest.rs +++ b/tests/all/manifest.rs @@ -65,11 +65,9 @@ fn it_creates_a_package_json_default_path() { 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(); - assert!( - crate_data - .write_package_json(&out_dir, &None, false, "", &step) - .is_ok() - ); + assert!(crate_data + .write_package_json(&out_dir, &None, false, "", &step) + .is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -90,9 +88,9 @@ fn it_creates_a_package_json_default_path() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -103,11 +101,9 @@ fn it_creates_a_package_json_provided_path() { 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(); - assert!( - crate_data - .write_package_json(&out_dir, &None, false, "", &step) - .is_ok() - ); + assert!(crate_data + .write_package_json(&out_dir, &None, false, "", &step) + .is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -121,9 +117,9 @@ fn it_creates_a_package_json_provided_path() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -134,11 +130,9 @@ fn it_creates_a_package_json_provided_path_with_scope() { 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(); - assert!( - crate_data - .write_package_json(&out_dir, &Some("test".to_string()), false, "", &step) - .is_ok() - ); + assert!(crate_data + .write_package_json(&out_dir, &Some("test".to_string()), false, "", &step) + .is_ok()); let package_json_path = &fixture.path.join("pkg").join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -152,9 +146,9 @@ fn it_creates_a_package_json_provided_path_with_scope() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -165,11 +159,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { 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(); - assert!( - crate_data - .write_package_json(&out_dir, &None, false, "nodejs", &step) - .is_ok() - ); + assert!(crate_data + .write_package_json(&out_dir, &None, false, "nodejs", &step) + .is_ok()); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -190,9 +182,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() { "js_hello_world.d.ts", "js_hello_world.js", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -203,11 +195,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { 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(); - assert!( - crate_data - .write_package_json(&out_dir, &None, false, "no-modules", &step) - .is_ok() - ); + assert!(crate_data + .write_package_json(&out_dir, &None, false, "no-modules", &step) + .is_ok()); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); @@ -227,9 +217,9 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() { "js_hello_world.js", "js_hello_world.d.ts", ] - .iter() - .map(|&s| String::from(s)) - .collect(); + .iter() + .map(|&s| String::from(s)) + .collect(); assert_eq!(actual_files, expected_files); } @@ -240,11 +230,9 @@ fn it_creates_a_pkg_json_in_out_dir() { 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(); - assert!( - crate_data - .write_package_json(&out_dir, &None, false, "", &step) - .is_ok() - ); + assert!(crate_data + .write_package_json(&out_dir, &None, false, "", &step) + .is_ok()); let package_json_path = &fixture.path.join(&out_dir).join("package.json"); fs::metadata(package_json_path).unwrap(); @@ -258,11 +246,9 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() { 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(); - assert!( - crate_data - .write_package_json(&out_dir, &None, true, "", &step) - .is_ok() - ); + assert!(crate_data + .write_package_json(&out_dir, &None, true, "", &step) + .is_ok()); let package_json_path = &out_dir.join("package.json"); fs::metadata(package_json_path).unwrap(); utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap(); diff --git a/tests/all/test.rs b/tests/all/test.rs index 323cc2e..718f275 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -200,7 +200,8 @@ fn complains_about_missing_wasm_bindgen_test_dependency() { [dev-dependencies] # no wasm-bindgen-test dep here! "#, - ).hello_world_src_lib() + ) + .hello_world_src_lib() .install_local_wasm_bindgen(); let cmd = Command::Test(test::TestOptions { @@ -265,7 +266,8 @@ fn renamed_crate_name_works() { [dev-dependencies] wasm-bindgen-test = "=0.2.21" "#, - ).file( + ) + .file( "src/lib.rs", r#" extern crate wasm_bindgen; diff --git a/tests/all/utils/fixture.rs b/tests/all/utils/fixture.rs index b361865..b916c6b 100644 --- a/tests/all/utils/fixture.rs +++ b/tests/all/utils/fixture.rs @@ -346,7 +346,8 @@ pub fn wbg_test_diff_versions() -> Fixture { # wasm-bindgen-test at 0.2.19, and everything should still work. wasm-bindgen-test = "0.2.19" "#, - ).file( + ) + .file( "src/lib.rs", r#" extern crate wasm_bindgen; @@ -355,7 +356,8 @@ pub fn wbg_test_diff_versions() -> Fixture { #[wasm_bindgen] pub fn one() -> u32 { 1 } "#, - ).file( + ) + .file( "tests/node.rs", r#" extern crate wbg_test_diff_versions;