build: live view for source builds, pin LC_ALL for the pipeline
Route 'pkh build' through the DebUi capture machinery 'pkh deb' already uses instead of letting dpkg-source inherit the terminal: - pin LANG=C and LC_ALL=C so dpkg-source emits deterministic English diagnostics regardless of the session locale; - new DpkgSourceClassifier rewrites info:/warning:/error: lines into colored pane entries, telling benign tar warnings from failures; - DebUi generalizes for reuse (arbitrary phase labels, build-specific log naming); run_source_build() drives phases and pipes subprocess output through the sink when a UI is present; - glyph-free house-style summaries: 'Built in Ns:' plus artifact paths relative to cwd; failures print captured errors + log path; - drop/capitalize pipeline chatter, add 'pkh build --verbose' to bypass the view like 'pkh deb --verbose'.
This commit is contained in:
+135
-24
@@ -15,11 +15,16 @@ pub mod env;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::error::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::context::capture::pump;
|
||||
use crate::context::{LineSink, Stream};
|
||||
use crate::debian::{
|
||||
ChecksumEntry, ControlInfo, FileChecksums, FilesEntry, FilesList, parse_paragraphs,
|
||||
};
|
||||
use crate::ui::deb::DebUi;
|
||||
use crate::ui::logfmt::{DpkgSourceClassifier, GenericClassifier};
|
||||
|
||||
/// Options for a native source-package build.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -52,11 +57,46 @@ pub struct SourceBuildOutput {
|
||||
|
||||
/// Build a Debian source package (to a .dsc) using the native pipeline.
|
||||
///
|
||||
/// Keeps the historical pkh entry-point signature; see [`run_source_build`]
|
||||
/// for the configurable version.
|
||||
pub fn build_source_package(cwd: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
||||
/// When `ui` is set, subprocess output is captured into a live view (status
|
||||
/// bar + rolling pane) and tee'd to a log file; on failure the view prints a
|
||||
/// summary of the last captured errors. Without a UI, commands inherit the
|
||||
/// terminal as before.
|
||||
pub fn build_source_package(
|
||||
cwd: Option<&Path>,
|
||||
ui: Option<Arc<DebUi>>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let cwd = cwd.unwrap_or_else(|| Path::new("."));
|
||||
let output = run_source_build(cwd, &SourceBuildOptions::default())?;
|
||||
let output = match run_source_build(cwd, &SourceBuildOptions::default(), ui.clone()) {
|
||||
Ok(output) => output,
|
||||
Err(e) => {
|
||||
if let Some(u) = &ui {
|
||||
u.finish_failure();
|
||||
}
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
// Artifact listing in dpkg order: dsc → tarballs → buildinfo → changes.
|
||||
let mut artifacts = Vec::with_capacity(3 + output.tarballs.len());
|
||||
artifacts.push(output.dsc.clone());
|
||||
artifacts.extend(output.tarballs.iter().cloned());
|
||||
artifacts.push(output.buildinfo.clone());
|
||||
artifacts.push(output.changes.clone());
|
||||
|
||||
// The live view lists the artifacts itself when it renders; otherwise
|
||||
// (verbose mode or non-TTY stdout) print them as plain lines.
|
||||
let listed = match &ui {
|
||||
Some(u) if u.is_enabled() => {
|
||||
u.finish_success(&artifacts, u.elapsed());
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
if !listed {
|
||||
for artifact in &artifacts {
|
||||
println!(" {}", crate::ui::display_path(artifact));
|
||||
}
|
||||
}
|
||||
|
||||
if output.signed {
|
||||
println!("Package built and signed successfully!");
|
||||
@@ -81,7 +121,9 @@ pub fn build_source_package(cwd: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
||||
pub fn run_source_build(
|
||||
cwd: &Path,
|
||||
opts: &SourceBuildOptions,
|
||||
ui: Option<Arc<DebUi>>,
|
||||
) -> Result<SourceBuildOutput, Box<dyn Error>> {
|
||||
let sink: Option<Arc<dyn LineSink>> = ui.as_ref().map(|u| u.sink());
|
||||
// ------------------------------------------------------------------
|
||||
// 1. Sanity checks
|
||||
// ------------------------------------------------------------------
|
||||
@@ -116,9 +158,9 @@ pub fn run_source_build(
|
||||
let entry = crate::debian::parse_changelog_entry(&changelog_path)?;
|
||||
let ctrl = ControlInfo::parse(&control_path)?;
|
||||
|
||||
log::info!("source package {}", entry.source);
|
||||
log::info!("source version {}", entry.version.full());
|
||||
log::info!("source distribution {}", entry.distribution);
|
||||
if let Some(u) = &ui {
|
||||
u.set_build_target(&entry.source, &entry.version.full(), &entry.distribution);
|
||||
}
|
||||
|
||||
// binNMU builds reference the *previous* (source) version in their
|
||||
// artifact metadata, like dpkg-genchanges/genbuildinfo do.
|
||||
@@ -167,19 +209,19 @@ pub fn run_source_build(
|
||||
if signing_key.is_none() {
|
||||
match crate::utils::gpg::find_signing_key_for_email(&entry.maintainer_email) {
|
||||
Ok(Some(key)) => {
|
||||
log::info!("using GPG key {} for signing", key);
|
||||
log::info!("Using GPG key {} for signing", key);
|
||||
signing_key = Some(key);
|
||||
}
|
||||
Ok(None) => {
|
||||
log::warn!(
|
||||
"no GPG secret key found for {} <{}>, building without signing",
|
||||
"No GPG secret key found for {} <{}>, building without signing",
|
||||
entry.maintainer_name,
|
||||
entry.maintainer_email
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!(
|
||||
"failed to check for GPG key: {}, building without signing",
|
||||
"Failed to check for GPG key: {}, building without signing",
|
||||
e
|
||||
);
|
||||
}
|
||||
@@ -188,7 +230,7 @@ pub fn run_source_build(
|
||||
let do_sign = match &signing_key {
|
||||
None => false,
|
||||
Some(_) if entry.distribution == "UNRELEASED" && !opts.force_sign => {
|
||||
log::warn!("not signing UNRELEASED build; use force_sign to override");
|
||||
log::warn!("Not signing UNRELEASED build; use force_sign to override");
|
||||
false
|
||||
}
|
||||
Some(_) => true,
|
||||
@@ -197,17 +239,24 @@ pub fn run_source_build(
|
||||
// ------------------------------------------------------------------
|
||||
// 5. dpkg-source lifecycle: before-build + source build
|
||||
// ------------------------------------------------------------------
|
||||
if let Some(u) = &ui {
|
||||
u.phase_custom("Applying patches", Box::new(DpkgSourceClassifier::new()));
|
||||
}
|
||||
run_command(
|
||||
cwd,
|
||||
"dpkg-source",
|
||||
&["-I", "-i", "--before-build", "."],
|
||||
&pipeline_env,
|
||||
sink.as_ref(),
|
||||
)?;
|
||||
|
||||
// Build-dependency check (native dpkg-checkbuilddeps equivalent).
|
||||
// dpkg-buildpackage skips it entirely for source-only builds unless
|
||||
// forced with -D; unsatisfied dependencies abort with exit status 3.
|
||||
if opts.force_dep_check {
|
||||
if let Some(u) = &ui {
|
||||
u.progress_message("Checking build dependencies");
|
||||
}
|
||||
let check_opts = crate::debian::deps::CheckOpts {
|
||||
host_arch: arch_vars
|
||||
.get("DEB_HOST_ARCH")
|
||||
@@ -225,7 +274,19 @@ pub fn run_source_build(
|
||||
}
|
||||
}
|
||||
|
||||
run_command(cwd, "dpkg-source", &["-I", "-i", "-b", "."], &pipeline_env)?;
|
||||
if let Some(u) = &ui {
|
||||
u.phase_custom(
|
||||
"Building source package",
|
||||
Box::new(DpkgSourceClassifier::new()),
|
||||
);
|
||||
}
|
||||
run_command(
|
||||
cwd,
|
||||
"dpkg-source",
|
||||
&["-I", "-i", "-b", "."],
|
||||
&pipeline_env,
|
||||
sink.as_ref(),
|
||||
)?;
|
||||
|
||||
if !dsc_path.exists() {
|
||||
return Err(format!(
|
||||
@@ -259,6 +320,9 @@ pub fn run_source_build(
|
||||
// ------------------------------------------------------------------
|
||||
// 6. .buildinfo generation (native dpkg-genbuildinfo equivalent)
|
||||
// ------------------------------------------------------------------
|
||||
if let Some(u) = &ui {
|
||||
u.progress_message("Generating .buildinfo");
|
||||
}
|
||||
let mut checksums = FileChecksums::new();
|
||||
checksums.add_file_as(&ref_dsc_path, &ref_dsc_name)?;
|
||||
|
||||
@@ -304,6 +368,9 @@ pub fn run_source_build(
|
||||
// ------------------------------------------------------------------
|
||||
// 7. .changes generation (native dpkg-genchanges equivalent)
|
||||
// ------------------------------------------------------------------
|
||||
if let Some(u) = &ui {
|
||||
u.progress_message("Generating .changes");
|
||||
}
|
||||
// Pull the tarball checksums out of the referenced .dsc so they are
|
||||
// distributed through the .changes like dpkg-genchanges does, in the
|
||||
// order the .dsc itself lists them.
|
||||
@@ -416,11 +483,15 @@ pub fn run_source_build(
|
||||
// ------------------------------------------------------------------
|
||||
// 8. dpkg-source after-build (unapplies quilt patches it applied)
|
||||
// ------------------------------------------------------------------
|
||||
if let Some(u) = &ui {
|
||||
u.phase_custom("Restoring patches", Box::new(DpkgSourceClassifier::new()));
|
||||
}
|
||||
run_command(
|
||||
cwd,
|
||||
"dpkg-source",
|
||||
&["-I", "-i", "--after-build", "."],
|
||||
&pipeline_env,
|
||||
sink.as_ref(),
|
||||
)?;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
@@ -430,7 +501,11 @@ pub fn run_source_build(
|
||||
if let Some(keyid) = signing_key.filter(|_| do_sign) {
|
||||
crate::utils::gpg::validate_key_id(&keyid)?;
|
||||
|
||||
println!("signfile {}", dsc_name);
|
||||
if let Some(u) = &ui {
|
||||
u.phase_custom("Signing artifacts", Box::new(GenericClassifier::new()));
|
||||
}
|
||||
|
||||
log::info!("Signing {}", dsc_name);
|
||||
crate::utils::gpg::clearsign_file(&dsc_path, &keyid)?;
|
||||
// The freshly built .dsc changed: refresh its checksums inside the
|
||||
// .buildinfo. For binary-only builds the metadata references the
|
||||
@@ -441,13 +516,13 @@ pub fn run_source_build(
|
||||
}
|
||||
buildinfo::save_buildinfo(&buildinfo_path, &render_buildinfo_doc(&checksums))?;
|
||||
|
||||
println!("signfile {}", buildinfo_name);
|
||||
log::info!("Signing {}", buildinfo_name);
|
||||
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);
|
||||
log::info!("Signing {}", changes_name);
|
||||
crate::utils::gpg::clearsign_file(&changes_path, &keyid)?;
|
||||
|
||||
signed = true;
|
||||
@@ -472,13 +547,17 @@ struct PartialChecksum {
|
||||
}
|
||||
|
||||
/// Run a build command in `cwd` with extra environment variables layered on
|
||||
/// top of the inherited environment, with stdio attached to the terminal.
|
||||
/// top of the inherited environment.
|
||||
///
|
||||
/// When `sink` is set, stdout/stderr are piped and every line is forwarded to
|
||||
/// it (live view + tee log); otherwise stdio is inherited from the terminal.
|
||||
/// Returns an error on non-zero exit status.
|
||||
fn run_command(
|
||||
cwd: &Path,
|
||||
program: &str,
|
||||
args: &[&str],
|
||||
env: &BTreeMap<String, String>,
|
||||
sink: Option<&Arc<dyn LineSink>>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
log::debug!(
|
||||
"running: {} {} (in {})",
|
||||
@@ -486,12 +565,44 @@ fn run_command(
|
||||
args.join(" "),
|
||||
cwd.display()
|
||||
);
|
||||
let status = Command::new(program)
|
||||
.current_dir(cwd)
|
||||
.envs(env)
|
||||
.args(args)
|
||||
.status()
|
||||
.map_err(|e| format!("failed to run '{}': {}", program, e))?;
|
||||
|
||||
let mut cmd = Command::new(program);
|
||||
cmd.current_dir(cwd).envs(env).args(args);
|
||||
|
||||
let status = match sink {
|
||||
None => cmd
|
||||
.status()
|
||||
.map_err(|e| format!("failed to run '{}': {}", program, e))?,
|
||||
Some(sink) => {
|
||||
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
|
||||
let mut child = cmd
|
||||
.spawn()
|
||||
.map_err(|e| format!("failed to run '{}': {}", program, e))?;
|
||||
let stdout = child.stdout.take();
|
||||
let stderr = child.stderr.take();
|
||||
|
||||
// One reader thread per stream; interleaving across streams is
|
||||
// approximate (channel arrival order), acceptable for display.
|
||||
let out_sink = sink.clone();
|
||||
let err_sink = sink.clone();
|
||||
let out_thread = std::thread::spawn(move || {
|
||||
if let Some(out) = stdout {
|
||||
pump(out, Stream::Stdout, &*out_sink);
|
||||
}
|
||||
});
|
||||
let err_thread = std::thread::spawn(move || {
|
||||
if let Some(err) = stderr {
|
||||
pump(err, Stream::Stderr, &*err_sink);
|
||||
}
|
||||
});
|
||||
let _ = out_thread.join();
|
||||
let _ = err_thread.join();
|
||||
|
||||
child
|
||||
.wait()
|
||||
.map_err(|e| format!("failed to wait for '{}': {}", program, e))?
|
||||
}
|
||||
};
|
||||
|
||||
if !status.success() {
|
||||
return Err(format!(
|
||||
@@ -852,7 +963,7 @@ mod differential_tests {
|
||||
let ours_tree = ours_root.join(&tree_name);
|
||||
|
||||
run_dpkg(&golden_tree);
|
||||
run_source_build(&ours_tree, &SourceBuildOptions::default())
|
||||
run_source_build(&ours_tree, &SourceBuildOptions::default(), None)
|
||||
.expect("native source pipeline failed");
|
||||
|
||||
let entry =
|
||||
|
||||
Reference in New Issue
Block a user