build,debian: extract reusable Debian format primitives from build/
Move the generic components out of src/build/ into a new src/debian/ module so they can be reused independently of the build pipeline: deb822 control parsing (plus the debian/control model), file checksum registry, debian/files registry, Debian version handling and changelog entry parsing. Merge OpenPGP clearsigning into utils/gpg.rs next to the existing key discovery helper, making signing available outside of builds. Delegate changelog.rs header/footer parsing to the new debian::changelog parser, removing the duplicate regex implementation. src/build/ keeps only build-specific logic: the pipeline driver, build types, environment setup and the .buildinfo/.changes writers.
This commit is contained in:
+10
-27
@@ -9,22 +9,16 @@
|
||||
pub mod buildinfo;
|
||||
pub mod buildtype;
|
||||
pub mod changes;
|
||||
pub mod checksums;
|
||||
pub mod control;
|
||||
pub mod env;
|
||||
pub mod files;
|
||||
pub mod metadata;
|
||||
pub mod sign;
|
||||
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::error::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
use checksums::{Entry as ChecksumEntry, FileChecksums};
|
||||
use control::parse_paragraphs;
|
||||
use files::{FilesEntry, FilesList};
|
||||
use metadata::ControlInfo;
|
||||
use crate::debian::{
|
||||
parse_paragraphs, ChecksumEntry, ControlInfo, FileChecksums, FilesEntry, FilesList,
|
||||
};
|
||||
|
||||
/// Options for a native source-package build.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -114,7 +108,7 @@ pub fn run_source_build(
|
||||
// ------------------------------------------------------------------
|
||||
// 2. Metadata resolution
|
||||
// ------------------------------------------------------------------
|
||||
let entry = metadata::parse_changelog_entry(&changelog_path)?;
|
||||
let entry = crate::debian::parse_changelog_entry(&changelog_path)?;
|
||||
let ctrl = ControlInfo::parse(&control_path)?;
|
||||
|
||||
log::info!("source package {}", entry.source);
|
||||
@@ -346,22 +340,22 @@ pub fn run_source_build(
|
||||
// ------------------------------------------------------------------
|
||||
let mut signed = false;
|
||||
if let Some(keyid) = signing_key.filter(|_| do_sign) {
|
||||
sign::validate_key_id(&keyid)?;
|
||||
crate::utils::gpg::validate_key_id(&keyid)?;
|
||||
|
||||
println!("signfile {}", dsc_name);
|
||||
sign::clearsign_file(&dsc_path, &keyid)?;
|
||||
crate::utils::gpg::clearsign_file(&dsc_path, &keyid)?;
|
||||
// The .dsc changed: refresh its checksums inside the .buildinfo.
|
||||
checksums.add_file_as(&dsc_path, &dsc_name)?;
|
||||
buildinfo::save_buildinfo(&buildinfo_path, &render_buildinfo_doc(&checksums))?;
|
||||
|
||||
println!("signfile {}", buildinfo_name);
|
||||
sign::clearsign_file(&buildinfo_path, &keyid)?;
|
||||
crate::utils::gpg::clearsign_file(&buildinfo_path, &keyid)?;
|
||||
// Both .dsc and .buildinfo changed: refresh the .changes.
|
||||
checksums.add_file_as(&buildinfo_path, &buildinfo_name)?;
|
||||
changes::save_changes(&changes_path, &render_changes_doc(&checksums))?;
|
||||
|
||||
println!("signfile {}", changes_name);
|
||||
sign::clearsign_file(&changes_path, &keyid)?;
|
||||
crate::utils::gpg::clearsign_file(&changes_path, &keyid)?;
|
||||
|
||||
signed = true;
|
||||
}
|
||||
@@ -418,13 +412,10 @@ fn run_command(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Re-export commonly used types at the module root.
|
||||
pub use metadata::{ChangelogEntry, DebianVersion};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use buildtype::BuildType;
|
||||
use crate::debian::DebianVersion;
|
||||
|
||||
#[test]
|
||||
fn partial_checksum_defaults() {
|
||||
@@ -434,16 +425,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn debian_version_reexport_usable() {
|
||||
fn debian_version_from_debian_module_usable() {
|
||||
let v = DebianVersion::parse("1.0-2").unwrap();
|
||||
assert_eq!(v.no_epoch(), "1.0-2");
|
||||
}
|
||||
|
||||
// The full pipeline is exercised end-to-end by running pkh against a
|
||||
// fixture package; unit tests cover the individual stages above.
|
||||
#[test]
|
||||
fn build_type_source_only_pipeline_mapping() {
|
||||
// Source-only builds always map to the 'source' artifact suffix.
|
||||
assert_eq!(buildtype::SOURCE.arch_suffix("amd64"), "source");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user