]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/lib.rs
Rollup merge of #60444 - nikomatsakis:issue-60010-cycle-error-investigation, r=pnkfelix
[rust.git] / src / tools / tidy / src / lib.rs
1 //! Library used by tidy and other tools.
2 //!
3 //! This library contains the tidy lints and exposes it
4 //! to be used by tools.
5
6 use std::fs;
7
8 use std::path::Path;
9
10 macro_rules! t {
11     ($e:expr, $p:expr) => (match $e {
12         Ok(e) => e,
13         Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
14     });
15
16     ($e:expr) => (match $e {
17         Ok(e) => e,
18         Err(e) => panic!("{} failed with {}", stringify!($e), e),
19     })
20 }
21
22 macro_rules! tidy_error {
23     ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
24         *$bad = true;
25         eprint!("tidy error: ");
26         eprintln!($fmt, $($arg)*);
27     });
28 }
29
30 pub mod bins;
31 pub mod style;
32 pub mod errors;
33 pub mod features;
34 pub mod cargo;
35 pub mod pal;
36 pub mod deps;
37 pub mod extdeps;
38 pub mod ui_tests;
39 pub mod unstable_book;
40 pub mod libcoretest;
41
42 fn filter_dirs(path: &Path) -> bool {
43     let skip = [
44         "src/llvm",
45         "src/llvm-project",
46         "src/llvm-emscripten",
47         "src/libbacktrace",
48         "src/librustc_data_structures/owning_ref",
49         "src/vendor",
50         "src/tools/cargo",
51         "src/tools/clang",
52         "src/tools/rls",
53         "src/tools/clippy",
54         "src/tools/rust-installer",
55         "src/tools/rustfmt",
56         "src/tools/miri",
57         "src/tools/lld",
58         "src/tools/lldb",
59         "src/target",
60         "src/stdsimd",
61         "src/rust-sgx",
62         "target",
63         "vendor",
64     ];
65     skip.iter().any(|p| path.ends_with(p))
66 }
67
68 fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
69     for path in paths {
70         walk(path, skip, f);
71     }
72 }
73
74 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
75     if let Ok(dir) = fs::read_dir(path) {
76         for entry in dir {
77             let entry = t!(entry);
78             let kind = t!(entry.file_type());
79             let path = entry.path();
80             if kind.is_dir() {
81                 if !skip(&path) {
82                     walk(&path, skip, f);
83                 }
84             } else {
85                 f(&path);
86             }
87         }
88     }
89 }