pub fn run_make_with_output(
kernel_dir: &Path,
args: &[&str],
progress: Option<&FetchProgress>,
) -> Result<()>Expand description
Run make with merged stdout+stderr piped through the progress group.
Creates a single pipe via nix::unistd::pipe2(O_CLOEXEC), hands
the write end to the child’s stdout AND stderr (a clone), and
reads from the read end. O_CLOEXEC prevents the raw pipe fds
from leaking into any concurrently-spawned children on other
threads — without the flag, a race between pipe() and the
Stdio::from() consumption could let an unrelated fork+exec
inherit the write end and hold the reader open indefinitely.
One pipe, one reader — no threads, no channel, no chance of a
deadlock where reading stdout blocks while stderr fills its
buffer. Same merged-stream semantics that sh -c "make … 2>&1"
gives, without the shell-out.
When a progress group is supplied, each line is printed via
crate::cli::FetchProgress::println (which lands above the live
bars, or on stderr when the group is hidden). When None, output
is captured and shown only on failure.
Pipe-read I/O errors propagate via Err rather than silently
ending the read loop. The prior line-iterator formulation
(.lines() + Result::ok) dropped every error-tagged item —
a mid-stream read failure just looked like EOF and the child’s
tail output disappeared without a diagnostic. The byte-oriented
drain_lines_lossy now surfaces such failures with anyhow
context naming the merged-stream read, so a broken-pipe or EIO
during make’s output is caught at the call site.
Lines observed by the progress group’s println and retained in the
on-failure replay buffer are LF-normalized: drain_lines_lossy
strips the trailing \n, and a preceding \r (the CRLF form
Make emits on some toolchain + terminal combinations) is
stripped too, so every line the caller sees is LF-only and
terminator-less. Interior lone \r bytes — e.g. a progress
bar using carriage-return redraw — pass through verbatim (see
drain_lines_lossy_interior_cr_is_preserved), which keeps
the on-failure replay readable without mangling tools that
legitimately use \r mid-line.