Skip to content

Commit ce778a9

Browse files
authored
Revert "perf(upgrade): cache downloaded binaries in DENO_DIR" (denoland#26799)
Reverts denoland#26108 Tests are flaky on main denoland@01de331
1 parent 01de331 commit ce778a9

File tree

8 files changed

+117
-128
lines changed

8 files changed

+117
-128
lines changed

cli/download_deno_binary.rs

Lines changed: 0 additions & 97 deletions
This file was deleted.

cli/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod args;
44
mod auth_tokens;
55
mod cache;
66
mod cdp;
7-
mod download_deno_binary;
87
mod emit;
98
mod errors;
109
mod factory;

cli/mainrt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod standalone;
1010
mod args;
1111
mod auth_tokens;
1212
mod cache;
13-
mod download_deno_binary;
1413
mod emit;
1514
mod errors;
1615
mod file_fetcher;

cli/standalone/binary.rs

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ use crate::args::NpmInstallDepsProvider;
6363
use crate::args::PermissionFlags;
6464
use crate::args::UnstableConfig;
6565
use crate::cache::DenoDir;
66-
use crate::download_deno_binary::archive_name;
67-
use crate::download_deno_binary::download_deno_binary;
68-
use crate::download_deno_binary::BinaryKind;
6966
use crate::emit::Emitter;
7067
use crate::file_fetcher::FileFetcher;
7168
use crate::http_util::HttpClientProvider;
@@ -455,24 +452,36 @@ impl<'a> DenoCompileBinaryWriter<'a> {
455452
}
456453

457454
let target = compile_flags.resolve_target();
455+
let binary_name = format!("denort-{target}.zip");
456+
457+
let binary_path_suffix =
458+
match crate::version::DENO_VERSION_INFO.release_channel {
459+
ReleaseChannel::Canary => {
460+
format!(
461+
"canary/{}/{}",
462+
crate::version::DENO_VERSION_INFO.git_hash,
463+
binary_name
464+
)
465+
}
466+
_ => {
467+
format!("release/v{}/{}", env!("CARGO_PKG_VERSION"), binary_name)
468+
}
469+
};
458470

459-
let archive_name = archive_name(BinaryKind::Denort, &target);
471+
let download_directory = self.deno_dir.dl_folder_path();
472+
let binary_path = download_directory.join(&binary_path_suffix);
460473

461-
let binary_path = download_deno_binary(
462-
self.http_client_provider,
463-
self.deno_dir,
464-
BinaryKind::Denort,
465-
&target,
466-
crate::version::DENO_VERSION_INFO.version_or_git_hash(),
467-
crate::version::DENO_VERSION_INFO.release_channel,
468-
)
469-
.await?;
474+
if !binary_path.exists() {
475+
self
476+
.download_base_binary(&download_directory, &binary_path_suffix)
477+
.await?;
478+
}
470479

471480
let archive_data = std::fs::read(binary_path)?;
472481
let temp_dir = tempfile::TempDir::new()?;
473482
let base_binary_path = archive::unpack_into_dir(archive::UnpackArgs {
474-
exe_name: BinaryKind::Denort.name(),
475-
archive_name: &archive_name,
483+
exe_name: "denort",
484+
archive_name: &binary_name,
476485
archive_data: &archive_data,
477486
is_windows: target.contains("windows"),
478487
dest_path: temp_dir.path(),
@@ -482,6 +491,41 @@ impl<'a> DenoCompileBinaryWriter<'a> {
482491
Ok(base_binary)
483492
}
484493

494+
async fn download_base_binary(
495+
&self,
496+
output_directory: &Path,
497+
binary_path_suffix: &str,
498+
) -> Result<(), AnyError> {
499+
let download_url = format!("https://dl.deno.land/{binary_path_suffix}");
500+
let maybe_bytes = {
501+
let progress_bars = ProgressBar::new(ProgressBarStyle::DownloadBars);
502+
let progress = progress_bars.update(&download_url);
503+
504+
self
505+
.http_client_provider
506+
.get_or_create()?
507+
.download_with_progress_and_retries(
508+
download_url.parse()?,
509+
None,
510+
&progress,
511+
)
512+
.await?
513+
};
514+
let bytes = match maybe_bytes {
515+
Some(bytes) => bytes,
516+
None => {
517+
log::info!("Download could not be found, aborting");
518+
std::process::exit(1)
519+
}
520+
};
521+
522+
std::fs::create_dir_all(output_directory)?;
523+
let output_path = output_directory.join(binary_path_suffix);
524+
std::fs::create_dir_all(output_path.parent().unwrap())?;
525+
tokio::fs::write(output_path, bytes).await?;
526+
Ok(())
527+
}
528+
485529
/// This functions creates a standalone deno binary by appending a bundle
486530
/// and magic trailer to the currently executing binary.
487531
#[allow(clippy::too_many_arguments)]

cli/tools/upgrade.rs

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ use crate::args::Flags;
66
use crate::args::UpgradeFlags;
77
use crate::args::UPGRADE_USAGE;
88
use crate::colors;
9-
use crate::download_deno_binary::archive_name;
10-
use crate::download_deno_binary::download_deno_binary;
11-
use crate::download_deno_binary::BinaryKind;
129
use crate::factory::CliFactory;
1310
use crate::http_util::HttpClient;
1411
use crate::http_util::HttpClientProvider;
1512
use crate::shared::ReleaseChannel;
1613
use crate::util::archive;
14+
use crate::util::progress_bar::ProgressBar;
15+
use crate::util::progress_bar::ProgressBarStyle;
1716
use crate::version;
1817

1918
use async_trait::async_trait;
@@ -35,8 +34,12 @@ use std::process::Command;
3534
use std::sync::Arc;
3635
use std::time::Duration;
3736

38-
static ARCHIVE_NAME: Lazy<String> =
39-
Lazy::new(|| archive_name(BinaryKind::Deno, env!("TARGET")));
37+
const RELEASE_URL: &str = "https://github.com/denoland/deno/releases";
38+
const CANARY_URL: &str = "https://dl.deno.land/canary";
39+
const DL_RELEASE_URL: &str = "https://dl.deno.land/release";
40+
41+
pub static ARCHIVE_NAME: Lazy<String> =
42+
Lazy::new(|| format!("deno-{}.zip", env!("TARGET")));
4043

4144
// How often query server for new version. In hours.
4245
const UPGRADE_CHECK_INTERVAL: i64 = 24;
@@ -529,17 +532,13 @@ pub async fn upgrade(
529532
return Ok(());
530533
};
531534

532-
let binary_path = download_deno_binary(
533-
http_client_provider,
534-
factory.deno_dir()?,
535-
BinaryKind::Deno,
536-
env!("TARGET"),
535+
let download_url = get_download_url(
537536
&selected_version_to_upgrade.version_or_hash,
538537
requested_version.release_channel(),
539-
)
540-
.await?;
541-
542-
let Ok(archive_data) = tokio::fs::read(&binary_path).await else {
538+
)?;
539+
log::info!("{}", colors::gray(format!("Downloading {}", &download_url)));
540+
let Some(archive_data) = download_package(&client, download_url).await?
541+
else {
543542
log::error!("Download could not be found, aborting");
544543
std::process::exit(1)
545544
};
@@ -882,6 +881,48 @@ fn base_upgrade_url() -> Cow<'static, str> {
882881
}
883882
}
884883

884+
fn get_download_url(
885+
version: &str,
886+
release_channel: ReleaseChannel,
887+
) -> Result<Url, AnyError> {
888+
let download_url = match release_channel {
889+
ReleaseChannel::Stable => {
890+
format!("{}/download/v{}/{}", RELEASE_URL, version, *ARCHIVE_NAME)
891+
}
892+
ReleaseChannel::Rc => {
893+
format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME)
894+
}
895+
ReleaseChannel::Canary => {
896+
format!("{}/{}/{}", CANARY_URL, version, *ARCHIVE_NAME)
897+
}
898+
ReleaseChannel::Lts => {
899+
format!("{}/v{}/{}", DL_RELEASE_URL, version, *ARCHIVE_NAME)
900+
}
901+
};
902+
903+
Url::parse(&download_url).with_context(|| {
904+
format!(
905+
"Failed to parse URL to download new release: {}",
906+
download_url
907+
)
908+
})
909+
}
910+
911+
async fn download_package(
912+
client: &HttpClient,
913+
download_url: Url,
914+
) -> Result<Option<Vec<u8>>, AnyError> {
915+
let progress_bar = ProgressBar::new(ProgressBarStyle::DownloadBars);
916+
// provide an empty string here in order to prefer the downloading
917+
// text above which will stay alive after the progress bars are complete
918+
let progress = progress_bar.update("");
919+
let maybe_bytes = client
920+
.download_with_progress_and_retries(download_url.clone(), None, &progress)
921+
.await
922+
.with_context(|| format!("Failed downloading {download_url}. The version you requested may not have been built for the current architecture."))?;
923+
Ok(maybe_bytes)
924+
}
925+
885926
fn replace_exe(from: &Path, to: &Path) -> Result<(), std::io::Error> {
886927
if cfg!(windows) {
887928
// On windows you cannot replace the currently running executable.

tests/specs/upgrade/out/upgrade.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Current Deno version: [WILDCARD]
2+
Downloading https://github.com/denoland/deno/releases/download/v1.43.2/deno-[WILDCARD].zip
23
Deno is upgrading to version 1.43.2
34

45
Upgraded successfully to Deno v1.43.2 (stable)

tests/specs/upgrade/space_in_tmp/upgrade.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Current Deno version: [WILDCARD]
2+
Downloading https://github.com/denoland/deno/releases/download/v1.43.2/deno-[WILDCARD].zip
23
Deno is upgrading to version 1.43.2
34

45
Upgraded successfully to Deno v1.43.2 (stable)

tests/specs/upgrade/specific_stable/upgrade.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Current Deno version: [WILDCARD]
2+
Downloading https://github.com/denoland/deno/releases/download/v1.43.2/deno-[WILDCARD].zip
23
Deno is upgrading to version 1.43.2
34

45
Upgraded successfully to Deno v1.43.2 (stable)

0 commit comments

Comments
 (0)