Skip to content

Commit

Permalink
refactor: auto detect target triples for upgrade (denoland#8286)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Nov 8, 2020
1 parent ccc95bc commit 5995c58
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ use std::process::Stdio;
use std::string::String;
use tempfile::TempDir;

// TODO(ry) Auto detect target triples for the uploaded files.
#[cfg(windows)]
const ARCHIVE_NAME: &str = "deno-x86_64-pc-windows-msvc.zip";
#[cfg(target_os = "macos")]
const ARCHIVE_NAME: &str = "deno-x86_64-apple-darwin.zip";
#[cfg(target_os = "linux")]
const ARCHIVE_NAME: &str = "deno-x86_64-unknown-linux-gnu.zip";
lazy_static! {
static ref ARCHIVE_NAME: String = format!("deno-{}.zip", env!("TARGET"));
}

async fn get_latest_version(client: &Client) -> Result<Version, AnyError> {
println!("Checking for latest version");
Expand Down Expand Up @@ -165,7 +161,7 @@ fn download_package(
fn compose_url_to_exec(version: &Version) -> Result<Url, AnyError> {
let s = format!(
"https://github.com/denoland/deno/releases/download/v{}/{}",
version, ARCHIVE_NAME
version, *ARCHIVE_NAME
);
Url::parse(&s).map_err(AnyError::from)
}
Expand All @@ -188,7 +184,7 @@ fn unpack(archive_data: Vec<u8>) -> Result<PathBuf, std::io::Error> {
let exe_path = temp_dir.join("deno").with_extension(exe_ext);
assert!(!exe_path.exists());

let archive_ext = Path::new(ARCHIVE_NAME)
let archive_ext = Path::new(&*ARCHIVE_NAME)
.extension()
.and_then(|ext| ext.to_str())
.unwrap();
Expand Down

0 comments on commit 5995c58

Please sign in to comment.