From cc7cbaaa8fffe76b332d250e510a0cfd648a6517 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Sat, 22 Aug 2026 12:31:30 +0200 Subject: [PATCH] deb: apply quilt patches before building --- src/deb/local.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/deb/local.rs b/src/deb/local.rs index 02c98ce..de0b0af 100644 --- a/src/deb/local.rs +++ b/src/deb/local.rs @@ -198,6 +198,9 @@ pub async fn build( .to_str() .ok_or("Invalid package directory path")?; + // Apply quilt patches if the package provides a patch series + apply_quilt_patches(package_dir_str, &env, ctx.clone())?; + // Install injected packages if specified if let Some(packages) = inject_packages { install_injected_packages(packages, &env, ctx.clone())?; @@ -268,6 +271,66 @@ pub async fn build( Ok(()) } +/// Apply quilt patches before building, if the package provides a +/// 'debian/patches/series' file +fn apply_quilt_patches( + package_dir: &str, + env: &HashMap, + ctx: Arc, +) -> Result<(), Box> { + let series_path = Path::new(package_dir).join("debian/patches/series"); + if !ctx.exists(&series_path)? { + log::debug!( + "No '{}' found, skipping quilt patch application", + series_path.display() + ); + return Ok(()); + } + + // Skip patch application if the series file contains no patches + let series_content = ctx.read_file(&series_path)?; + let has_patches = series_content + .lines() + .any(|line| !line.trim().is_empty() && !line.trim().starts_with('#')); + if !has_patches { + log::debug!( + "'{}' contains no patches, skipping quilt patch application", + series_path.display() + ); + return Ok(()); + } + + // Make sure quilt is available in the build context + log::debug!("Installing quilt for patch application..."); + let status = ctx + .command("apt-get") + .envs(env.clone()) + .arg("-y") + .arg("install") + .arg("quilt") + .status()?; + if !status.success() { + return Err("Could not install 'quilt', required to apply patches".into()); + } + + // Apply all patches listed in the series + log::info!("Applying quilt patches from debian/patches/series..."); + let mut patch_env = env.clone(); + patch_env.insert("QUILT_PATCHES".to_string(), "debian/patches".to_string()); + let status = ctx + .command("quilt") + .current_dir(package_dir) + .envs(patch_env) + .arg("push") + .arg("-a") + .status()?; + if !status.success() { + return Err("Failed to apply quilt patches ('quilt push -a')".into()); + } + + Ok(()) +} + fn install_injected_packages( packages: &[&str], env: &HashMap,