Skip to content

Commit

Permalink
Auto merge of #7819 - ehuss:fix-replay-newlines, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix cache replay including extra newlines.

The compiler output cache replay was changed in #7737 to use `BufReader::read_line` instead of `str::lines`. `read_line`, unlike `lines`, includes the trailing line ending. The code is written assuming that the line endings are stripped, so make sure they are stripped here, too.

This only happens for non-JSON messages, like `RUSTC_LOG`.
  • Loading branch information
bors committed Jan 22, 2020
2 parents f6449ba + 7be3c2f commit 9d11cd1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,8 @@ fn replay_output_cache(
if length == 0 {
break;
}
on_stderr_line(state, line.as_str(), package_id, &target, &mut options)?;
let trimmed = line.trim_end_matches(&['\n', '\r'][..]);
on_stderr_line(state, trimmed, package_id, &target, &mut options)?;
line.clear();
}
Ok(())
Expand Down
49 changes: 48 additions & 1 deletion tests/testsuite/cache_messages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Tests for caching compiler diagnostics.

use cargo_test_support::{
clippy_is_available, is_coarse_mtime, process, project, registry::Package, sleep_ms,
basic_manifest, clippy_is_available, is_coarse_mtime, process, project, registry::Package,
sleep_ms,
};
use std::path::Path;

Expand Down Expand Up @@ -390,3 +391,49 @@ fn doesnt_create_extra_files() {
p.cargo("build").run();
assert_eq!(p.glob("target/debug/.fingerprint/foo-*/output").count(), 1);
}

#[cargo_test]
fn replay_non_json() {
// Handles non-json output.
let rustc = project()
.at("rustc")
.file("Cargo.toml", &basic_manifest("rustc_alt", "1.0.0"))
.file(
"src/main.rs",
r#"
fn main() {
eprintln!("line 1");
eprintln!("line 2");
let r = std::process::Command::new("rustc")
.args(std::env::args_os().skip(1))
.status();
std::process::exit(r.unwrap().code().unwrap_or(2));
}
"#,
)
.build();
rustc.cargo("build").run();
let p = project().file("src/lib.rs", "").build();
p.cargo("check")
.env("RUSTC", rustc.bin("rustc_alt"))
.with_stderr(
"\
[CHECKING] foo [..]
line 1
line 2
[FINISHED] dev [..]
",
)
.run();

p.cargo("check")
.env("RUSTC", rustc.bin("rustc_alt"))
.with_stderr(
"\
line 1
line 2
[FINISHED] dev [..]
",
)
.run();
}

0 comments on commit 9d11cd1

Please sign in to comment.