~comcloudway/cabin

972a9276b3282fb97ef5342c0caad07d480911ad — Jakob Meier 10 months ago 9e7ba1e
Added build-group command to build a list of packages
in topological order
4 files changed, 55 insertions(+), 5 deletions(-)

M README.md
M src/cmds/build.rs
M src/cmds/mod.rs
M src/main.rs
M README.md => README.md +17 -0
@@ 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 <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 <DB>      package database path
>   -v                 allows the build log to be toggled on and off
>   -h, --help         Print help


### Tree
```sh
cabin help tree

M src/cmds/build.rs => src/cmds/build.rs +12 -4
@@ 102,18 102,26 @@ pub fn build(name: PackageName, db: Option<PathBuf>, arch: Option<String>, build
        build_package(&name, &db, &arch, verbose);
    }
}
/// attempts to build every package and its dependencies from the repo
pub fn build_all(db: Option<PathBuf>, arch: Option<String>, 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<PackageName>, db: Option<PathBuf>, arch: Option<String>, 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<PathBuf>, arch: Option<String>, 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);
}

M src/cmds/mod.rs => src/cmds/mod.rs +1 -1
@@ 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;

M src/main.rs => src/main.rs +25 -0
@@ 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<String>,
        /// package database path
        #[arg(short='d',long)]
        db: Option<PathBuf>,
        /// 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<String>
    },
    /// 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")