Skip to content

Commit dc51d49

Browse files
committed
save local packaged id + small fix
1 parent 2930af1 commit dc51d49

File tree

3 files changed

+111
-45
lines changed

3 files changed

+111
-45
lines changed

src/results/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl ::std::str::FromStr for FailureReason {
238238
type Err = ::failure::Error;
239239

240240
fn from_str(s: &str) -> ::failure::Fallible<FailureReason> {
241-
if let Some(idx) = s.find('(') {
241+
if let (Some(idx), true) = (s.find('('), s.ends_with(')')) {
242242
let prefix = &s[..idx];
243243
let contents = s[idx + 1..s.len() - 1].split(", ");
244244
match prefix {

src/runner/test.rs

Lines changed: 108 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use crate::results::{BrokenReason, EncodingType, FailureReason, TestResult, Writ
55
use crate::runner::tasks::TaskCtx;
66
use crate::runner::OverrideResult;
77
use cargo_metadata::diagnostic::DiagnosticLevel;
8-
use cargo_metadata::Message;
8+
use cargo_metadata::{Message, Metadata, PackageId};
99
use failure::Error;
1010
use remove_dir_all::remove_dir_all;
1111
use rustwide::cmd::{CommandError, ProcessLinesActions, SandboxBuilder};
1212
use rustwide::{Build, PrepareError};
13-
use std::collections::BTreeSet;
13+
use std::collections::{BTreeSet, HashSet};
1414
use std::convert::TryFrom;
1515

1616
fn failure_reason(err: &Error) -> FailureReason {
@@ -61,10 +61,25 @@ pub(super) fn detect_broken<T>(res: Result<T, Error>) -> Result<T, Error> {
6161
}
6262
}
6363

64+
fn get_local_packages(build_env: &Build) -> Fallible<HashSet<PackageId>> {
65+
Ok(build_env
66+
.cargo()
67+
.args(&["metadata", "--no-deps", "--format-version=1"])
68+
.log_output(false)
69+
.run_capture()?
70+
.stdout_lines()
71+
.iter()
72+
.filter_map(|line| serde_json::from_str::<Metadata>(line).ok())
73+
.flat_map(|metadata| metadata.packages.into_iter().map(|pkg| pkg.id))
74+
.collect::<HashSet<_>>())
75+
}
76+
6477
fn run_cargo<DB: WriteResults>(
6578
ctx: &TaskCtx<DB>,
6679
build_env: &Build,
6780
args: &[&str],
81+
check_errors: bool,
82+
local_packages_id: &HashSet<PackageId>,
6883
) -> Fallible<()> {
6984
let mut rustflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
7085
if let Some(ref tc_rustflags) = ctx.toolchain.rustflags {
@@ -84,42 +99,46 @@ fn run_cargo<DB: WriteResults>(
8499

85100
let mut detect_error = |line: &str, actions: &mut ProcessLinesActions| {
86101
// Avoid trying to deserialize non JSON output
87-
if line.starts_with('{') {
88-
let message = serde_json::from_str(line);
89-
if let Ok(message) = message {
90-
match message {
91-
Message::CompilerMessage(compiler_message) => {
92-
let inner_message = compiler_message.message;
93-
match (
94-
inner_message.level,
95-
Crate::try_from(&compiler_message.package_id),
96-
) {
97-
// the only local crate in a well defined job is the crate currently being tested
98-
(DiagnosticLevel::Error, Ok(Crate::Local(_))) => {
99-
if let Some(code) = inner_message.code {
100-
error_codes.insert(DiagnosticCode::from(code.code));
101-
}
102-
}
103-
(DiagnosticLevel::Ice, Ok(Crate::Local(_))) => did_ice = true,
104-
// If the error is in a crate that is not local then it's referred to a dependency
105-
// of the current crate
106-
(DiagnosticLevel::Error, Ok(krate)) => {
107-
deps.insert(krate);
108-
}
109-
(DiagnosticLevel::Ice, Ok(krate)) => {
110-
deps.insert(krate);
111-
}
102+
if !line.starts_with('{') {
103+
return;
104+
}
112105

113-
_ => (),
114-
}
106+
let message = match serde_json::from_str(line) {
107+
Ok(message) => message,
108+
Err(_) => return,
109+
};
115110

116-
actions.replace_with_lines(
117-
inner_message.rendered.unwrap_or_default().split('\n'),
118-
);
111+
match message {
112+
Message::CompilerMessage(compiler_message) => {
113+
let inner_message = compiler_message.message;
114+
match (inner_message.level, &compiler_message.package_id) {
115+
// the only local crate in a well defined job is the crate currently being tested
116+
(DiagnosticLevel::Error, pkgid) if local_packages_id.contains(pkgid) => {
117+
if let Some(code) = inner_message.code {
118+
error_codes.insert(DiagnosticCode::from(code.code));
119+
}
120+
}
121+
(DiagnosticLevel::Ice, pkgid) if local_packages_id.contains(pkgid) => {
122+
did_ice = true
123+
}
124+
// If the error is in a crate that is not local then it's referred to a dependency
125+
// of the current crate
126+
(DiagnosticLevel::Error, pkgid) => {
127+
if let Ok(krate) = Crate::try_from(pkgid) {
128+
deps.insert(krate);
129+
}
119130
}
120-
_ => actions.remove_line(),
131+
(DiagnosticLevel::Ice, pkgid) => {
132+
if let Ok(krate) = Crate::try_from(pkgid) {
133+
deps.insert(krate);
134+
}
135+
}
136+
_ => (),
121137
}
138+
139+
actions.replace_with_lines(inner_message.rendered.unwrap_or_default().split('\n'));
122140
}
141+
_ => actions.remove_line(),
123142
}
124143
};
125144

@@ -128,8 +147,11 @@ fn run_cargo<DB: WriteResults>(
128147
.args(args)
129148
.env("CARGO_INCREMENTAL", "0")
130149
.env("RUST_BACKTRACE", "full")
131-
.env(rustflags_env, rustflags)
132-
.process_lines(&mut detect_error);
150+
.env(rustflags_env, rustflags);
151+
152+
if check_errors {
153+
command = command.process_lines(&mut detect_error);
154+
}
133155

134156
if ctx.quiet {
135157
command = command.no_output_timeout(None);
@@ -154,7 +176,7 @@ fn run_cargo<DB: WriteResults>(
154176
pub(super) fn run_test<DB: WriteResults>(
155177
action: &str,
156178
ctx: &TaskCtx<DB>,
157-
test_fn: fn(&TaskCtx<DB>, &Build) -> Fallible<TestResult>,
179+
test_fn: fn(&TaskCtx<DB>, &Build, &HashSet<PackageId>) -> Fallible<TestResult>,
158180
) -> Fallible<()> {
159181
if let Some(res) = ctx
160182
.db
@@ -195,23 +217,34 @@ pub(super) fn run_test<DB: WriteResults>(
195217
build = build.patch_with_git(&patch.name, &patch.repo, &patch.branch);
196218
}
197219

198-
detect_broken(build.run(|build| test_fn(ctx, build)))
220+
detect_broken(build.run(|build| {
221+
let local_packages_id = get_local_packages(build)?;
222+
test_fn(ctx, build, &local_packages_id)
223+
}))
199224
},
200225
)?;
201226
}
202227
Ok(())
203228
}
204229

205-
fn build<DB: WriteResults>(ctx: &TaskCtx<DB>, build_env: &Build) -> Fallible<()> {
230+
fn build<DB: WriteResults>(
231+
ctx: &TaskCtx<DB>,
232+
build_env: &Build,
233+
local_packages_id: &HashSet<PackageId>,
234+
) -> Fallible<()> {
206235
run_cargo(
207236
ctx,
208237
build_env,
209238
&["build", "--frozen", "--message-format=json"],
239+
true,
240+
local_packages_id,
210241
)?;
211242
run_cargo(
212243
ctx,
213244
build_env,
214245
&["test", "--frozen", "--no-run", "--message-format=json"],
246+
true,
247+
local_packages_id,
215248
)?;
216249
Ok(())
217250
}
@@ -220,15 +253,18 @@ fn test<DB: WriteResults>(ctx: &TaskCtx<DB>, build_env: &Build) -> Fallible<()>
220253
run_cargo(
221254
ctx,
222255
build_env,
223-
&["test", "--frozen", "--message-format=json"],
256+
&["test", "--frozen"],
257+
false,
258+
&HashSet::new(),
224259
)
225260
}
226261

227262
pub(super) fn test_build_and_test<DB: WriteResults>(
228263
ctx: &TaskCtx<DB>,
229264
build_env: &Build,
265+
local_packages_id: &HashSet<PackageId>,
230266
) -> Fallible<TestResult> {
231-
let build_r = build(ctx, build_env);
267+
let build_r = build(ctx, build_env, local_packages_id);
232268
let test_r = if build_r.is_ok() {
233269
Some(test(ctx, build_env))
234270
} else {
@@ -246,8 +282,9 @@ pub(super) fn test_build_and_test<DB: WriteResults>(
246282
pub(super) fn test_build_only<DB: WriteResults>(
247283
ctx: &TaskCtx<DB>,
248284
build_env: &Build,
285+
local_packages_id: &HashSet<PackageId>,
249286
) -> Fallible<TestResult> {
250-
if let Err(err) = build(ctx, build_env) {
287+
if let Err(err) = build(ctx, build_env, local_packages_id) {
251288
Ok(TestResult::BuildFail(failure_reason(&err)))
252289
} else {
253290
Ok(TestResult::TestSkipped)
@@ -257,11 +294,20 @@ pub(super) fn test_build_only<DB: WriteResults>(
257294
pub(super) fn test_check_only<DB: WriteResults>(
258295
ctx: &TaskCtx<DB>,
259296
build_env: &Build,
297+
local_packages_id: &HashSet<PackageId>,
260298
) -> Fallible<TestResult> {
261299
if let Err(err) = run_cargo(
262300
ctx,
263301
build_env,
264-
&["check", "--frozen", "--all", "--all-targets"],
302+
&[
303+
"check",
304+
"--frozen",
305+
"--all",
306+
"--all-targets",
307+
"--message-format=json",
308+
],
309+
true,
310+
local_packages_id,
265311
) {
266312
Ok(TestResult::BuildFail(failure_reason(&err)))
267313
} else {
@@ -272,11 +318,20 @@ pub(super) fn test_check_only<DB: WriteResults>(
272318
pub(super) fn test_clippy_only<DB: WriteResults>(
273319
ctx: &TaskCtx<DB>,
274320
build_env: &Build,
321+
local_packages_id: &HashSet<PackageId>,
275322
) -> Fallible<TestResult> {
276323
if let Err(err) = run_cargo(
277324
ctx,
278325
build_env,
279-
&["clippy", "--frozen", "--all", "--all-targets"],
326+
&[
327+
"clippy",
328+
"--frozen",
329+
"--all",
330+
"--all-targets",
331+
"--message-format=json",
332+
],
333+
true,
334+
local_packages_id,
280335
) {
281336
Ok(TestResult::BuildFail(failure_reason(&err)))
282337
} else {
@@ -287,11 +342,20 @@ pub(super) fn test_clippy_only<DB: WriteResults>(
287342
pub(super) fn test_rustdoc<DB: WriteResults>(
288343
ctx: &TaskCtx<DB>,
289344
build_env: &Build,
345+
local_packages_id: &HashSet<PackageId>,
290346
) -> Fallible<TestResult> {
291347
let res = run_cargo(
292348
ctx,
293349
build_env,
294-
&["doc", "--frozen", "--no-deps", "--document-private-items"],
350+
&[
351+
"doc",
352+
"--frozen",
353+
"--no-deps",
354+
"--document-private-items",
355+
"--message-format=json",
356+
],
357+
true,
358+
local_packages_id,
295359
);
296360

297361
// Make sure to remove the built documentation

src/runner/unstable_features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::prelude::*;
22
use crate::results::TestResult;
33
use crate::results::WriteResults;
44
use crate::runner::tasks::TaskCtx;
5+
use cargo_metadata::PackageId;
56
use rustwide::Build;
67
use std::collections::HashSet;
78
use std::path::Path;
@@ -10,6 +11,7 @@ use walkdir::{DirEntry, WalkDir};
1011
pub(super) fn find_unstable_features<DB: WriteResults>(
1112
_ctx: &TaskCtx<DB>,
1213
build: &Build,
14+
_local_packages_id: &HashSet<PackageId>,
1315
) -> Fallible<TestResult> {
1416
let mut features = HashSet::new();
1517

0 commit comments

Comments
 (0)