Skip to content

Commit fa3bd37

Browse files
committed
Use DiagCtx in tidy CI check
1 parent 9f63474 commit fa3bd37

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

src/tools/tidy/src/diagnostics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ impl RunningCheck {
111111
tidy_error(&t.to_string()).expect("failed to output error");
112112
}
113113

114+
/// Immediately output a warning.
115+
pub fn warning<T: Display>(&mut self, t: T) {
116+
eprintln!("WARNING: {t}");
117+
}
118+
114119
/// Output an informational message
115120
pub fn message<T: Display>(&mut self, t: T) {
116121
eprintln!("{t}");

src/tools/tidy/src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use build_helper::git::{GitConfig, get_closest_upstream_commit};
1313
use build_helper::stage0_parser::{Stage0Config, parse_stage0_file};
1414
use termcolor::WriteColor;
1515

16+
use crate::diagnostics::{DiagCtx, RunningCheck};
17+
1618
macro_rules! static_regex {
1719
($re:literal) => {{
1820
static RE: ::std::sync::LazyLock<::regex::Regex> =
@@ -66,7 +68,9 @@ pub struct CiInfo {
6668
}
6769

6870
impl CiInfo {
69-
pub fn new(bad: &mut bool) -> Self {
71+
pub fn new(diag_ctx: DiagCtx) -> Self {
72+
let mut check = diag_ctx.start_check("CI history");
73+
7074
let stage0 = parse_stage0_file();
7175
let Stage0Config { nightly_branch, git_merge_commit_email, .. } = stage0.config;
7276

@@ -79,11 +83,14 @@ impl CiInfo {
7983
let base_commit = match get_closest_upstream_commit(None, &info.git_config(), info.ci_env) {
8084
Ok(Some(commit)) => Some(commit),
8185
Ok(None) => {
82-
info.error_if_in_ci("no base commit found", bad);
86+
info.error_if_in_ci("no base commit found", &mut check);
8387
None
8488
}
8589
Err(error) => {
86-
info.error_if_in_ci(&format!("failed to retrieve base commit: {error}"), bad);
90+
info.error_if_in_ci(
91+
&format!("failed to retrieve base commit: {error}"),
92+
&mut check,
93+
);
8794
None
8895
}
8996
};
@@ -98,12 +105,11 @@ impl CiInfo {
98105
}
99106
}
100107

101-
pub fn error_if_in_ci(&self, msg: &str, bad: &mut bool) {
108+
pub fn error_if_in_ci(&self, msg: &str, check: &mut RunningCheck) {
102109
if self.ci_env.is_running_in_ci() {
103-
*bad = true;
104-
eprintln!("tidy check error: {msg}");
110+
check.error(msg);
105111
} else {
106-
eprintln!("tidy check warning: {msg}. Some checks will be skipped.");
112+
check.warning(format!("{msg}. Some checks will be skipped."));
107113
}
108114
}
109115
}

src/tools/tidy/src/main.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::collections::VecDeque;
88
use std::num::NonZeroUsize;
99
use std::path::PathBuf;
1010
use std::str::FromStr;
11-
use std::sync::atomic::AtomicBool;
1211
use std::thread::{self, ScopedJoinHandle, scope};
1312
use std::{env, process};
1413

@@ -51,11 +50,8 @@ fn main() {
5150
let extra_checks =
5251
cfg_args.iter().find(|s| s.starts_with("--extra-checks=")).map(String::as_str);
5352

54-
let mut bad = false;
55-
let ci_info = CiInfo::new(&mut bad);
56-
let bad = std::sync::Arc::new(AtomicBool::new(bad));
57-
58-
let mut diag_ctx = DiagCtx::new(verbose);
53+
let diag_ctx = DiagCtx::new(verbose);
54+
let ci_info = CiInfo::new(diag_ctx.clone());
5955

6056
let drain_handles = |handles: &mut VecDeque<ScopedJoinHandle<'_, ()>>| {
6157
// poll all threads for completion before awaiting the oldest one

src/tools/tidy/src/triagebot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn check(path: &Path, diag_ctx: DiagCtx) {
4040
}
4141
} else {
4242
check.error(
43-
"triagebot.toml missing [mentions.*] section, this wrong for rust-lang/rust repo."
43+
"triagebot.toml missing [mentions.*] section, this wrong for rust-lang/rust repo.",
4444
);
4545
}
4646

src/tools/tidy/src/x_version.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn check(root: &Path, cargo: &Path, diag_ctx: DiagCtx) {
1414
Err(e) => {
1515
check.error(format!("failed to run `cargo`: {e}"));
1616
return;
17-
},
17+
}
1818
};
1919

2020
let cargo_list = child.wait_with_output().unwrap();
@@ -53,9 +53,7 @@ pub fn check(root: &Path, cargo: &Path, diag_ctx: DiagCtx) {
5353
)
5454
}
5555
} else {
56-
check.error(
57-
"Unable to parse the latest version of `x` at `src/tools/x/Cargo.toml`"
58-
)
56+
check.error("Unable to parse the latest version of `x` at `src/tools/x/Cargo.toml`")
5957
}
6058
} else {
6159
check.error(format!("failed to check version of `x`: {}", cargo_list.status))

0 commit comments

Comments
 (0)