Skip to content

Commit 7047704

Browse files
committed
custom routine for --failed flag
1 parent 2c16121 commit 7047704

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

src/bootstrap/builder/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ mod dist {
576576
config.cmd = Subcommand::Test {
577577
test_args: vec![],
578578
rustc_args: vec![],
579+
failed: false,
579580
no_fail_fast: false,
580581
no_doc: true,
581582
doc: false,
@@ -649,6 +650,7 @@ mod dist {
649650
test_args: vec![],
650651
rustc_args: vec![],
651652
no_fail_fast: false,
653+
failed: false,
652654
doc: true,
653655
no_doc: false,
654656
skip: vec![],

src/bootstrap/failed.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::{
2+
collections::HashSet,
3+
fs::File,
4+
io::Read,
5+
path::{Path, PathBuf},
6+
};
7+
8+
use crate::builder::Builder;
9+
10+
pub const TRACKER_FILE: &'static str = "./src/bootstrap/test.tracker";
11+
12+
/// Runs all the tests that failed on their last run
13+
pub fn failed(_builder: &Builder<'_>) {
14+
let _failed_tests = get_failed_tests();
15+
}
16+
17+
/// Returns a list of paths of tests that failed the last time that they were run
18+
fn get_failed_tests() -> Vec<PathBuf> {
19+
let contents = {
20+
let path = Path::new(TRACKER_FILE);
21+
let mut f = File::open(path).unwrap_or_else(|_| {
22+
eprintln!("Please run `x.py test` atleast once before running this command");
23+
panic!();
24+
});
25+
26+
let mut buf = String::new();
27+
f.read_to_string(&mut buf).expect(&format!("failed to read {}", TRACKER_FILE));
28+
29+
buf
30+
};
31+
32+
let failed_tests =
33+
serde_json::from_str::<HashSet<&str>>(&contents).expect("failed to deserialise tracker");
34+
35+
for test in failed_tests {
36+
let test = test.split(" ").collect::<Vec<_>>();
37+
println!("{:?}", test);
38+
}
39+
40+
vec![]
41+
}

src/bootstrap/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ mod config;
5050
mod dist;
5151
mod doc;
5252
mod download;
53+
mod failed;
5354
mod flags;
5455
mod format;
5556
mod install;
@@ -217,6 +218,7 @@ pub struct Build {
217218
in_tree_llvm_info: channel::GitInfo,
218219
local_rebuild: bool,
219220
fail_fast: bool,
221+
failed: bool,
220222
doc_tests: DocTests,
221223
verbosity: usize,
222224

@@ -437,6 +439,7 @@ impl Build {
437439
initial_libdir,
438440
initial_sysroot: initial_sysroot.into(),
439441
local_rebuild: config.local_rebuild,
442+
failed: config.cmd.failed(),
440443
fail_fast: config.cmd.fail_fast(),
441444
doc_tests: config.cmd.doc_tests(),
442445
verbosity: config.verbose,
@@ -673,11 +676,16 @@ impl Build {
673676
// Download rustfmt early so that it can be used in rust-analyzer configs.
674677
let _ = &builder::Builder::new(&self).initial_rustfmt();
675678

676-
// hardcoded subcommands
679+
// hardcoded subcommands and flags
677680
match &self.config.cmd {
678681
Subcommand::Format { check } => {
679682
return format::format(&builder::Builder::new(&self), *check, &self.config.paths);
680683
}
684+
Subcommand::Test { failed, .. } => {
685+
if *failed {
686+
return failed::failed(&builder::Builder::new(&self));
687+
}
688+
}
681689
Subcommand::Suggest { run } => {
682690
return suggest::suggest(&builder::Builder::new(&self), *run);
683691
}

src/bootstrap/render_tests.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
//! about the executed tests. Doing so suppresses the human-readable output, and (compared to Cargo
66
//! and rustc) libtest doesn't include the rendered human-readable output as a JSON field. We had
77
//! to reimplement all the rendering logic in this module because of that.
8-
9-
use crate::builder::Builder;
108
use std::collections::HashSet;
119
use std::fs::OpenOptions;
1210
use std::io::{BufRead, BufReader, Read, Write};
1311
use std::process::{ChildStdout, Command, Stdio};
1412
use std::time::Duration;
13+
14+
use crate::builder::Builder;
15+
use crate::failed::TRACKER_FILE;
16+
1517
use termcolor::{Color, ColorSpec, WriteColor};
1618

1719
const TERSE_TESTS_PER_LINE: usize = 88;
1820
#[allow(unused)] // FIXME unused warning even though it is
19-
const TRACKER_FILE: &'static str = "./src/bootstrap/test.tracker";
2021

2122
pub(crate) fn add_flags_and_try_run_tests(builder: &Builder<'_>, cmd: &mut Command) -> bool {
2223
if cmd.get_args().position(|arg| arg == "--").is_none() {

src/bootstrap/suggest.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![cfg_attr(feature = "build-metrics", allow(unused))]
22

3-
use std::str::FromStr;
4-
5-
use std::path::PathBuf;
3+
use std::{path::PathBuf, str::FromStr};
64

75
use clap::Parser;
86

@@ -60,6 +58,7 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
6058

6159
if run {
6260
for sug in suggestions {
61+
println!("paths: {:?}", &sug.2);
6362
let mut build: crate::Build = builder.build.clone();
6463
build.config.paths = sug.2;
6564
build.config.cmd = crate::flags::Flags::parse_from(["x.py", sug.0]).cmd;

0 commit comments

Comments
 (0)