build: first implementation
All checks were successful
CI / build (push) Successful in 1m38s

wrap around dpkg-buildpackage
This commit is contained in:
2025-12-01 20:56:50 +01:00
parent 4e7f447326
commit 2bd59b4556
3 changed files with 35 additions and 0 deletions

26
src/build.rs Normal file
View File

@@ -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<dyn Error>> {
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.
}

View File

@@ -1,3 +1,4 @@
pub mod build;
pub mod package_info;
pub mod pull;

View File

@@ -49,6 +49,7 @@ fn main() {
.arg(arg!(--backport "This changelog is for a backport entry").required(false))
.arg(arg!(-v --version <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`"),
}
}