diff options
author | crowlKats <13135287+crowlKats@users.noreply.github.com> | 2020-11-08 11:54:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-08 11:54:35 +0100 |
commit | 5995c58e634aa11f80987be8572dfc6e7c2a2906 (patch) | |
tree | d62424c87d205ed2651f91e2cd549abf08ade415 /cli/upgrade.rs | |
parent | ccc95bc9b926dc2340302d9afc0ab813e1dc887d (diff) |
refactor: auto detect target triples for upgrade (#8286)
Diffstat (limited to 'cli/upgrade.rs')
-rw-r--r-- | cli/upgrade.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/cli/upgrade.rs b/cli/upgrade.rs index 37c7a88ed..e67e88d93 100644 --- a/cli/upgrade.rs +++ b/cli/upgrade.rs @@ -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"); @@ -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) } @@ -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(); |