From 94a0355907be4988b693909a2c08114a3c20c3aa Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sat, 28 Mar 2026 11:28:21 +0700 Subject: [PATCH] Don't pass cargo offline for custom script --- src/cook/cook_build.rs | 6 +++++- src/cook/fetch.rs | 24 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/cook/cook_build.rs b/src/cook/cook_build.rs index 0a23a002f..f6772069f 100644 --- a/src/cook/cook_build.rs +++ b/src/cook/cook_build.rs @@ -356,6 +356,7 @@ pub fn build( return build_remote(stage_dirs, recipe, target_dir, cook_config); } + let mut allow_cargo_offline = false; //TODO: better integration with redoxer (library instead of binary) //TODO: configurable target //TODO: Add more configurability, convert scripts to Rust? @@ -366,6 +367,7 @@ pub fn build( cargopackages, cargoexamples, } => { + allow_cargo_offline = true; let mut script = format!( "DYNAMIC_INIT\n{}\nCOOKBOOK_CARGO_PATH={} ", flags_fn("COOKBOOK_CARGO_FLAGS", cargoflags), @@ -455,8 +457,10 @@ pub fn build( if cli_verbose { command.env("COOKBOOK_VERBOSE", "1"); } - if cook_config.offline { + if cook_config.offline && allow_cargo_offline { command.env("COOKBOOK_OFFLINE", "1"); + } else { + command.env_remove("COOKBOOK_OFFLINE"); } if let Ok(ident_source) = fetch::fetch_get_source_info(&cook_recipe) { command.env("COOKBOOK_SOURCE_IDENT", ident_source.source_identifier); diff --git a/src/cook/fetch.rs b/src/cook/fetch.rs index f9a8ebfc1..e05e983a3 100644 --- a/src/cook/fetch.rs +++ b/src/cook/fetch.rs @@ -1,4 +1,5 @@ use crate::config::translate_mirror; +use crate::cook::cook_build; use crate::cook::fetch_repo; use crate::cook::fetch_repo::PlainPtyCallback; use crate::cook::fs::*; @@ -392,8 +393,9 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result cargoexamples: _, } = &recipe.recipe.build.kind { - // TODO: No need to fetch if !check_source and already fetched? - fetch_cargo(&source_dir, cargopath.as_ref(), logger)?; + if fetch_will_build(recipe) { + fetch_cargo(&source_dir, cargopath.as_ref(), logger)?; + } } fetch_apply_source_info(recipe, ident)?; @@ -401,6 +403,24 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result Ok(source_dir) } +/// This does the same check as in cook_build +fn fetch_will_build(recipe: &CookRecipe) -> bool { + let check_source = !recipe.is_deps; + if !check_source { + // there could be more check here, but it's heavy so just assume it will build + return true; + } + + let stage_dirs = + cook_build::get_stage_dirs(&recipe.recipe.optional_packages, &recipe.target_dir()); + let stage_pkgars: Vec = stage_dirs + .iter() + .map(|p| p.with_added_extension("pkgar")) + .collect(); + let stage_present = stage_pkgars.iter().all(|file| file.is_file()); + !stage_present +} + pub(crate) fn fetch_make_symlink(source_dir: &PathBuf, same_as: &String) -> Result<(), String> { let target_dir = Path::new(same_as).join("source"); if !source_dir.is_symlink() {