From 31e0ab5f828db12b7f62fac826e5d2ddb353dbb2 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sat, 22 Nov 2025 04:49:29 -0800 Subject: [PATCH] Move package binary download at fetch step --- src/cook/cook_build.rs | 34 ++------------------------ src/cook/fetch.rs | 55 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/cook/cook_build.rs b/src/cook/cook_build.rs index 2fb19b6b..d2738b37 100644 --- a/src/cook/cook_build.rs +++ b/src/cook/cook_build.rs @@ -19,8 +19,6 @@ use std::{ use crate::{is_redox, log_to_pty}; -use crate::REMOTE_PKG_SOURCE; - fn auto_deps_from_dynamic_linking( stage_dir: &Path, dep_pkgars: &BTreeSet<(PackageName, PathBuf)>, @@ -314,7 +312,7 @@ pub fn build( flags_fn("COOKBOOK_MESON_FLAGS", mesonflags), ), BuildKind::Custom { script } => script.clone(), - BuildKind::Remote => return build_remote(target_dir, name, offline_mode, logger), + BuildKind::Remote => return build_remote(target_dir), BuildKind::None => "".to_owned(), }; @@ -410,25 +408,7 @@ fn build_auto_deps( Ok(auto_deps) } -fn get_remote_url(name: &PackageName, ext: &str) -> String { - return format!( - "{}/{}/{}.{}", - REMOTE_PKG_SOURCE, - redoxer::target(), - name, - ext - ); -} -fn get_pubkey_url() -> String { - return format!("{}/id_ed25519.pub.toml", REMOTE_PKG_SOURCE); -} - -pub fn build_remote( - target_dir: &Path, - name: &PackageName, - offline_mode: bool, - logger: &PtyOut, -) -> Result<(PathBuf, BTreeSet), String> { +pub fn build_remote(target_dir: &Path) -> Result<(PathBuf, BTreeSet), String> { // download straight from remote source then declare pkg dependencies as autodeps dependency let stage_dir = target_dir.join("stage"); @@ -436,16 +416,6 @@ pub fn build_remote( let source_toml = target_dir.join("source.toml"); let source_pubkey = target_dir.join("id_ed25519.pub.toml"); - if !offline_mode { - download_wget(&get_remote_url(name, "pkgar"), &source_pkgar, logger)?; - download_wget(&get_remote_url(name, "toml"), &source_toml, logger)?; - download_wget(&get_pubkey_url(), &source_pubkey, logger)?; - } else { - offline_check_exists(&source_pkgar)?; - offline_check_exists(&source_toml)?; - offline_check_exists(&source_pubkey)?; - } - if stage_dir.is_dir() && modified(&source_pkgar)? > modified(&stage_dir)? { remove_all(&stage_dir)? } diff --git a/src/cook/fetch.rs b/src/cook/fetch.rs index 7536d6e7..aff03b2a 100644 --- a/src/cook/fetch.rs +++ b/src/cook/fetch.rs @@ -1,3 +1,4 @@ +use crate::REMOTE_PKG_SOURCE; use crate::config::translate_mirror; use crate::cook::fs::*; use crate::cook::pty::PtyOut; @@ -33,10 +34,15 @@ pub fn fetch_offline( logger: &PtyOut, ) -> Result { let source_dir = recipe_dir.join("source"); - if recipe.build.kind == BuildKind::None || recipe.build.kind == BuildKind::Remote { + if recipe.build.kind == BuildKind::None { // the build function doesn't need source dir exists return Ok(source_dir); } + if recipe.build.kind == BuildKind::Remote { + fetch_remote(recipe_dir, true, logger)?; + return Ok(source_dir); + } + match &recipe.source { Some(SourceRecipe::Path { path: _ }) | None => { return fetch(recipe_dir, recipe, logger); @@ -71,6 +77,7 @@ pub fn fetch_offline( "The downloaded tar blake3 '{source_tar_blake3}' is not equal to blake3 in recipe.toml." )); } + create_dir(&source_dir)?; fetch_extract_tar(source_tar, &source_dir, logger)?; fetch_apply_patches(recipe_dir, patches, script, &source_dir, logger)?; } else { @@ -92,10 +99,15 @@ pub fn fetch_offline( pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result { let source_dir = recipe_dir.join("source"); - if recipe.build.kind == BuildKind::None || recipe.build.kind == BuildKind::Remote { + if recipe.build.kind == BuildKind::None { // the build function doesn't need source dir exists return Ok(source_dir); } + if recipe.build.kind == BuildKind::Remote { + fetch_remote(recipe_dir, false, logger)?; + return Ok(source_dir); + } + match &recipe.source { Some(SourceRecipe::SameAs { same_as }) => { let (canon_dir, recipe) = fetch_resolve_canon(recipe_dir, &same_as)?; @@ -415,6 +427,45 @@ pub(crate) fn fetch_cargo( Ok(()) } +fn get_remote_url(name: &str, ext: &str) -> String { + return format!( + "{}/{}/{}.{}", + REMOTE_PKG_SOURCE, + redoxer::target(), + name, + ext + ); +} + +fn get_pubkey_url() -> String { + return format!("{}/id_ed25519.pub.toml", REMOTE_PKG_SOURCE); +} + +pub fn fetch_remote(recipe_dir: &Path, offline_mode: bool, logger: &PtyOut) -> Result<(), String> { + let target_dir = create_target_dir(recipe_dir)?; + let name = recipe_dir + .file_name() + .ok_or("Unable to get recipe name")? + .to_str() + .unwrap(); + let source_pkgar = target_dir.join("source.pkgar"); + let source_toml = target_dir.join("source.toml"); + let source_pubkey = target_dir.join("id_ed25519.pub.toml"); + + if !offline_mode { + //TODO: Check freshness + download_wget(&get_remote_url(name, "pkgar"), &source_pkgar, logger)?; + download_wget(&get_remote_url(name, "toml"), &source_toml, logger)?; + download_wget(&get_pubkey_url(), &source_pubkey, logger)?; + } else { + offline_check_exists(&source_pkgar)?; + offline_check_exists(&source_toml)?; + offline_check_exists(&source_pubkey)?; + } + + Ok(()) +} + pub(crate) fn fetch_is_patches_newer( recipe_dir: &Path, patches: &Vec,