mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Auto merge of #7819 - ehuss:fix-replay-newlines, r=alexcrichton
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`.
This commit is contained in:
commit
9d11cd19a9
@ -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(())
|
||||
|
@ -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;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user