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

Read cached output line-by-line #7737

Merged
merged 1 commit into from
Dec 22, 2019
Merged
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
18 changes: 14 additions & 4 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod unit_dependencies;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::io::Write;
use std::io::{BufRead, Write};
use std::path::PathBuf;
use std::sync::Arc;

Expand Down Expand Up @@ -1252,9 +1252,19 @@ fn replay_output_cache(
// No cached output, probably didn't emit anything.
return Ok(());
}
let contents = fs::read_to_string(&path)?;
for line in contents.lines() {
on_stderr_line(state, line, package_id, &target, &mut options)?;
// We sometimes have gigabytes of output from the compiler, so avoid
// loading it all into memory at once, as that can cause OOM where
// otherwise there would be none.
let file = fs::File::open(&path)?;
let mut reader = std::io::BufReader::new(file);
let mut line = String::new();
loop {
let length = reader.read_line(&mut line)?;
if length == 0 {
break;
}
on_stderr_line(state, line.as_str(), package_id, &target, &mut options)?;
line.clear();
}
Ok(())
})
Expand Down