Test URL-building matrix

master
Philipp Krüger 3 years ago committed by printfn
parent a0074b8893
commit 0d39cced6b
  1. 40
      src/install/arch.rs
  2. 46
      src/install/mod.rs
  3. 40
      src/install/os.rs
  4. 36
      tests/all/download.rs

@ -0,0 +1,40 @@
use std::fmt;
use crate::target;
/// An enum representing supported architectures
#[derive(Clone, PartialEq, Eq)]
pub enum Arch {
/// x86 64-bit
X86_64,
/// x86 32-bit
X86,
/// ARM 64-bit
AArch64,
}
impl Arch {
/// Gets the current architecture
pub fn get() -> Result<Self, failure::Error> {
if target::x86_64 {
Ok(Arch::X86_64)
} else if target::x86 {
Ok(Arch::X86)
} else if target::aarch64 {
Ok(Arch::AArch64)
} else {
bail!("Unrecognized target!")
}
}
}
impl fmt::Display for Arch {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Arch::X86_64 => "x86-64",
Arch::X86 => "x86",
Arch::AArch64 => "aarch64",
};
write!(f, "{}", s)
}
}

@ -12,14 +12,17 @@ use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;
use target;
use which::which;
use PBAR;
mod arch;
mod krate;
mod mode;
mod os;
mod tool;
pub use self::arch::Arch;
pub use self::mode::InstallMode;
pub use self::os::Os;
pub use self::tool::Tool;
/// Possible outcomes of attempting to find/install a tool
@ -162,27 +165,28 @@ pub fn download_prebuilt(
/// Returns the URL of a precompiled version of wasm-bindgen, if we have one
/// available for our host platform.
fn prebuilt_url(tool: &Tool, version: &str) -> Result<String, failure::Error> {
let target = if target::LINUX && target::x86_64 {
match tool {
Tool::WasmOpt => "x86_64-linux",
_ => "x86_64-unknown-linux-musl",
}
} else if target::MACOS && (target::x86_64 || target::aarch64) {
"x86_64-macos"
} else if target::WINDOWS && target::x86_64 {
match tool {
Tool::WasmOpt => "x86_64-windows",
_ => "x86_64-pc-windows-msvc",
}
} else if target::WINDOWS && target::x86 {
match tool {
Tool::WasmOpt => "x86-windows",
_ => bail!("Unrecognized target!"),
}
} else {
bail!("Unrecognized target!")
};
let os = Os::get()?;
let arch = Arch::get()?;
prebuilt_url_for(tool, version, &arch, &os)
}
/// Get the download URL for some tool at some version, architecture and operating system
pub fn prebuilt_url_for(
tool: &Tool,
version: &str,
arch: &Arch,
os: &Os,
) -> Result<String, failure::Error> {
let target = match (os, arch, tool) {
(Os::Linux, Arch::X86_64, Tool::WasmOpt) => "x86_64-linux",
(Os::Linux, Arch::X86_64, _) => "x86_64-unknown-linux-musl",
(Os::MacOS, Arch::X86, _) => bail!("Unrecognized target!"),
(Os::MacOS, _, Tool::WasmOpt) => "x86_64-macos",
(Os::MacOS, _, _) => "x86_64-apple-darwin",
(Os::Windows, Arch::X86_64, Tool::WasmOpt) => "x86_64-windows",
(Os::Windows, Arch::X86_64, _) => "x86_64-pc-windows-msvc",
_ => bail!("Unrecognized target!"),
};
match tool {
Tool::WasmBindgen => {
Ok(format!(

@ -0,0 +1,40 @@
use std::fmt;
use crate::target;
/// An enum representing supported operating systems
#[derive(Clone, PartialEq, Eq)]
pub enum Os {
/// Linux operating system
Linux,
/// Macos operating system
MacOS,
/// Windows operating system
Windows,
}
impl Os {
/// Get the current operating system
pub fn get() -> Result<Self, failure::Error> {
if target::LINUX {
Ok(Os::Linux)
} else if target::MACOS {
Ok(Os::MacOS)
} else if target::WINDOWS {
Ok(Os::Windows)
} else {
bail!("Unrecognized target!")
}
}
}
impl fmt::Display for Os {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Os::Linux => "linux",
Os::MacOS => "macOS",
Os::Windows => "windows",
};
write!(f, "{}", s)
}
}

@ -1,6 +1,6 @@
use binary_install::Cache;
use tempfile;
use wasm_pack::install::{self, Tool};
use wasm_pack::install::{self, Arch, Os, Tool};
#[test]
#[cfg(any(
@ -58,3 +58,37 @@ fn can_download_prebuilt_cargo_generate() {
assert!(false, "Download Failed");
}
}
#[test]
fn all_latest_tool_download_urls_valid() {
let mut errors = Vec::new();
for tool in [Tool::CargoGenerate, Tool::WasmBindgen, Tool::WasmOpt] {
for arch in [Arch::X86_64, Arch::X86, Arch::AArch64] {
for os in [Os::Linux, Os::MacOS, Os::Windows] {
// For all valid tool, arch & os combinations,
// error out when any of them is a 404 or similar
if let Ok(url) = install::prebuilt_url_for(&tool, "0.2.82", &arch, &os) {
let client = reqwest::Client::new();
// Use HTTP HEAD instead of GET to avoid fetching lots of stuff
let res = client.head(&url).send().unwrap();
if res.status().is_client_error() {
errors.push(format!(
"Can't download URL {} for {} on {}: {}",
url,
arch,
os,
res.status()
));
}
}
}
}
}
if !errors.is_empty() {
panic!(
"Some URLs for prebuild tools were unavailable:\n{}",
errors.join("\n")
);
}
}

Loading…
Cancel
Save