build: record the actual build environment in .buildinfo
The binary build exported DEB_BUILD_OPTIONS='parallel=<context nproc> nocheck' (or the -j override) but the generated .buildinfo recomputed the environment from host state: host core count, no nocheck, and vendor profiles that ignored DEB_BUILD_PROFILES (a cross build recorded no 'cross' profile). generate_binary_metadata now records the exact env map that was exported to the build steps, and the recorded profiles come from the exported DEB_BUILD_PROFILES when set. Also unifies vendor parsing on one helper (the context-side copy lacked the Origin: fallback of the source-build path).
This commit is contained in:
+27
-3
@@ -60,11 +60,16 @@ pub fn arch_env(host_arch: Option<&str>) -> Result<BTreeMap<String, String>, Str
|
||||
/// Read the current vendor name from `/etc/dpkg/origins/default`
|
||||
/// (its `Vendor:` or `Origin:` field), defaulting to `"debian"`.
|
||||
pub fn current_vendor() -> String {
|
||||
read_vendor_from(Path::new("/etc/dpkg/origins/default")).unwrap_or_else(|| "debian".to_string())
|
||||
std::fs::read_to_string(Path::new("/etc/dpkg/origins/default"))
|
||||
.ok()
|
||||
.and_then(|content| vendor_from_origins_content(&content))
|
||||
.unwrap_or_else(|| "debian".to_string())
|
||||
}
|
||||
|
||||
fn read_vendor_from(path: &Path) -> Option<String> {
|
||||
let content = std::fs::read_to_string(path).ok()?;
|
||||
/// Extract the vendor name from the content of a dpkg origins file: its
|
||||
/// `Vendor:` field, falling back to `Origin:` when absent. `None` when
|
||||
/// neither field carries a non-empty value.
|
||||
pub fn vendor_from_origins_content(content: &str) -> Option<String> {
|
||||
for line in content.lines() {
|
||||
if let Some(value) = line.strip_prefix("Vendor:") {
|
||||
let v = value.trim();
|
||||
@@ -282,6 +287,25 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vendor_from_origins_content_prefers_vendor_then_origin() {
|
||||
assert_eq!(
|
||||
vendor_from_origins_content("Vendor: Ubuntu\nSuite: noble\n"),
|
||||
Some("Ubuntu".to_string())
|
||||
);
|
||||
// Origin fallback when no Vendor field is present.
|
||||
assert_eq!(
|
||||
vendor_from_origins_content("Origin: Debian\nSuite: stable\n"),
|
||||
Some("Debian".to_string())
|
||||
);
|
||||
// Empty Vendor falls through to Origin.
|
||||
assert_eq!(
|
||||
vendor_from_origins_content("Vendor: \nOrigin: Debian\n"),
|
||||
Some("Debian".to_string())
|
||||
);
|
||||
assert_eq!(vendor_from_origins_content("Suite: stable\n"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn environment_escaping() {
|
||||
// The function reads the process env; just verify formatting helpers
|
||||
|
||||
Reference in New Issue
Block a user