exp: cross #6

This commit is contained in:
2025-12-22 23:08:44 +01:00
parent 63389f0bad
commit 3ecfe6dda2
6 changed files with 101 additions and 16 deletions

View File

@@ -103,3 +103,45 @@ fn find_dsc_file(
}
Ok(dsc_path)
}
#[cfg(test)]
mod tests {
async fn test_build_end_to_end(package: &str, series: &str, arch: Option<&str>, cross: bool) {
let temp_dir = tempfile::tempdir().unwrap();
let cwd = temp_dir.path();
crate::pull::pull(
package,
"",
Some(series),
"",
"",
Some("ubuntu"),
Some(cwd),
None,
)
.await
.expect("Cannot pull package");
// Change directory to the package directory
let cwd = cwd.join(package).join(package);
crate::deb::build_binary_package(arch, Some(series), Some(&cwd), cross, None)
.expect("Cannot build binary package (deb)");
// Check that the .deb files are present
let parent_dir = cwd.parent().expect("Cannot find parent directory");
let deb_files = std::fs::read_dir(parent_dir)
.expect("Cannot read build directory")
.filter_map(|entry| entry.ok())
.filter(|entry| entry.path().extension().is_some_and(|ext| ext == "deb"))
.collect::<Vec<_>>();
assert!(!deb_files.is_empty(), "No .deb files found after build");
}
#[tokio::test]
async fn test_deb_hello_ubuntu_end_to_end() {
test_build_end_to_end("hello", "noble", None, false).await;
}
}

View File

@@ -1,21 +1,19 @@
/// Sbuild binary package building
/// Call 'sbuild' with the dsc file to build the package with unshare
use crate::context;
use crate::deb::find_dsc_file;
use std::error::Error;
pub fn build(
package: &str,
version: &str,
_version: &str,
arch: &str,
series: &str,
build_root: &str,
cross: bool,
) -> Result<(), Box<dyn Error>> {
let dsc_path = find_dsc_file(build_root, package, version)?;
let ctx = context::current();
let mut cmd = ctx.command("sbuild");
cmd.current_dir(format!("{}/{}", build_root, package));
cmd.arg("--chroot-mode=unshare");
if cross {
@@ -28,8 +26,7 @@ pub fn build(
// Add output directory argument
cmd.arg(format!("--build-dir={}", build_root));
let status = cmd.arg(dsc_path).status()?;
let status = cmd.status()?;
if !status.success() {
return Err(format!("sbuild failed with status: {}", status).into());
}