~comcloudway/cabin

b81e362e050c9bfa7657ce8a20cae513c8ac0cad — Jakob Meier 10 months ago 8d84b6e main
Added --run-after to multi package build

runs the named script after successfully building a package
3 files changed, 24 insertions(+), 9 deletions(-)

M Cargo.toml
M src/cmds/build.rs
M src/main.rs
M Cargo.toml => Cargo.toml +1 -1
@@ 3,7 3,7 @@ name = "cabin"
description = "Simple alpine package builder with dependency resolution using abuild"
authors = [ "Jakob Meier <comcloudway@ccw.icu>" ]
license = "GPL-3.0-or-later"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

M src/cmds/build.rs => src/cmds/build.rs +10 -3
@@ 104,7 104,7 @@ pub fn build(name: PackageName, db: Option<PathBuf>, arch: Option<String>, build
}
/// 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) {
pub fn build_multi(names: Vec<PackageName>, db: Option<PathBuf>, arch: Option<String>, verbose: bool, run_after: Option<String>) {
    let db = Database::from_file(db.unwrap_or(PathBuf::from("db.yml")))
        .expect("Unable to open database");



@@ 115,13 115,20 @@ pub fn build_multi(names: Vec<PackageName>, db: Option<PathBuf>, arch: Option<St
    for (i, task) in tasks.iter().enumerate() {
        println!("Building {} ({}/{})", task, i+1, num);
        build_package(task, &db, &arch, verbose);
        // run command after building a package
        if let Some(cmd) = &run_after {
            Command::new(cmd.to_string())
                .arg(task)
                .output()
                .expect("failed to execute process");
        }
    }
}
/// attempts to build every package and its dependencies from the repo
pub fn build_all(db: Option<PathBuf>, arch: Option<String>, verbose:bool) {
pub fn build_all(db: Option<PathBuf>, arch: Option<String>, verbose:bool, run_after: Option<String>) {
    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);
    build_multi(db.packages.keys().map(|s|s.to_string()).collect(), dbpath, arch, verbose, run_after);
}

M src/main.rs => src/main.rs +13 -5
@@ 35,7 35,11 @@ enum Commands {
        db: Option<PathBuf>,
        /// allows the build log to be toggled on and off
        #[arg(short='v', default_value="false")]
        verbose: bool
        verbose: bool,
        /// run command after building a package
        /// calls $cmd $pkgname
        #[arg(long)]
        run_after: Option<String>
    },
    /// Builds multiple packages from a list
    BuildGroup {


@@ 53,7 57,11 @@ enum Commands {
        #[arg(short='v', default_value="false")]
        verbose: bool,
        /// list of packages to be build
        packages: Vec<String>
        packages: Vec<String>,
        /// run command after building a package
        /// calls $cmd $pkgname
        #[arg(long)]
        run_after: Option<String>
    },
    /// Builds the package
    Build {


@@ 125,15 133,15 @@ 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 } => {
        Commands::BuildGroup { packages, db, arch, verbose, run_after } => {
            if packages.len() == 0 {
                println!("Nothing do be done");
            } else {
                cmds::build_multi(packages, db, arch, verbose);
                cmds::build_multi(packages, db, arch, verbose, run_after);
            }
        },
        Commands::Tree { package, db, only_local } => cmds::tree(package, db, only_local),
        Commands::BuildAll { arch, db, verbose } => cmds::build_all(db, arch, verbose),
        Commands::BuildAll { arch, db, verbose, run_after } => cmds::build_all(db, arch, verbose, run_after),
        Commands::Search { query, db } => cmds::search(query, db)
    }
}