diff --git a/quirks.yml b/quirks.yml new file mode 100644 index 0000000..d4ccc40 --- /dev/null +++ b/quirks.yml @@ -0,0 +1,14 @@ +# Quirks configuration for package-specific workarounds +# This file defines package-specific quirks that are applied during pull and deb operations + +quirks: + + # Add more packages and their quirks as needed + # example-package: + # pull: + # method: archive + # deb: + # extra_dependencies: + # - another-dependency + # parameters: + # key: value diff --git a/src/deb/local.rs b/src/deb/local.rs index 4c87251..183ec74 100644 --- a/src/deb/local.rs +++ b/src/deb/local.rs @@ -185,22 +185,22 @@ pub async fn build( return Err("Could not install build-dependencies for the build".into()); } - // // Install arch-independant build dependencies - // log::debug!("Installing arch-independant build dependencies..."); - // let status = ctx.command("apt-get") - // .current_dir(package_dir_str) - // .envs(env.clone()) - // .arg("-y") - // .arg("build-dep") - // .arg("--indep-only") - // .arg("./") - // .status()?; + // Install arch-independant build dependencies + log::debug!("Installing arch-independant build dependencies..."); + let status = ctx + .command("apt-get") + .current_dir(package_dir_str) + .envs(env.clone()) + .arg("-y") + .arg("build-dep") + .arg("./") + .status()?; - // // If build-dep fails, we try to explain the failure using dose-debcheck - // if !status.success() { - // dose3_explain_dependencies(package, version, arch, build_root, cross)?; - // return Err("Could not install build-dependencies for the build".into()); - // } + // If build-dep fails, we try to explain the failure using dose-debcheck + if !status.success() { + dose3_explain_dependencies(package, version, arch, build_root, cross)?; + return Err("Could not install build-dependencies for the build".into()); + } // Run the build step log::debug!("Building (debian/rules build) package..."); @@ -260,6 +260,7 @@ fn dose3_explain_dependencies( } // Transform the dsc file into a 'Source' stanza (replacing 'Source' with 'Package') + // TODO: Remove potential GPG headers/signature let dsc_path = find_dsc_file(build_root, package, version)?; let mut dsc_content = ctx.read_file(&dsc_path)?; dsc_content = dsc_content.replace("Source", "Package"); diff --git a/src/deb/mod.rs b/src/deb/mod.rs index 60d3aa4..f40d44d 100644 --- a/src/deb/mod.rs +++ b/src/deb/mod.rs @@ -288,6 +288,17 @@ mod tests { test_build_end_to_end("hello", "sid", None, None, false).await; } + /// This is a specific test case for the linux-riscv package on Ubuntu + /// 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 + /// to debug and test + #[tokio::test] + #[test_log::test] + #[cfg(target_arch = "x86_64")] + async fn test_deb_linux_riscv_ubuntu_cross_end_to_end() { + test_build_end_to_end("linux-riscv", "questing", None, Some("riscv64"), true).await; + } + /// This is a specific test case for the latest gcc package on Debian /// The GCC package is complex and hard to build, with specific stages /// and system-bound scripts. Building it requires specific things that diff --git a/src/lib.rs b/src/lib.rs index e5ac7ba..e926df3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,8 @@ pub mod distro_info; pub mod package_info; /// Download a source package locally pub mod pull; +/// Handle package-specific quirks and workarounds +pub mod quirks; /// Handle context for .deb building: locally, over ssh, in a chroot... pub mod context; diff --git a/src/quirks.rs b/src/quirks.rs new file mode 100644 index 0000000..1a32a28 --- /dev/null +++ b/src/quirks.rs @@ -0,0 +1,77 @@ +//! Quirks module for handling package-specific workarounds +//! +//! This module provides functionality to read quirks from a YAML file +//! and apply them during pull and deb operations. + +use lazy_static::lazy_static; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +/// Quirks configuration for a specific operation (pull or deb) +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct OperationQuirks { + /// Extra dependencies to install before the operation + #[serde(default)] + pub extra_dependencies: Vec, + + /// Additional parameters for the operation + #[serde(default)] + pub parameters: HashMap, +} + +/// Quirks for a specific package +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct PackageQuirks { + /// Quirks to apply during pull operation + #[serde(default)] + pub pull: Option, + + /// Quirks to apply during deb operation + #[serde(default)] + pub deb: Option, +} + +/// Top-level quirks configuration +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct QuirksConfig { + /// Map of package names to their quirks + pub quirks: HashMap, +} + +const QUIRKS_YAML: &str = include_str!("../quirks.yml"); +lazy_static! { + static ref QUIRKS_DATA: QuirksConfig = serde_yaml::from_str(QUIRKS_YAML).unwrap(); +} + +/// Get quirks for a specific package +/// +/// # Arguments +/// * `config` - The quirks configuration +/// * `package` - The package name +/// +/// # Returns +/// * `Option` - The quirks for the package, or None if not found +pub fn get_package_quirks<'a>( + config: &'a QuirksConfig, + package: &str, +) -> Option<&'a PackageQuirks> { + config.quirks.get(package) +} + +/// Get deb-time extra dependencies for a package +/// +/// This function returns the list of extra dependencies that should be installed +/// before building a package, as defined in the quirks configuration. +/// +/// # Arguments +/// * `package` - The package name +/// +/// # Returns +/// * `Vec` - List of extra dependencies, or empty vector if none +pub fn get_deb_extra_dependencies(package: &str) -> Vec { + if let Some(quirks) = &get_package_quirks(&QUIRKS_DATA, package).unwrap().deb { + return quirks.extra_dependencies.clone(); + } + + Vec::new() +}