From 972a9276b3282fb97ef5342c0caad07d480911ad Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Thu, 9 Nov 2023 09:10:51 +0100 Subject: [PATCH] Added build-group command to build a list of packages in topological order --- README.md | 17 +++++++++++++++++ src/cmds/build.rs | 16 ++++++++++++---- src/cmds/mod.rs | 2 +- src/main.rs | 25 +++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4e3a3fc..e927533 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,23 @@ cabin help build-all > -v allows the build log to be toggled on and off > -h, --help Print help +### Build Group +Allows building multiple packages in topologically sorted order. +```sh +cabin build-group [...packages] +``` + +> Builds multiple packages from a list +> Usage: cabin build-group [OPTIONS] [PACKAGES]... +> Arguments: +> [PACKAGES]... list of packages to be build +> Options: +> -a, --arch build the package for a target architecture requires abuild-rootbld and qemu-binfmt to be installed (for the given architecture) and the .rootbld-repositories file to be configured correctly (even if set to host architecture) +> -d, --db package database path +> -v allows the build log to be toggled on and off +> -h, --help Print help + + ### Tree ```sh cabin help tree diff --git a/src/cmds/build.rs b/src/cmds/build.rs index 814e6f3..3dd35ba 100644 --- a/src/cmds/build.rs +++ b/src/cmds/build.rs @@ -102,18 +102,26 @@ pub fn build(name: PackageName, db: Option, arch: Option, build build_package(&name, &db, &arch, verbose); } } -/// attempts to build every package and its dependencies from the repo -pub fn build_all(db: Option, arch: Option, verbose:bool) { +/// attempts to build every package from the list +/// tries to autodetect the order in which the packages need to be build +pub fn build_multi(names: Vec, db: Option, arch: Option, verbose: bool) { let db = Database::from_file(db.unwrap_or(PathBuf::from("db.yml"))) .expect("Unable to open database"); - let tasks = super::tree::topological_sort(db.packages.keys().map(|s|s.to_string()).collect(), &db) + let tasks = super::tree::topological_sort(names, &db) .expect("Unable to resolve dependencies, as there is a cycle in the graph"); let num = tasks.len(); - for (i, task) in tasks.iter().enumerate() { println!("Building {} ({}/{})", task, i+1, num); build_package(task, &db, &arch, verbose); } } +/// attempts to build every package and its dependencies from the repo +pub fn build_all(db: Option, arch: Option, verbose:bool) { + let dbpath = db.clone(); + let db = Database::from_file(db.unwrap_or(PathBuf::from("db.yml"))) + .expect("Unable to open database"); + + build_multi(db.packages.keys().map(|s|s.to_string()).collect(), dbpath, arch, verbose); +} diff --git a/src/cmds/mod.rs b/src/cmds/mod.rs index d1aa173..249c9c5 100644 --- a/src/cmds/mod.rs +++ b/src/cmds/mod.rs @@ -6,5 +6,5 @@ mod tree; pub use scan::scan; pub use list::list; pub use info::info; -pub use build::{build, build_all}; +pub use build::{build, build_all, build_multi}; pub use tree::tree; diff --git a/src/main.rs b/src/main.rs index c390e2a..3c419ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,6 +37,24 @@ enum Commands { #[arg(short='v', default_value="false")] verbose: bool }, + /// Builds multiple packages from a list + BuildGroup { + /// build the package for a target architecture + /// requires abuild-rootbld and qemu-binfmt to be installed + /// (for the given architecture) + /// and the .rootbld-repositories file to be configured correctly + /// (even if set to host architecture) + #[arg(short='a',long)] + arch: Option, + /// package database path + #[arg(short='d',long)] + db: Option, + /// allows the build log to be toggled on and off + #[arg(short='v', default_value="false")] + verbose: bool, + /// list of packages to be build + packages: Vec + }, /// Builds the package Build { /// the packagename @@ -107,6 +125,13 @@ fn main() { Commands::List { db } => cmds::list(db), Commands::Info { package, db, show_depends, show_provides } => cmds::info(package, db, show_provides, show_depends), Commands::Build { package, db, arch, no_build_dependencies, verbose } => cmds::build(package, db, arch, !no_build_dependencies, verbose), + Commands::BuildGroup { packages, db, arch, verbose } => { + if packages.len() == 0 { + println!("Nothing do be done"); + } else { + cmds::build_multi(packages, db, arch, verbose); + } + }, Commands::Tree { package, db, only_local } => cmds::tree(package, db, only_local), Commands::BuildAll { arch, db, verbose } => cmds::build_all(db, arch, verbose), _ => panic!("Unimplemented") -- 2.38.5