From 835c25e92d78cc9ee725787717f3295d88aa0e4b Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sat, 1 Nov 2025 19:21:57 +0700 Subject: [PATCH] Make repo call repo_builder instead --- repo.sh | 2 -- src/bin/repo.rs | 26 +++++++++++++++++++++++--- src/bin/repo_builder.rs | 15 ++++++++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/repo.sh b/repo.sh index 15a81cece..4f0325302 100755 --- a/repo.sh +++ b/repo.sh @@ -23,5 +23,3 @@ do done repo cook $COOK_OPT $recipes - -repo_builder "$ROOT/repo/$TARGET" $recipes diff --git a/src/bin/repo.rs b/src/bin/repo.rs index 97c4066c2..45b9726ec 100644 --- a/src/bin/repo.rs +++ b/src/bin/repo.rs @@ -4,7 +4,7 @@ use cookbook::WALK_DEPTH; use cookbook::config::{CookConfig, get_config, init_config}; use cookbook::cook::cook_build::build; use cookbook::cook::fetch::{fetch, fetch_offline}; -use cookbook::cook::fs::create_target_dir; +use cookbook::cook::fs::{create_target_dir, run_command}; use cookbook::cook::package::package; use cookbook::cook::pty::{PtyOut, UnixSlavePty, setup_pty}; use cookbook::cook::tree::{display_tree_entry, format_size}; @@ -173,7 +173,7 @@ fn main_inner() -> anyhow::Result<()> { let (config, command, recipe_names) = parse_args(args)?; if command == CliCommand::Cook && config.cook.tui { - if let Some((name, e)) = run_tui_cook(config, recipe_names)? { + if let Some((name, e)) = run_tui_cook(config.clone(), recipe_names.clone())? { let _ = stderr().write(e.as_bytes()); let _ = stderr().write(b"\n\n"); eprintln!( @@ -194,7 +194,7 @@ fn main_inner() -> anyhow::Result<()> { style::Reset, ); } - return Ok(()); + return publish_packages(&recipe_names, &config.repo_dir); } if command == CliCommand::Tree { return handle_tree(&recipe_names, &config); @@ -236,6 +236,10 @@ fn main_inner() -> anyhow::Result<()> { } } + if command == CliCommand::Cook { + return publish_packages(&recipe_names, &config.repo_dir); + } + if verbose { println!( "\nCommand '{}' completed for {} recipes.", @@ -267,6 +271,22 @@ fn repo_inner( }) } +fn publish_packages(recipe_names: &Vec, repo_path: &PathBuf) -> anyhow::Result<()> { + let repo_bin = env::current_exe()?.parent().unwrap().join("repo_builder"); + let mut command = Command::new(repo_bin); + command + .arg(repo_path) + .args(recipe_names.iter().filter_map(|n| { + if !n.is_deps { + Some(n.name.as_str()) + } else { + None + } + })); + + run_command(command, &None).map_err(|e| anyhow!(e)) +} + fn parse_args(args: Vec) -> anyhow::Result<(CliConfig, CliCommand, Vec)> { let mut config = CliConfig::new()?; let mut command: Option = None; diff --git a/src/bin/repo_builder.rs b/src/bin/repo_builder.rs index 4748560e8..41bd53fa2 100644 --- a/src/bin/repo_builder.rs +++ b/src/bin/repo_builder.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use cookbook::WALK_DEPTH; use pkg::{Package, PackageName, recipes}; use std::collections::{BTreeMap, HashMap}; @@ -25,6 +26,11 @@ fn main() -> Result<(), Box> { let repo_dir = args .next() .expect("Usage: repo_builder ..."); + Ok(publish_packages(args.collect(), repo_dir)?) +} + +// TODO: Make this callable from repo bin +fn publish_packages(recipe_list: Vec, repo_dir: String) -> anyhow::Result<()> { let repo_path = Path::new(&repo_dir); if !repo_path.is_dir() { fs::create_dir_all(repo_path)?; @@ -36,7 +42,10 @@ fn main() -> Result<(), Box> { // The following adds the package dependencies of the recipes to the repo as // well. let recipe_list = Package::new_recursive( - &args.map(PackageName::new).collect::, _>>()?, + &recipe_list + .iter() + .map(PackageName::new) + .collect::, _>>()?, WALK_DEPTH, )? .into_iter() @@ -111,7 +120,7 @@ fn main() -> Result<(), Box> { .status()? .success() .then_some(()) - .ok_or("appstreamcli failed")?; + .ok_or(anyhow!("appstreamcli failed"))?; Command::new("pkgar") .arg("create") @@ -123,7 +132,7 @@ fn main() -> Result<(), Box> { .status()? .success() .then_some(()) - .ok_or("pkgar create failed")?; + .ok_or(anyhow!("pkgar create failed"))?; } }