Compare commits

..

3 Commits

Author SHA1 Message Date
2b27b7b06e deb: add quirks to allow packages to declare specific package directories
All checks were successful
CI / build (push) Successful in 8m41s
CI / snap (push) Successful in 3m55s
2026-03-25 17:40:55 +01:00
32e15b1106 deb: ignore linux-riscv test
Some checks failed
CI / build (push) Successful in 8m16s
CI / snap (push) Failing after 7s
2026-03-19 11:27:02 +01:00
7640952bdc unshare: mount proc differently depending on root privileges 2026-03-19 11:26:10 +01:00
4 changed files with 69 additions and 0 deletions

View File

@@ -12,3 +12,8 @@ quirks:
# - another-dependency # - another-dependency
# parameters: # parameters:
# key: value # key: value
linux-riscv:
deb:
package_directory:
- linux-main

View File

@@ -352,6 +352,18 @@ impl Drop for EphemeralContextGuard {
// Check if we're running as root to avoid unnecessary sudo // Check if we're running as root to avoid unnecessary sudo
let is_root = crate::utils::root::is_root().unwrap_or(false); let is_root = crate::utils::root::is_root().unwrap_or(false);
// Unmount /proc from chroot before removing (ignore errors)
let proc_path = self.chroot_path.join("proc");
let _ = if is_root {
self.base_ctx.command("umount").arg(&proc_path).status()
} else {
self.base_ctx
.command("sudo")
.arg("umount")
.arg(&proc_path)
.status()
};
let result = if is_root { let result = if is_root {
self.base_ctx self.base_ctx
.command("rm") .command("rm")

View File

@@ -142,12 +142,26 @@ pub async fn build_binary_package(
/// Find the current package directory by trying both patterns: /// Find the current package directory by trying both patterns:
/// - package/package /// - package/package
/// - package/package-origversion /// - package/package-origversion
/// - custom directories from quirks configuration
pub(crate) fn find_package_directory( pub(crate) fn find_package_directory(
parent_dir: &Path, parent_dir: &Path,
package: &str, package: &str,
version: &str, version: &str,
ctx: &context::Context, ctx: &context::Context,
) -> Result<PathBuf, Box<dyn Error>> { ) -> Result<PathBuf, Box<dyn Error>> {
// Check quirks first for custom package directories
let custom_dirs = crate::quirks::get_package_directories(package);
for custom_dir in custom_dirs {
let package_dir = parent_dir.join(&custom_dir);
if ctx.exists(&package_dir)? && ctx.exists(&package_dir.join("debian"))? {
log::debug!(
"Found package directory via quirks: {}",
package_dir.display()
);
return Ok(package_dir);
}
}
// Try package/package pattern first // Try package/package pattern first
let package_dir = parent_dir.join(package).join(package); let package_dir = parent_dir.join(package).join(package);
if ctx.exists(&package_dir)? && ctx.exists(&package_dir.join("debian"))? { if ctx.exists(&package_dir)? && ctx.exists(&package_dir.join("debian"))? {
@@ -344,6 +358,10 @@ mod tests {
/// It is important to ensure that pkh can cross-compile linux-riscv, as /// It is important to ensure that pkh can cross-compile linux-riscv, as
/// for risc-v hardware is still rare and cross-compilation is necessary /// for risc-v hardware is still rare and cross-compilation is necessary
/// to debug and test /// to debug and test
/// NOTE: Ideally, we want to run this in CI, but it takes more than 1h
/// to fully build the linux-riscv package on an amd64 builder, which is too
/// much time
#[ignore]
#[tokio::test] #[tokio::test]
#[test_log::test] #[test_log::test]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]

View File

@@ -17,6 +17,12 @@ pub struct OperationQuirks {
/// Additional parameters for the operation /// Additional parameters for the operation
#[serde(default)] #[serde(default)]
pub parameters: HashMap<String, serde_yaml::Value>, pub parameters: HashMap<String, serde_yaml::Value>,
/// Custom package directories to try when looking for the package source
/// This is useful for packages that don't follow the standard naming conventions
/// like linux packages that use directories like "linux-main" or other custom names
#[serde(default)]
pub package_directory: Vec<String>,
} }
/// Quirks for a specific package /// Quirks for a specific package
@@ -75,3 +81,31 @@ pub fn get_deb_extra_dependencies(package: &str) -> Vec<String> {
Vec::new() Vec::new()
} }
/// Get package directories from quirks configuration
///
/// This function returns the list of custom package directories to try
/// when looking for the package source directory.
///
/// # Arguments
/// * `package` - The package name
///
/// # Returns
/// * `Vec<String>` - List of package directories to try, or empty vector if none
pub fn get_package_directories(package: &str) -> Vec<String> {
if let Some(quirks) = get_package_quirks(&QUIRKS_DATA, package) {
// Check deb quirks first, then pull quirks
if let Some(deb_quirks) = &quirks.deb
&& !deb_quirks.package_directory.is_empty()
{
return deb_quirks.package_directory.clone();
}
if let Some(pull_quirks) = &quirks.pull
&& !pull_quirks.package_directory.is_empty()
{
return pull_quirks.package_directory.clone();
}
}
Vec::new()
}