From 2bd59b45568d22b753b9133b75fd4fef81f67f25 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Mon, 1 Dec 2025 20:56:50 +0100 Subject: [PATCH] build: first implementation wrap around dpkg-buildpackage --- src/build.rs | 26 ++++++++++++++++++++++++++ src/lib.rs | 1 + src/main.rs | 8 ++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/build.rs diff --git a/src/build.rs b/src/build.rs new file mode 100644 index 0000000..24ffb4f --- /dev/null +++ b/src/build.rs @@ -0,0 +1,26 @@ +use std::error::Error; +use std::path::Path; +use std::process::Command; + +pub fn build_source_package(cwd: Option<&Path>) -> Result<(), Box> { + let cwd = cwd.unwrap_or_else(|| Path::new(".")); + + let status = Command::new("dpkg-buildpackage") + .current_dir(cwd) + .args(["-S", "-I", "-i", "-d"]) + .status()?; + + if !status.success() { + return Err(format!("dpkg-buildpackage failed with status: {}", status).into()); + } + + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + // We are not testing the build part, as for now this is just a wrapper + // around dpkg-buildpackage. +} diff --git a/src/lib.rs b/src/lib.rs index d7be731..ca7b7a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +pub mod build; pub mod package_info; pub mod pull; diff --git a/src/main.rs b/src/main.rs index ea02a3c..6470122 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,6 +49,7 @@ fn main() { .arg(arg!(--backport "This changelog is for a backport entry").required(false)) .arg(arg!(-v --version "Target version").required(false)), ) + .subcommand(Command::new("build").about("Build the source package")) .get_matches(); match matches.subcommand() { @@ -101,6 +102,13 @@ fn main() { .args(["debian/changelog"]) .status(); } + Some(("build", _sub_matches)) => { + let cwd = std::env::current_dir().unwrap(); + if let Err(e) = pkh::build::build_source_package(Some(&cwd)) { + error!("{}", e); + std::process::exit(1); + } + } _ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"), } }