/// Sbuild binary package building /// Call 'sbuild' with the dsc file to build the package with unshare use crate::context; use std::error::Error; use std::path::{Path, PathBuf}; fn find_dsc_file(cwd: &Path, package: &str, version: &str) -> Result> { let parent = cwd.parent().ok_or("Cannot find parent directory")?; // Strip epoch from version (e.g., "1:2.3.4-5" -> "2.3.4-5") let version_without_epoch = version.split_once(':').map(|(_, v)| v).unwrap_or(version); let dsc_name = format!("{}_{}.dsc", package, version_without_epoch); let dsc_path = parent.join(&dsc_name); if !dsc_path.exists() { return Err(format!("Could not find .dsc file at {}", dsc_path.display()).into()); } Ok(dsc_path) } pub fn build( cwd: &Path, package: &str, version: &str, arch: &str, series: &str, build_root: &str, cross: bool, ) -> Result<(), Box> { let dsc_path = find_dsc_file(cwd, package, version)?; let ctx = context::current(); let mut cmd = ctx.command("sbuild"); cmd.arg("--chroot-mode=unshare"); if cross { cmd.arg(format!("--host={}", arch)); } else { cmd.arg(format!("--arch={}", arch)); } cmd.arg(format!("--dist={}", series)); // Add output directory argument cmd.arg(format!("--build-dir={}", build_root)); let status = cmd.arg(dsc_path).status()?; if !status.success() { return Err(format!("sbuild failed with status: {}", status).into()); } Ok(()) }