Skip to content

Commit

Permalink
Avoid retaining all rustc output in memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Nov 9, 2018
1 parent 1f730be commit 17b6df9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> JobState<'a> {
&self,
cmd: &ProcessBuilder,
prefix: Option<String>,
print_output: bool,
capture_output: bool,
) -> CargoResult<Output> {
let prefix = prefix.unwrap_or_else(|| String::new());
cmd.exec_with_streaming(
Expand All @@ -125,7 +125,7 @@ impl<'a> JobState<'a> {
let _ = self.tx.send(Message::Stderr(format!("{}{}", prefix, err)));
Ok(())
},
print_output,
capture_output,
)
}
}
Expand Down
40 changes: 25 additions & 15 deletions src/cargo/util/process_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl ProcessBuilder {
&self,
on_stdout_line: &mut FnMut(&str) -> CargoResult<()>,
on_stderr_line: &mut FnMut(&str) -> CargoResult<()>,
print_output: bool,
capture_output: bool,
) -> CargoResult<Output> {
let mut stdout = Vec::new();
let mut stderr = Vec::new();
Expand All @@ -226,23 +226,33 @@ impl ProcessBuilder {
None => return,
}
};
let data = data.drain(..idx);
let dst = if is_out { &mut stdout } else { &mut stderr };
let start = dst.len();
dst.extend(data);
for line in String::from_utf8_lossy(&dst[start..]).lines() {
if callback_error.is_some() {
break;
}
let callback_result = if is_out {
on_stdout_line(line)
{ // scope for new_lines
let new_lines = if capture_output {
let dst = if is_out { &mut stdout } else { &mut stderr };
let start = dst.len();
let data = data.drain(..idx);
dst.extend(data);
&dst[start..]
} else {
on_stderr_line(line)
&data[..idx]
};
if let Err(e) = callback_result {
callback_error = Some(e);
for line in String::from_utf8_lossy(new_lines).lines() {
if callback_error.is_some() {
break;
}
let callback_result = if is_out {
on_stdout_line(line)
} else {
on_stderr_line(line)
};
if let Err(e) = callback_result {
callback_error = Some(e);
}
}
}
if !capture_output {
data.drain(..idx);
}
})?;
child.wait()
})()
Expand All @@ -260,7 +270,7 @@ impl ProcessBuilder {
};

{
let to_print = if print_output { Some(&output) } else { None };
let to_print = if capture_output { Some(&output) } else { None };
if !output.status.success() {
return Err(process_error(
&format!("process didn't exit successfully: {}", self),
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ impl Execs {
process.exec_with_streaming(
&mut |out| Ok(println!("{}", out)),
&mut |err| Ok(eprintln!("{}", err)),
false,
true,
)
} else {
process.exec_with_output()
Expand Down

0 comments on commit 17b6df9

Please sign in to comment.