From d3f8264ef73ef634f951964dbc745d221de3d218 Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Mon, 24 Sep 2018 19:43:38 -0400 Subject: [PATCH 1/2] feat(buildmode): allow --mode force to skip rustc check --- src/command/build.rs | 11 +++++++++++ src/command/test.rs | 24 ++++++++++++++++++++++++ src/test/webdriver.rs | 2 ++ tests/all/bindgen.rs | 24 ++++++++++++++---------- tests/all/test.rs | 30 +++++++++++++++++------------- tests/all/webdriver.rs | 28 ++++++++++++++++------------ 6 files changed, 84 insertions(+), 35 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index f46d211..9e81c65 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -38,6 +38,8 @@ pub enum BuildMode { /// Don't install tools like `wasm-bindgen`, just use the global /// environment's existing versions to do builds. Noinstall, + /// Skip the rustc version check + Force, } impl Default for BuildMode { @@ -52,6 +54,7 @@ impl FromStr for BuildMode { match s { "no-install" => Ok(BuildMode::Noinstall), "normal" => Ok(BuildMode::Normal), + "force" => Ok(BuildMode::Force), _ => Error::crate_config(&format!("Unknown build mode: {}", s)).map(|_| unreachable!()), } } @@ -175,6 +178,13 @@ impl Build { step_copy_readme, step_run_wasm_bindgen ], + BuildMode::Force => steps![ + step_build_wasm, + step_create_dir, + step_create_json, + step_copy_readme, + step_run_wasm_bindgen + ], } } @@ -255,6 +265,7 @@ impl Build { info!(&log, "Installing wasm-bindgen-cli..."); let install_permitted = match self.mode { BuildMode::Normal => true, + BuildMode::Force => true, BuildMode::Noinstall => false, }; bindgen::install_wasm_bindgen( diff --git a/src/command/test.rs b/src/command/test.rs index ed803dc..6ad3e7a 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -185,6 +185,7 @@ impl Test { } match self.mode { BuildMode::Normal => steps![ + step_check_rustc_version, step_check_crate_config, step_add_wasm_target, step_build_tests, @@ -197,6 +198,18 @@ impl Test { step_get_safaridriver if self.safari && self.safaridriver.is_none(), step_test_safari if self.safari, ], + BuildMode::Force => steps![ + step_add_wasm_target, + step_build_tests, + step_install_wasm_bindgen, + step_test_node if self.node, + step_get_chromedriver if self.chrome && self.chromedriver.is_none(), + step_test_chrome if self.chrome, + step_get_geckodriver if self.firefox && self.geckodriver.is_none(), + step_test_firefox if self.firefox, + step_get_safaridriver if self.safari && self.safaridriver.is_none(), + step_test_safari if self.safari, + ], BuildMode::Noinstall => steps![ step_check_crate_config, step_build_tests, @@ -212,6 +225,13 @@ impl Test { } } + fn step_check_rustc_version(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { + info!(log, "Checking rustc version..."); + let _ = build::check_rustc_version(step)?; + info!(log, "Rustc version is correct."); + Ok(()) + } + fn step_check_crate_config(&mut self, step: &Step, log: &Logger) -> Result<(), Error> { info!(log, "Checking crate configuration..."); manifest::check_crate_config(&self.crate_path, step)?; @@ -263,6 +283,10 @@ impl Test { info!(&log, "Ensuring wasm-bindgen-cli is installed..."); true } + BuildMode::Force => { + info!(&log, "Ensuring wasm-bindgen-cli is installed..."); + true + } BuildMode::Noinstall => { info!(&log, "Searching for existing wasm-bindgen-cli install..."); false diff --git a/src/test/webdriver.rs b/src/test/webdriver.rs index f507775..5668f6a 100644 --- a/src/test/webdriver.rs +++ b/src/test/webdriver.rs @@ -19,6 +19,7 @@ pub fn get_or_install_chromedriver( match (mode, bin_path(log, crate_path, "chromedriver")) { (_, Some(path)) => Ok(path), (BuildMode::Normal, None) => install_chromedriver(crate_path), + (BuildMode::Force, None) => install_chromedriver(crate_path), (BuildMode::Noinstall, None) => Error::crate_config( "No crate-local `chromedriver` binary found, and could not find a global \ `chromedriver` on the `$PATH`. Not installing `chromedriver` because of noinstall \ @@ -69,6 +70,7 @@ pub fn get_or_install_geckodriver( match (mode, bin_path(log, crate_path, "geckodriver")) { (_, Some(path)) => Ok(path), (BuildMode::Normal, None) => install_geckodriver(crate_path), + (BuildMode::Force, None) => install_geckodriver(crate_path), (BuildMode::Noinstall, None) => Error::crate_config( "No crate-local `geckodriver` binary found, and could not find a global `geckodriver` \ on the `$PATH`. Not installing `geckodriver` because of noinstall mode.", diff --git a/tests/all/bindgen.rs b/tests/all/bindgen.rs index b79d58c..9066e95 100644 --- a/tests/all/bindgen.rs +++ b/tests/all/bindgen.rs @@ -2,11 +2,13 @@ use tempfile; use wasm_pack::bindgen; #[test] -#[cfg(any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(windows, target_arch = "x86_64"), -))] +#[cfg( + any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(windows, target_arch = "x86_64"), + ) +)] fn can_download_prebuilt_wasm_bindgen() { use std::env; let dir = tempfile::TempDir::new().unwrap(); @@ -28,11 +30,13 @@ fn can_download_prebuilt_wasm_bindgen() { } #[test] -#[cfg(any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(windows, target_arch = "x86_64"), -))] +#[cfg( + any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(windows, target_arch = "x86_64"), + ) +)] fn downloading_prebuilt_wasm_bindgen_handles_http_errors() { let dir = tempfile::TempDir::new().unwrap(); let bad_version = "0.2.21-some-trailing-version-stuff-that-does-not-exist"; diff --git a/tests/all/test.rs b/tests/all/test.rs index 63757b1..a9173fa 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -35,12 +35,14 @@ fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() { } #[test] -#[cfg(any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86"), - all(target_os = "windows", target_arch = "x86_64") -))] +#[cfg( + any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86"), + all(target_os = "windows", target_arch = "x86_64") + ) +)] fn it_can_run_browser_tests() { let fixture = fixture::wbg_test_browser(); fixture.install_local_wasm_bindgen(); @@ -103,13 +105,15 @@ fn it_can_run_failing_tests() { } #[test] -#[cfg(any( - all(target_os = "linux", target_arch = "x86"), - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86"), - all(target_os = "windows", target_arch = "x86_64") -))] +#[cfg( + any( + all(target_os = "linux", target_arch = "x86"), + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86"), + all(target_os = "windows", target_arch = "x86_64") + ) +)] fn it_can_find_a_webdriver_on_path() { let fixture = fixture::wbg_test_browser(); fixture.install_local_wasm_bindgen(); diff --git a/tests/all/webdriver.rs b/tests/all/webdriver.rs index 5e3b0cb..72b2d28 100644 --- a/tests/all/webdriver.rs +++ b/tests/all/webdriver.rs @@ -2,24 +2,28 @@ use utils::fixture; use wasm_pack::test::webdriver; #[test] -#[cfg(any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86") -))] +#[cfg( + any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86") + ) +)] fn can_install_chromedriver() { let fixture = fixture::js_hello_world(); assert!(webdriver::install_chromedriver(&fixture.path).is_ok()); } #[test] -#[cfg(any( - all(target_os = "linux", target_arch = "x86"), - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86"), - all(target_os = "windows", target_arch = "x86_64") -))] +#[cfg( + any( + all(target_os = "linux", target_arch = "x86"), + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86"), + all(target_os = "windows", target_arch = "x86_64") + ) +)] fn can_install_geckodriver() { let fixture = fixture::js_hello_world(); assert!(webdriver::install_geckodriver(&fixture.path).is_ok()); From 66ffe1df967a071826add3d2c70224d65085558e Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Mon, 24 Sep 2018 20:30:25 -0400 Subject: [PATCH 2/2] fix(style): appease cargo fmt --- tests/all/bindgen.rs | 24 ++++++++++-------------- tests/all/test.rs | 30 +++++++++++++----------------- tests/all/webdriver.rs | 28 ++++++++++++---------------- 3 files changed, 35 insertions(+), 47 deletions(-) diff --git a/tests/all/bindgen.rs b/tests/all/bindgen.rs index 9066e95..b79d58c 100644 --- a/tests/all/bindgen.rs +++ b/tests/all/bindgen.rs @@ -2,13 +2,11 @@ use tempfile; use wasm_pack::bindgen; #[test] -#[cfg( - any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(windows, target_arch = "x86_64"), - ) -)] +#[cfg(any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(windows, target_arch = "x86_64"), +))] fn can_download_prebuilt_wasm_bindgen() { use std::env; let dir = tempfile::TempDir::new().unwrap(); @@ -30,13 +28,11 @@ fn can_download_prebuilt_wasm_bindgen() { } #[test] -#[cfg( - any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(windows, target_arch = "x86_64"), - ) -)] +#[cfg(any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(windows, target_arch = "x86_64"), +))] fn downloading_prebuilt_wasm_bindgen_handles_http_errors() { let dir = tempfile::TempDir::new().unwrap(); let bad_version = "0.2.21-some-trailing-version-stuff-that-does-not-exist"; diff --git a/tests/all/test.rs b/tests/all/test.rs index a9173fa..63757b1 100644 --- a/tests/all/test.rs +++ b/tests/all/test.rs @@ -35,14 +35,12 @@ fn it_can_run_tests_with_different_wbg_test_and_wbg_versions() { } #[test] -#[cfg( - any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86"), - all(target_os = "windows", target_arch = "x86_64") - ) -)] +#[cfg(any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86"), + all(target_os = "windows", target_arch = "x86_64") +))] fn it_can_run_browser_tests() { let fixture = fixture::wbg_test_browser(); fixture.install_local_wasm_bindgen(); @@ -105,15 +103,13 @@ fn it_can_run_failing_tests() { } #[test] -#[cfg( - any( - all(target_os = "linux", target_arch = "x86"), - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86"), - all(target_os = "windows", target_arch = "x86_64") - ) -)] +#[cfg(any( + all(target_os = "linux", target_arch = "x86"), + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86"), + all(target_os = "windows", target_arch = "x86_64") +))] fn it_can_find_a_webdriver_on_path() { let fixture = fixture::wbg_test_browser(); fixture.install_local_wasm_bindgen(); diff --git a/tests/all/webdriver.rs b/tests/all/webdriver.rs index 72b2d28..5e3b0cb 100644 --- a/tests/all/webdriver.rs +++ b/tests/all/webdriver.rs @@ -2,28 +2,24 @@ use utils::fixture; use wasm_pack::test::webdriver; #[test] -#[cfg( - any( - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86") - ) -)] +#[cfg(any( + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86") +))] fn can_install_chromedriver() { let fixture = fixture::js_hello_world(); assert!(webdriver::install_chromedriver(&fixture.path).is_ok()); } #[test] -#[cfg( - any( - all(target_os = "linux", target_arch = "x86"), - all(target_os = "linux", target_arch = "x86_64"), - all(target_os = "macos", target_arch = "x86_64"), - all(target_os = "windows", target_arch = "x86"), - all(target_os = "windows", target_arch = "x86_64") - ) -)] +#[cfg(any( + all(target_os = "linux", target_arch = "x86"), + all(target_os = "linux", target_arch = "x86_64"), + all(target_os = "macos", target_arch = "x86_64"), + all(target_os = "windows", target_arch = "x86"), + all(target_os = "windows", target_arch = "x86_64") +))] fn can_install_geckodriver() { let fixture = fixture::js_hello_world(); assert!(webdriver::install_geckodriver(&fixture.path).is_ok());