Rollup merge of #148017 - simp4t7:add-tidy-flags, r=Kobzol
Add TidyFlags and merge DiagCtx Adds a struct `TidyFlags` and merges it with `DiagCtx` into `TidyCtx`. Removes the need to pass `bless` into individual check functions in tidy.
This commit is contained in:
commit
5ff30d3daf
37 changed files with 171 additions and 137 deletions
|
|
@ -24,7 +24,7 @@ use std::fmt::Display;
|
|||
use std::iter::Peekable;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -130,8 +130,8 @@ fn check_lines<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("alphabetical").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("alphabetical").path(path));
|
||||
|
||||
let skip =
|
||||
|path: &_, _is_dir| filter_dirs(path) || path.ends_with("tidy/src/alphabetical/tests.rs");
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use std::path::Path;
|
||||
|
||||
use crate::alphabetical::check_lines;
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::{TidyCtx, TidyFlags};
|
||||
|
||||
#[track_caller]
|
||||
fn test(lines: &str, name: &str, expected_msg: &str, expected_bad: bool) {
|
||||
let diag_ctx = DiagCtx::new(Path::new("/"), false);
|
||||
let mut check = diag_ctx.start_check("alphabetical-test");
|
||||
let tidy_ctx = TidyCtx::new(Path::new("/"), false, TidyFlags::default());
|
||||
let mut check = tidy_ctx.start_check("alphabetical-test");
|
||||
check_lines(&name, lines.lines().enumerate(), &mut check);
|
||||
|
||||
assert_eq!(expected_bad, check.is_bad());
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ pub use os_impl::*;
|
|||
mod os_impl {
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
pub fn check_filesystem_support(_sources: &[&Path], _output: &Path) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn check(_path: &Path, _diag_ctx: DiagCtx) {}
|
||||
pub fn check(_path: &Path, _tidy_ctx: TidyCtx) {}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
|
@ -38,7 +38,7 @@ mod os_impl {
|
|||
|
||||
use FilesystemSupport::*;
|
||||
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
fn is_executable(path: &Path) -> std::io::Result<bool> {
|
||||
Ok(path.metadata()?.mode() & 0o111 != 0)
|
||||
|
|
@ -110,8 +110,8 @@ mod os_impl {
|
|||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("bins");
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("bins");
|
||||
|
||||
use std::ffi::OsStr;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::walk::{filter_dirs, filter_not_rust, walk};
|
||||
|
||||
const GRAPHVIZ_POSTFLOW_MSG: &str = "`borrowck_graphviz_postflow` attribute in test";
|
||||
|
||||
pub fn check(test_dir: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("debug_artifacts").path(test_dir));
|
||||
pub fn check(test_dir: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("debug_artifacts").path(test_dir));
|
||||
|
||||
walk(
|
||||
test_dir,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use build_helper::ci::CiEnv;
|
|||
use cargo_metadata::semver::Version;
|
||||
use cargo_metadata::{Metadata, Package, PackageId};
|
||||
|
||||
use crate::diagnostics::{DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{RunningCheck, TidyCtx};
|
||||
|
||||
#[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"]
|
||||
mod proc_macro_deps;
|
||||
|
|
@ -615,8 +615,9 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
|
|||
///
|
||||
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
|
||||
/// to the cargo executable.
|
||||
pub fn check(root: &Path, cargo: &Path, bless: bool, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("deps");
|
||||
pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("deps");
|
||||
let bless = tidy_ctx.is_bless_enabled();
|
||||
|
||||
let mut checked_runtime_licenses = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,28 +5,59 @@ use std::sync::{Arc, Mutex};
|
|||
|
||||
use termcolor::{Color, WriteColor};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
///CLI flags used by tidy.
|
||||
pub struct TidyFlags {
|
||||
///Applies style and formatting changes during a tidy run.
|
||||
bless: bool,
|
||||
}
|
||||
|
||||
impl TidyFlags {
|
||||
pub fn new(cfg_args: &[String]) -> Self {
|
||||
let mut flags = Self::default();
|
||||
|
||||
for arg in cfg_args {
|
||||
match arg.as_str() {
|
||||
"--bless" => flags.bless = true,
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
flags
|
||||
}
|
||||
}
|
||||
|
||||
/// Collects diagnostics from all tidy steps, and contains shared information
|
||||
/// that determines how should message and logs be presented.
|
||||
///
|
||||
/// Since checks are executed in parallel, the context is internally synchronized, to avoid
|
||||
/// all checks to lock it explicitly.
|
||||
#[derive(Clone)]
|
||||
pub struct DiagCtx(Arc<Mutex<DiagCtxInner>>);
|
||||
pub struct TidyCtx {
|
||||
tidy_flags: TidyFlags,
|
||||
diag_ctx: Arc<Mutex<DiagCtxInner>>,
|
||||
}
|
||||
|
||||
impl DiagCtx {
|
||||
pub fn new(root_path: &Path, verbose: bool) -> Self {
|
||||
Self(Arc::new(Mutex::new(DiagCtxInner {
|
||||
running_checks: Default::default(),
|
||||
finished_checks: Default::default(),
|
||||
root_path: root_path.to_path_buf(),
|
||||
verbose,
|
||||
})))
|
||||
impl TidyCtx {
|
||||
pub fn new(root_path: &Path, verbose: bool, tidy_flags: TidyFlags) -> Self {
|
||||
Self {
|
||||
diag_ctx: Arc::new(Mutex::new(DiagCtxInner {
|
||||
running_checks: Default::default(),
|
||||
finished_checks: Default::default(),
|
||||
root_path: root_path.to_path_buf(),
|
||||
verbose,
|
||||
})),
|
||||
tidy_flags,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_bless_enabled(&self) -> bool {
|
||||
self.tidy_flags.bless
|
||||
}
|
||||
|
||||
pub fn start_check<Id: Into<CheckId>>(&self, id: Id) -> RunningCheck {
|
||||
let mut id = id.into();
|
||||
|
||||
let mut ctx = self.0.lock().unwrap();
|
||||
let mut ctx = self.diag_ctx.lock().unwrap();
|
||||
|
||||
// Shorten path for shorter diagnostics
|
||||
id.path = match id.path {
|
||||
|
|
@ -38,14 +69,14 @@ impl DiagCtx {
|
|||
RunningCheck {
|
||||
id,
|
||||
bad: false,
|
||||
ctx: self.0.clone(),
|
||||
ctx: self.diag_ctx.clone(),
|
||||
#[cfg(test)]
|
||||
errors: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_failed_checks(self) -> Vec<FinishedCheck> {
|
||||
let ctx = Arc::into_inner(self.0).unwrap().into_inner().unwrap();
|
||||
let ctx = Arc::into_inner(self.diag_ctx).unwrap().into_inner().unwrap();
|
||||
assert!(ctx.running_checks.is_empty(), "Some checks are still running");
|
||||
ctx.finished_checks.into_iter().filter(|c| c.bad).collect()
|
||||
}
|
||||
|
|
@ -151,7 +182,7 @@ impl RunningCheck {
|
|||
/// Useful if you want to run some functions from tidy without configuring
|
||||
/// diagnostics.
|
||||
pub fn new_noop() -> Self {
|
||||
let ctx = DiagCtx::new(Path::new(""), false);
|
||||
let ctx = TidyCtx::new(Path::new(""), false, TidyFlags::default());
|
||||
ctx.start_check("noop")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("edition").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("edition").path(path));
|
||||
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
|
||||
let file = entry.path();
|
||||
let filename = file.file_name().unwrap();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use std::path::Path;
|
|||
|
||||
use regex::Regex;
|
||||
|
||||
use crate::diagnostics::{DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{RunningCheck, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk, walk_many};
|
||||
|
||||
const ERROR_CODES_PATH: &str = "compiler/rustc_error_codes/src/lib.rs";
|
||||
|
|
@ -36,8 +36,8 @@ const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E07
|
|||
const IGNORE_UI_TEST_CHECK: &[&str] =
|
||||
&["E0461", "E0465", "E0514", "E0554", "E0640", "E0717", "E0729"];
|
||||
|
||||
pub fn check(root_path: &Path, search_paths: &[&Path], ci_info: &crate::CiInfo, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("error_codes");
|
||||
pub fn check(root_path: &Path, search_paths: &[&Path], ci_info: &crate::CiInfo, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("error_codes");
|
||||
|
||||
// Check that no error code explanation was removed.
|
||||
check_removed_error_code_explanation(ci_info, &mut check);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::fs;
|
|||
use std::path::Path;
|
||||
|
||||
use crate::deps::WorkspaceInfo;
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
/// List of allowed sources for packages.
|
||||
const ALLOWED_SOURCES: &[&str] = &[
|
||||
|
|
@ -15,8 +15,8 @@ const ALLOWED_SOURCES: &[&str] = &[
|
|||
|
||||
/// Checks for external package sources. `root` is the path to the directory that contains the
|
||||
/// workspace `Cargo.toml`.
|
||||
pub fn check(root: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("extdeps");
|
||||
pub fn check(root: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("extdeps");
|
||||
|
||||
for &WorkspaceInfo { path, submodules, .. } in crate::deps::WORKSPACES {
|
||||
if crate::deps::has_missing_submodule(root, submodules) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use std::str::FromStr;
|
|||
use std::{fmt, fs, io};
|
||||
|
||||
use crate::CiInfo;
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
mod rustdoc_js;
|
||||
|
||||
|
|
@ -52,12 +52,11 @@ pub fn check(
|
|||
tools_path: &Path,
|
||||
npm: &Path,
|
||||
cargo: &Path,
|
||||
bless: bool,
|
||||
extra_checks: Option<&str>,
|
||||
pos_args: &[String],
|
||||
diag_ctx: DiagCtx,
|
||||
tidy_ctx: TidyCtx,
|
||||
) {
|
||||
let mut check = diag_ctx.start_check("extra_checks");
|
||||
let mut check = tidy_ctx.start_check("extra_checks");
|
||||
|
||||
if let Err(e) = check_impl(
|
||||
root_path,
|
||||
|
|
@ -67,9 +66,9 @@ pub fn check(
|
|||
tools_path,
|
||||
npm,
|
||||
cargo,
|
||||
bless,
|
||||
extra_checks,
|
||||
pos_args,
|
||||
&tidy_ctx,
|
||||
) {
|
||||
check.error(e);
|
||||
}
|
||||
|
|
@ -83,12 +82,13 @@ fn check_impl(
|
|||
tools_path: &Path,
|
||||
npm: &Path,
|
||||
cargo: &Path,
|
||||
bless: bool,
|
||||
extra_checks: Option<&str>,
|
||||
pos_args: &[String],
|
||||
tidy_ctx: &TidyCtx,
|
||||
) -> Result<(), Error> {
|
||||
let show_diff =
|
||||
std::env::var("TIDY_PRINT_DIFF").is_ok_and(|v| v.eq_ignore_ascii_case("true") || v == "1");
|
||||
let bless = tidy_ctx.is_bless_enabled();
|
||||
|
||||
// Split comma-separated args up
|
||||
let mut lint_args = match extra_checks {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use std::num::NonZeroU32;
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::{fmt, fs};
|
||||
|
||||
use crate::diagnostics::{DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{RunningCheck, TidyCtx};
|
||||
use crate::walk::{filter_dirs, filter_not_rust, walk, walk_many};
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -92,9 +92,9 @@ pub fn check(
|
|||
tests_path: &Path,
|
||||
compiler_path: &Path,
|
||||
lib_path: &Path,
|
||||
diag_ctx: DiagCtx,
|
||||
tidy_ctx: TidyCtx,
|
||||
) -> CollectedFeatures {
|
||||
let mut check = diag_ctx.start_check("features");
|
||||
let mut check = tidy_ctx.start_check("features");
|
||||
|
||||
let mut features = collect_lang_features(compiler_path, &mut check);
|
||||
assert!(!features.is_empty());
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@
|
|||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
pub fn check(root_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("filenames");
|
||||
pub fn check(root_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("filenames");
|
||||
let stat_output = Command::new("git")
|
||||
.arg("-C")
|
||||
.arg(root_path)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use fluent_syntax::ast::Entry;
|
|||
use fluent_syntax::parser;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
fn message() -> &'static Regex {
|
||||
|
|
@ -87,8 +87,9 @@ fn sort_messages(
|
|||
out
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, bless: bool, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("fluent_alphabetical").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("fluent_alphabetical").path(path));
|
||||
let bless = tidy_ctx.is_bless_enabled();
|
||||
|
||||
let mut all_defined_msgs = HashMap::new();
|
||||
walk(
|
||||
|
|
@ -120,5 +121,5 @@ pub fn check(path: &Path, bless: bool, diag_ctx: DiagCtx) {
|
|||
|
||||
assert!(!all_defined_msgs.is_empty());
|
||||
|
||||
crate::fluent_used::check(path, all_defined_msgs, diag_ctx);
|
||||
crate::fluent_used::check(path, all_defined_msgs, tidy_ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::path::Path;
|
|||
|
||||
use fluent_syntax::ast::{Entry, Message, PatternElement};
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
@ -53,8 +53,8 @@ fn check_lowercase(filename: &str, contents: &str, check: &mut RunningCheck) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("fluent_lowercase").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("fluent_lowercase").path(path));
|
||||
walk(
|
||||
path,
|
||||
|path, is_dir| filter_dirs(path) || (!is_dir && filter_fluent(path)),
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::path::Path;
|
|||
|
||||
use fluent_syntax::ast::{Entry, PatternElement};
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
fn filter_fluent(path: &Path) -> bool {
|
||||
|
|
@ -75,8 +75,8 @@ fn find_line(haystack: &str, needle: &str) -> usize {
|
|||
1
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("fluent_period").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("fluent_period").path(path));
|
||||
|
||||
walk(
|
||||
path,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
fn filter_used_messages(
|
||||
|
|
@ -28,8 +28,8 @@ fn filter_used_messages(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, mut all_defined_msgs: HashMap<String, String>, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("fluent_used").path(path));
|
||||
pub fn check(path: &Path, mut all_defined_msgs: HashMap<String, String>, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("fluent_used").path(path));
|
||||
|
||||
let mut msgs_appear_only_once = HashMap::new();
|
||||
walk(path, |path, _| filter_dirs(path), &mut |_, contents| {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
pub fn check(root_path: &Path, compiler_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("gcc_submodule");
|
||||
pub fn check(root_path: &Path, compiler_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("gcc_submodule");
|
||||
|
||||
let cg_gcc_version_path = compiler_path.join("rustc_codegen_gcc/libgccjit.version");
|
||||
let cg_gcc_version = std::fs::read_to_string(&cg_gcc_version_path)
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::walk::*;
|
||||
|
||||
pub fn check(filepath: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("known_bug").path(filepath));
|
||||
pub fn check(filepath: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("known_bug").path(filepath));
|
||||
walk(filepath, |path, _is_dir| filter_not_rust(path), &mut |entry, contents| {
|
||||
let file: &Path = entry.path();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use build_helper::ci::CiEnv;
|
|||
use build_helper::git::{GitConfig, get_closest_upstream_commit};
|
||||
use build_helper::stage0_parser::{Stage0Config, parse_stage0_file};
|
||||
|
||||
use crate::diagnostics::{DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{RunningCheck, TidyCtx};
|
||||
|
||||
macro_rules! static_regex {
|
||||
($re:literal) => {{
|
||||
|
|
@ -52,8 +52,8 @@ pub struct CiInfo {
|
|||
}
|
||||
|
||||
impl CiInfo {
|
||||
pub fn new(diag_ctx: DiagCtx) -> Self {
|
||||
let mut check = diag_ctx.start_check("CI history");
|
||||
pub fn new(tidy_ctx: TidyCtx) -> Self {
|
||||
let mut check = tidy_ctx.start_check("CI history");
|
||||
|
||||
let stage0 = parse_stage0_file();
|
||||
let Stage0Config { nightly_branch, git_merge_commit_email, .. } = stage0.config;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use std::str::FromStr;
|
|||
use std::thread::{self, ScopedJoinHandle, scope};
|
||||
use std::{env, process};
|
||||
|
||||
use tidy::diagnostics::{COLOR_ERROR, COLOR_SUCCESS, DiagCtx, output_message};
|
||||
use tidy::diagnostics::{COLOR_ERROR, COLOR_SUCCESS, TidyCtx, TidyFlags, output_message};
|
||||
use tidy::*;
|
||||
|
||||
fn main() {
|
||||
|
|
@ -46,12 +46,12 @@ fn main() {
|
|||
None => (&args[..], [].as_slice()),
|
||||
};
|
||||
let verbose = cfg_args.iter().any(|s| *s == "--verbose");
|
||||
let bless = cfg_args.iter().any(|s| *s == "--bless");
|
||||
let extra_checks =
|
||||
cfg_args.iter().find(|s| s.starts_with("--extra-checks=")).map(String::as_str);
|
||||
|
||||
let diag_ctx = DiagCtx::new(&root_path, verbose);
|
||||
let ci_info = CiInfo::new(diag_ctx.clone());
|
||||
let tidy_flags = TidyFlags::new(cfg_args);
|
||||
let tidy_ctx = TidyCtx::new(&root_path, verbose, tidy_flags);
|
||||
let ci_info = CiInfo::new(tidy_ctx.clone());
|
||||
|
||||
let drain_handles = |handles: &mut VecDeque<ScopedJoinHandle<'_, ()>>| {
|
||||
// poll all threads for completion before awaiting the oldest one
|
||||
|
|
@ -86,9 +86,9 @@ fn main() {
|
|||
(@ $p:ident, name=$name:expr $(, $args:expr)* ) => {
|
||||
drain_handles(&mut handles);
|
||||
|
||||
let diag_ctx = diag_ctx.clone();
|
||||
let tidy_ctx = tidy_ctx.clone();
|
||||
let handle = thread::Builder::new().name($name).spawn_scoped(s, || {
|
||||
$p::check($($args, )* diag_ctx);
|
||||
$p::check($($args, )* tidy_ctx);
|
||||
}).unwrap();
|
||||
handles.push_back(handle);
|
||||
}
|
||||
|
|
@ -97,15 +97,15 @@ fn main() {
|
|||
check!(target_specific_tests, &tests_path);
|
||||
|
||||
// Checks that are done on the cargo workspace.
|
||||
check!(deps, &root_path, &cargo, bless);
|
||||
check!(deps, &root_path, &cargo);
|
||||
check!(extdeps, &root_path);
|
||||
|
||||
// Checks over tests.
|
||||
check!(tests_placement, &root_path);
|
||||
check!(tests_revision_unpaired_stdout_stderr, &tests_path);
|
||||
check!(debug_artifacts, &tests_path);
|
||||
check!(ui_tests, &root_path, bless);
|
||||
check!(mir_opt_tests, &tests_path, bless);
|
||||
check!(ui_tests, &root_path);
|
||||
check!(mir_opt_tests, &tests_path);
|
||||
check!(rustdoc_gui_tests, &tests_path);
|
||||
check!(rustdoc_css_themes, &librustdoc_path);
|
||||
check!(rustdoc_templates, &librustdoc_path);
|
||||
|
|
@ -115,7 +115,7 @@ fn main() {
|
|||
|
||||
// Checks that only make sense for the compiler.
|
||||
check!(error_codes, &root_path, &[&compiler_path, &librustdoc_path], &ci_info);
|
||||
check!(fluent_alphabetical, &compiler_path, bless);
|
||||
check!(fluent_alphabetical, &compiler_path);
|
||||
check!(fluent_period, &compiler_path);
|
||||
check!(fluent_lowercase, &compiler_path);
|
||||
check!(target_policy, &root_path);
|
||||
|
|
@ -156,7 +156,7 @@ fn main() {
|
|||
let collected = {
|
||||
drain_handles(&mut handles);
|
||||
|
||||
features::check(&src_path, &tests_path, &compiler_path, &library_path, diag_ctx.clone())
|
||||
features::check(&src_path, &tests_path, &compiler_path, &library_path, tidy_ctx.clone())
|
||||
};
|
||||
check!(unstable_book, &src_path, collected);
|
||||
|
||||
|
|
@ -169,13 +169,12 @@ fn main() {
|
|||
&tools_path,
|
||||
&npm,
|
||||
&cargo,
|
||||
bless,
|
||||
extra_checks,
|
||||
pos_args
|
||||
);
|
||||
});
|
||||
|
||||
let failed_checks = diag_ctx.into_failed_checks();
|
||||
let failed_checks = tidy_ctx.into_failed_checks();
|
||||
if !failed_checks.is_empty() {
|
||||
let mut failed: Vec<String> =
|
||||
failed_checks.into_iter().map(|c| c.id().to_string()).collect();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use miropt_test_tools::PanicStrategy;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
use crate::walk::walk_no_read;
|
||||
|
||||
fn check_unused_files(path: &Path, bless: bool, check: &mut RunningCheck) {
|
||||
|
|
@ -74,8 +74,9 @@ fn check_dash_files(path: &Path, bless: bool, check: &mut RunningCheck) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, bless: bool, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("mir_opt_tests").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("mir_opt_tests").path(path));
|
||||
let bless = tidy_ctx.is_bless_enabled();
|
||||
|
||||
check_unused_files(path, bless, &mut check);
|
||||
check_dash_files(path, bless, &mut check);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
// Paths that may contain platform-specific code.
|
||||
|
|
@ -68,8 +68,8 @@ const EXCEPTION_PATHS: &[&str] = &[
|
|||
"library/std/src/io/error.rs", // Repr unpacked needed for UEFI
|
||||
];
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("pal").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("pal").path(path));
|
||||
|
||||
// Sanity check that the complex parsing here works.
|
||||
let mut saw_target_arch = false;
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
|
||||
pub fn check(librustdoc_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("rustdoc_css_themes").path(librustdoc_path));
|
||||
pub fn check(librustdoc_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("rustdoc_css_themes").path(librustdoc_path));
|
||||
|
||||
let rustdoc_css = "html/static/css/rustdoc.css";
|
||||
let noscript_css = "html/static/css/noscript.css";
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("rustdoc_gui_tests").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("rustdoc_gui_tests").path(path));
|
||||
|
||||
crate::walk::walk(
|
||||
&path.join("rustdoc-gui"),
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
|
||||
const RUSTDOC_JSON_TYPES: &str = "src/rustdoc-json-types";
|
||||
|
||||
pub fn check(src_path: &Path, ci_info: &crate::CiInfo, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("rustdoc_json").path(src_path));
|
||||
pub fn check(src_path: &Path, ci_info: &crate::CiInfo, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("rustdoc_json").path(src_path));
|
||||
|
||||
let Some(base_commit) = &ci_info.base_commit else {
|
||||
check.verbose_msg("No base commit, skipping rustdoc_json check");
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ use std::path::Path;
|
|||
|
||||
use ignore::DirEntry;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::walk::walk;
|
||||
|
||||
// Array containing `("beginning of tag", "end of tag")`.
|
||||
const TAGS: &[(&str, &str)] = &[("{#", "#}"), ("{%", "%}"), ("{{", "}}")];
|
||||
|
||||
pub fn check(librustdoc_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("rustdoc_templates").path(librustdoc_path));
|
||||
pub fn check(librustdoc_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("rustdoc_templates").path(librustdoc_path));
|
||||
|
||||
walk(
|
||||
&librustdoc_path.join("html/templates"),
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use std::sync::LazyLock;
|
|||
use regex::RegexSetBuilder;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -339,8 +339,8 @@ fn is_unexplained_ignore(extension: &str, line: &str) -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("style").path(path));
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("style").path(path));
|
||||
|
||||
fn skip(path: &Path, is_dir: bool) -> bool {
|
||||
if path.file_name().is_some_and(|name| name.to_string_lossy().starts_with(".#")) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
use std::collections::HashSet;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
use crate::walk::{filter_not_rust, walk};
|
||||
|
||||
const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/";
|
||||
|
|
@ -24,8 +24,8 @@ const EXCEPTIONS: &[&str] = &[
|
|||
"xtensa_esp32s3_espidf",
|
||||
];
|
||||
|
||||
pub fn check(root_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("target_policy");
|
||||
pub fn check(root_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("target_policy");
|
||||
|
||||
let mut targets_to_find = HashSet::new();
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::iter_header::{HeaderLine, iter_header};
|
||||
use crate::walk::filter_not_rust;
|
||||
|
||||
|
|
@ -17,8 +17,8 @@ struct RevisionInfo<'a> {
|
|||
llvm_components: Option<Vec<&'a str>>,
|
||||
}
|
||||
|
||||
pub fn check(tests_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("target-specific-tests").path(tests_path));
|
||||
pub fn check(tests_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("target-specific-tests").path(tests_path));
|
||||
|
||||
crate::walk::walk(tests_path, |path, _is_dir| filter_not_rust(path), &mut |entry, content| {
|
||||
if content.contains("// ignore-tidy-target-specific-tests") {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
const FORBIDDEN_PATH: &str = "src/test";
|
||||
const ALLOWED_PATH: &str = "tests";
|
||||
|
||||
pub fn check(root_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("tests_placement");
|
||||
pub fn check(root_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("tests_placement");
|
||||
|
||||
if root_path.join(FORBIDDEN_PATH).exists() {
|
||||
check.error(format!(
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::collections::{BTreeMap, BTreeSet};
|
|||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::iter_header::*;
|
||||
use crate::walk::*;
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ const IGNORES: &[&str] = &[
|
|||
const EXTENSIONS: &[&str] = &["stdout", "stderr"];
|
||||
const SPECIAL_TEST: &str = "tests/ui/command/need-crate-arg-ignore-tidy.x.rs";
|
||||
|
||||
pub fn check(tests_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx
|
||||
pub fn check(tests_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx
|
||||
.start_check(CheckId::new("tests_revision_unpaired_stdout_stderr").path(tests_path));
|
||||
|
||||
// Recurse over subdirectories under `tests/`
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ use std::path::Path;
|
|||
|
||||
use toml::Value;
|
||||
|
||||
use crate::diagnostics::DiagCtx;
|
||||
use crate::diagnostics::TidyCtx;
|
||||
|
||||
pub fn check(path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("triagebot");
|
||||
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("triagebot");
|
||||
let triagebot_path = path.join("triagebot.toml");
|
||||
|
||||
// This check is mostly to catch broken path filters *within* `triagebot.toml`, and not enforce
|
||||
|
|
|
|||
|
|
@ -7,16 +7,17 @@ use std::fs;
|
|||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
|
||||
const ISSUES_TXT_HEADER: &str = r#"============================================================
|
||||
⚠️⚠️⚠️NOTHING SHOULD EVER BE ADDED TO THIS LIST⚠️⚠️⚠️
|
||||
============================================================
|
||||
"#;
|
||||
|
||||
pub fn check(root_path: &Path, bless: bool, diag_ctx: DiagCtx) {
|
||||
pub fn check(root_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let path = &root_path.join("tests");
|
||||
let mut check = diag_ctx.start_check(CheckId::new("ui_tests").path(path));
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("ui_tests").path(path));
|
||||
let bless = tidy_ctx.is_bless_enabled();
|
||||
|
||||
// the list of files in ui tests that are allowed to start with `issue-XXXX`
|
||||
// BTreeSet because we would like a stable ordering so --bless works
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
use crate::walk::{filter_dirs, walk};
|
||||
|
||||
pub fn check(root_path: &Path, stdlib: bool, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("unit_tests").path(root_path));
|
||||
pub fn check(root_path: &Path, stdlib: bool, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("unit_tests").path(root_path));
|
||||
|
||||
let skip = move |path: &Path, is_dir| {
|
||||
let file_name = path.file_name().unwrap_or_default();
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ use std::sync::OnceLock;
|
|||
use ignore::DirEntry;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
|
||||
use crate::iter_header::{HeaderLine, iter_header};
|
||||
use crate::walk::{filter_dirs, filter_not_rust, walk};
|
||||
|
||||
pub fn check(tests_path: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("unknown_revision").path(tests_path));
|
||||
pub fn check(tests_path: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("unknown_revision").path(tests_path));
|
||||
walk(
|
||||
tests_path,
|
||||
|path, is_dir| {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::collections::BTreeSet;
|
|||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::diagnostics::{DiagCtx, RunningCheck};
|
||||
use crate::diagnostics::{RunningCheck, TidyCtx};
|
||||
use crate::features::{CollectedFeatures, Features, Status};
|
||||
|
||||
pub const PATH_STR: &str = "doc/unstable-book";
|
||||
|
|
@ -85,8 +85,8 @@ fn maybe_suggest_dashes(names: &BTreeSet<String>, feature_name: &str, check: &mu
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, features: CollectedFeatures, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check("unstable_book");
|
||||
pub fn check(path: &Path, features: CollectedFeatures, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check("unstable_book");
|
||||
|
||||
let lang_features = features.lang;
|
||||
let lib_features = features
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ use std::process::{Command, Stdio};
|
|||
|
||||
use semver::Version;
|
||||
|
||||
use crate::diagnostics::{CheckId, DiagCtx};
|
||||
use crate::diagnostics::{CheckId, TidyCtx};
|
||||
|
||||
pub fn check(root: &Path, cargo: &Path, diag_ctx: DiagCtx) {
|
||||
let mut check = diag_ctx.start_check(CheckId::new("x_version").path(root));
|
||||
pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
|
||||
let mut check = tidy_ctx.start_check(CheckId::new("x_version").path(root));
|
||||
let cargo_list = Command::new(cargo).args(["install", "--list"]).stdout(Stdio::piped()).spawn();
|
||||
|
||||
let child = match cargo_list {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue