From 7d128ee762cfdffb058cc97065a7ff552068ab0e Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 29 Jan 2026 13:03:05 +0700 Subject: [PATCH 1/4] Apply check_source logic to fetch --- src/bin/repo.rs | 18 +++++------------- src/cook/fetch.rs | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/bin/repo.rs b/src/bin/repo.rs index 913e885d9..9e1d1546a 100644 --- a/src/bin/repo.rs +++ b/src/bin/repo.rs @@ -293,7 +293,7 @@ fn repo_inner( let is_cook = *command == CliCommand::Cook; let source_dir = handle_fetch(recipe, config, is_cook, logger)?; if is_cook { - handle_cook(recipe, config, source_dir, recipe.is_deps, logger)?; + handle_cook(recipe, config, source_dir, logger)?; } Ok(()) }; @@ -628,9 +628,9 @@ fn handle_fetch( allow_offline: bool, logger: &PtyOut, ) -> anyhow::Result { - let source_dir = match config.cook.offline && allow_offline { + let source_dir = match (config.cook.offline) && allow_offline { true => fetch_offline(&recipe, logger), - false => fetch(&recipe, logger), + false => fetch(&recipe, !recipe.is_deps, logger), } .map_err(|e| anyhow!("failed to fetch: {:?}", e))?; @@ -641,7 +641,6 @@ fn handle_cook( recipe: &CookRecipe, config: &CliConfig, source_dir: PathBuf, - is_deps: bool, logger: &PtyOut, ) -> anyhow::Result<()> { let recipe_dir = &recipe.dir; @@ -653,7 +652,7 @@ fn handle_cook( &recipe.name, &recipe.recipe, &config.cook, - !is_deps, + !recipe.is_deps, logger, ) .map_err(|err| anyhow!("failed to build: {:?}", err))?; @@ -1099,7 +1098,6 @@ fn run_tui_cook( let cooker_handle = thread::spawn(move || { 'done: for (mut recipe, source_dir) in work_rx { let name = recipe.name.clone(); - let is_deps = recipe.is_deps; let (mut stdout_writer, mut stderr_writer) = setup_logger(&cooker_status_tx, &name); let mut logger = Some((&mut stdout_writer, &mut stderr_writer)); 'again: loop { @@ -1107,13 +1105,7 @@ fn run_tui_cook( .send(StatusUpdate::StartCook(name.clone())) .unwrap(); let _ = recipe.reload_recipe(); // reread recipe.toml in case we're retrying - let handler = handle_cook( - &recipe, - &cooker_config, - source_dir.clone(), - is_deps, - &logger, - ); + let handler = handle_cook(&recipe, &cooker_config, source_dir.clone(), &logger); if let Some(log_path) = cooker_config.logs_dir.as_ref() { if let Err(err_ctx) = &handler { log_to_pty!(&logger, "\n{:?}", err_ctx) diff --git a/src/cook/fetch.rs b/src/cook/fetch.rs index f17dc100b..ecfb77e42 100644 --- a/src/cook/fetch.rs +++ b/src/cook/fetch.rs @@ -52,7 +52,7 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result { - fetch(recipe, logger)?; + fetch(recipe, true, logger)?; "local_source".to_string() } Some(SourceRecipe::SameAs { same_as }) => { @@ -114,7 +114,7 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result Result { +pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result { let recipe_dir = &recipe.dir; let source_dir = recipe_dir.join("source"); match recipe.recipe.build.kind { @@ -134,7 +134,7 @@ pub fn fetch(recipe: &CookRecipe, logger: &PtyOut) -> Result { Some(SourceRecipe::SameAs { same_as }) => { let recipe = fetch_resolve_canon(recipe_dir, &same_as, recipe.name.is_host())?; // recursively fetch - fetch(&recipe, logger)?; + fetch(&recipe, check_source, logger)?; fetch_make_symlink(&source_dir, &same_as)?; fetch_get_source_info(&recipe)?.source_identifier } @@ -195,6 +195,8 @@ pub fn fetch(recipe: &CookRecipe, logger: &PtyOut) -> Result { rename(&source_dir_tmp, &source_dir)?; false + } else if !check_source { + true } else { if !source_dir.join(".git").is_dir() { return Err(format!( @@ -323,28 +325,30 @@ pub fn fetch(recipe: &CookRecipe, logger: &PtyOut) -> Result { }) => { let source_tar = recipe_dir.join("source.tar"); let mut tar_updated = false; - while { + loop { if !source_tar.is_file() { tar_updated = true; download_wget(&tar, &source_tar, logger)?; + continue; + } + if !check_source { + break; } let source_tar_blake3 = get_blake3(&source_tar, tar_updated && logger.is_none())?; if let Some(blake3) = blake3 { - if source_tar_blake3 != *blake3 { - if tar_updated { - return Err(format!( - "The downloaded tar blake3 '{source_tar_blake3}' is not equal to blake3 in recipe.toml" - )); - } else { - log_to_pty!( - logger, - "DEBUG: source tar blake3 is different and need redownload" - ); - remove_all(&source_tar)?; - } - true + if source_tar_blake3 == *blake3 { + break; + } + if tar_updated { + return Err(format!( + "The downloaded tar blake3 '{source_tar_blake3}' is not equal to blake3 in recipe.toml" + )); } else { - false + log_to_pty!( + logger, + "DEBUG: source tar blake3 is different and need redownload" + ); + remove_all(&source_tar)?; } } else { //TODO: set blake3 hash on the recipe with something like "cook fix" @@ -354,9 +358,9 @@ pub fn fetch(recipe: &CookRecipe, logger: &PtyOut) -> Result { source_tar.display(), source_tar_blake3 ); - false + break; } - } {} + } if source_dir.is_dir() { if tar_updated || fetch_is_patches_newer(recipe_dir, patches, &source_dir)? { log_to_pty!( @@ -396,6 +400,7 @@ pub fn fetch(recipe: &CookRecipe, logger: &PtyOut) -> Result { package_path, cargoflags: _, } = &recipe.recipe.build.kind + && check_source { fetch_cargo(&source_dir, package_path.as_ref(), logger)?; } From e80b936954578d0767e4512c5e87ae375d8390b3 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 29 Jan 2026 13:04:04 +0700 Subject: [PATCH 2/4] Check build against stage pkgar instead of dir --- src/cook/cook_build.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/cook/cook_build.rs b/src/cook/cook_build.rs index 183390d77..5468451a3 100644 --- a/src/cook/cook_build.rs +++ b/src/cook/cook_build.rs @@ -180,6 +180,10 @@ pub fn build( let sysroot_dir = target_dir.join("sysroot"); let toolchain_dir = target_dir.join("toolchain"); let stage_dirs = get_stage_dirs(&recipe.optional_packages, target_dir); + let stage_pkgars: Vec = stage_dirs + .iter() + .map(|p| p.with_added_extension("pkgar")) + .collect(); let cli_verbose = cook_config.verbose; let cli_jobs = cook_config.jobs; if recipe.build.kind == BuildKind::None { @@ -218,7 +222,7 @@ pub fn build( }; } - if !check_source && stage_dirs.iter().all(|dir| dir.exists()) { + if !check_source && stage_pkgars.iter().all(|file| file.is_file()) { if cli_verbose { log_to_pty!(logger, "DEBUG: using cached build, not checking source"); } @@ -245,14 +249,7 @@ pub fn build( .unwrap_or(Ok(SystemTime::UNIX_EPOCH))?; // check stage dir modified against pkgar files, any files missing will result in UNIX_EPOCH - let stage_modified = modified_all( - &stage_dirs - .iter() - .map(|p| p.with_added_extension("pkgar")) - .collect(), - modified, - ) - .unwrap_or(SystemTime::UNIX_EPOCH); + let stage_modified = modified_all(&stage_pkgars, modified).unwrap_or(SystemTime::UNIX_EPOCH); // Rebuild stage if source is newer if stage_modified < source_modified || stage_modified < deps_modified From aa3435155366321f7114327dfbac3842093cc846 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 29 Jan 2026 13:20:57 +0700 Subject: [PATCH 3/4] Reduce pty flush wait --- src/cook/pty.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cook/pty.rs b/src/cook/pty.rs index aec8869b0..1371cbddf 100644 --- a/src/cook/pty.rs +++ b/src/cook/pty.rs @@ -62,9 +62,8 @@ pub fn flush_pty(logger: &mut PtyOut) { }; // Not sure if flush actually working let _ = pty.flush(); - std::thread::sleep(Duration::from_millis(100)); + std::thread::sleep(Duration::from_millis(10)); let _ = file.flush(); - std::thread::sleep(Duration::from_millis(100)); } pub fn spawn_to_pipe(command: &mut Command, stdout_pipe: &PtyOut) -> Result { From 9089d46f8c764f4c28d4eedb81f8c7e3adda3f7a Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 29 Jan 2026 13:44:48 +0700 Subject: [PATCH 4/4] Some logic correction --- src/bin/repo.rs | 2 +- src/cook/fetch.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bin/repo.rs b/src/bin/repo.rs index 9e1d1546a..b51755e03 100644 --- a/src/bin/repo.rs +++ b/src/bin/repo.rs @@ -628,7 +628,7 @@ fn handle_fetch( allow_offline: bool, logger: &PtyOut, ) -> anyhow::Result { - let source_dir = match (config.cook.offline) && allow_offline { + let source_dir = match config.cook.offline && allow_offline { true => fetch_offline(&recipe, logger), false => fetch(&recipe, !recipe.is_deps, logger), } diff --git a/src/cook/fetch.rs b/src/cook/fetch.rs index ecfb77e42..4c7154d12 100644 --- a/src/cook/fetch.rs +++ b/src/cook/fetch.rs @@ -329,7 +329,6 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result if !source_tar.is_file() { tar_updated = true; download_wget(&tar, &source_tar, logger)?; - continue; } if !check_source { break; @@ -400,8 +399,8 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result package_path, cargoflags: _, } = &recipe.recipe.build.kind - && check_source { + // TODO: No need to fetch if !check_source and already fetched? fetch_cargo(&source_dir, package_path.as_ref(), logger)?; }