deb: make tests parallel
This commit is contained in:
+14
-12
@@ -1,5 +1,4 @@
|
||||
use crate::context;
|
||||
use crate::context::{Context, ContextConfig};
|
||||
use crate::context::{self, Context, ContextConfig};
|
||||
use directories::ProjectDirs;
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
@@ -14,24 +13,26 @@ pub struct EphemeralContextGuard {
|
||||
previous_context: String,
|
||||
chroot_path: PathBuf,
|
||||
build_succeeded: bool,
|
||||
base_ctx: Arc<Context>,
|
||||
}
|
||||
|
||||
impl EphemeralContextGuard {
|
||||
/// Create a new ephemeral unshare context for the specified series
|
||||
/// Create a new ephemeral unshare context with an explicit base context
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `series` - The distribution series (e.g., "noble", "sid")
|
||||
/// * `arch` - Optional target architecture. If provided and different from host,
|
||||
/// downloads a chroot for that architecture (uses qemu_binfmt transparently)
|
||||
pub async fn new(series: &str, arch: Option<&str>) -> Result<Self, Box<dyn Error>> {
|
||||
/// * `base_ctx` - The base context to use for creating the chroot
|
||||
pub async fn new_with_context(
|
||||
series: &str,
|
||||
arch: Option<&str>,
|
||||
base_ctx: Arc<Context>,
|
||||
) -> Result<Self, Box<dyn Error>> {
|
||||
let current_context_name = context::manager().current_name();
|
||||
|
||||
// Capture the current context once to avoid race conditions
|
||||
// with other threads modifying the global context state
|
||||
let ctx = context::current();
|
||||
|
||||
// Create a temporary directory for the chroot
|
||||
let chroot_path_str = ctx.create_temp_dir()?;
|
||||
let chroot_path_str = base_ctx.create_temp_dir()?;
|
||||
let chroot_path = PathBuf::from(chroot_path_str);
|
||||
|
||||
log::debug!(
|
||||
@@ -42,7 +43,7 @@ impl EphemeralContextGuard {
|
||||
);
|
||||
|
||||
// Download and extract the chroot tarball
|
||||
Self::download_and_extract_chroot(series, arch, &chroot_path, ctx.clone()).await?;
|
||||
Self::download_and_extract_chroot(series, arch, &chroot_path, base_ctx.clone()).await?;
|
||||
|
||||
// Switch to an ephemeral context to build the package in the chroot
|
||||
context::manager().set_current_ephemeral(Context::new(ContextConfig::Unshare {
|
||||
@@ -54,6 +55,7 @@ impl EphemeralContextGuard {
|
||||
previous_context: current_context_name,
|
||||
chroot_path,
|
||||
build_succeeded: false,
|
||||
base_ctx,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -309,13 +311,13 @@ impl Drop for EphemeralContextGuard {
|
||||
let is_root = crate::utils::root::is_root().unwrap_or(false);
|
||||
|
||||
let result = if is_root {
|
||||
context::current()
|
||||
self.base_ctx
|
||||
.command("rm")
|
||||
.arg("-rf")
|
||||
.arg(&self.chroot_path)
|
||||
.status()
|
||||
} else {
|
||||
context::current()
|
||||
self.base_ctx
|
||||
.command("sudo")
|
||||
.arg("rm")
|
||||
.arg("-rf")
|
||||
|
||||
Reference in New Issue
Block a user