Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid retaining all rustc output in memory. #6289

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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