From bd781773290223e2c24e4b90f3bd8ada99a8c538 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Mon, 29 Dec 2025 21:53:57 +0700 Subject: [PATCH 1/2] Flat out package names when building --- src/bin/repo.rs | 1 + src/cook/cook_build.rs | 2 +- src/recipe.rs | 32 ++++++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/bin/repo.rs b/src/bin/repo.rs index 8a939da3..82664f14 100644 --- a/src/bin/repo.rs +++ b/src/bin/repo.rs @@ -497,6 +497,7 @@ fn parse_args(args: Vec) -> anyhow::Result<(CliConfig, CliCommand, Vec Result, PackageError> { let mut packages = Self::new_recursive( names, @@ -399,6 +405,24 @@ impl CookRecipe { } } + if flatten_opt_package { + let old_packages = packages; + packages = Vec::new(); + let mut packages_set = BTreeSet::new(); + for mut package in old_packages { + let is_host = package.name.is_host(); + let mut name = package.name.with_suffix(None); + if is_host { + name = name.with_host(); + } + if !packages_set.contains(name.as_str()) { + packages_set.insert(name.to_string()); + package.name = name; + packages.push(package); + } + } + } + Ok(packages) } From 7654063412fff420f68ef3cfbe074463b6e5148c Mon Sep 17 00:00:00 2001 From: Wildan M Date: Wed, 31 Dec 2025 07:38:21 +0700 Subject: [PATCH 2/2] Refactor out deps helper fn --- src/bin/repo.rs | 15 +++++------ src/cook/cook_build.rs | 4 +-- src/recipe.rs | 56 +++++++++++++++++++++--------------------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/bin/repo.rs b/src/bin/repo.rs index 82664f14..9fe66a21 100644 --- a/src/bin/repo.rs +++ b/src/bin/repo.rs @@ -10,7 +10,7 @@ use cookbook::cook::pty::{PtyOut, UnixSlavePty, flush_pty, setup_pty}; use cookbook::cook::script::KILL_ALL_PID; use cookbook::cook::tree::{WalkTreeEntry, display_tree_entry, format_size, walk_tree_entry}; use cookbook::log_to_pty; -use cookbook::recipe::CookRecipe; +use cookbook::recipe::{CookRecipe, recipes_flatten_package_names, recipes_mark_as_deps}; use pkg::PackageName; use pkg::package::PackageError; use ratatui::Terminal; @@ -492,13 +492,14 @@ fn parse_args(args: Vec) -> anyhow::Result<(CliConfig, CliCommand, Vec Result, PackageError> { - let mut packages = Self::new_recursive( + let packages = Self::new_recursive( names, true, include_dev, @@ -399,30 +397,6 @@ impl CookRecipe { WALK_DEPTH, )?; - if mark_is_deps { - for package in packages.iter_mut() { - package.is_deps = !names.contains(&package.name); - } - } - - if flatten_opt_package { - let old_packages = packages; - packages = Vec::new(); - let mut packages_set = BTreeSet::new(); - for mut package in old_packages { - let is_host = package.name.is_host(); - let mut name = package.name.with_suffix(None); - if is_host { - name = name.with_host(); - } - if !packages_set.contains(name.as_str()) { - packages_set.insert(name.to_string()); - package.name = name; - packages.push(package); - } - } - } - Ok(packages) } @@ -497,6 +471,32 @@ impl CookRecipe { } } +// TODO: Wrap these vectors in a struct + +pub fn recipes_mark_as_deps(names: &[PackageName], packages: &mut Vec) { + for package in packages.iter_mut() { + package.is_deps = !names.contains(&package.name); + } +} + +pub fn recipes_flatten_package_names(packages: Vec) -> Vec { + let mut new_packages = Vec::new(); + let mut packages_set = BTreeSet::new(); + for mut package in packages { + let is_host = package.name.is_host(); + let mut name = package.name.with_suffix(None); + if is_host { + name = name.with_host(); + } + if !packages_set.contains(name.as_str()) { + packages_set.insert(name.to_string()); + package.name = name; + new_packages.push(package); + } + } + new_packages +} + #[derive(Serialize, Deserialize)] pub struct AutoDeps { pub packages: BTreeSet,