]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/lib.rs
Rollup merge of #50464 - est31:master, r=rkruppe
[rust.git] / src / tools / tidy / src / lib.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Library used by tidy and other tools
12 //!
13 //! This library contains the tidy lints and exposes it
14 //! to be used by tools.
15
16 extern crate serde;
17 extern crate serde_json;
18 #[macro_use]
19 extern crate serde_derive;
20
21 use std::fs;
22
23 use std::path::Path;
24
25 macro_rules! t {
26     ($e:expr, $p:expr) => (match $e {
27         Ok(e) => e,
28         Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
29     });
30
31     ($e:expr) => (match $e {
32         Ok(e) => e,
33         Err(e) => panic!("{} failed with {}", stringify!($e), e),
34     })
35 }
36
37 macro_rules! tidy_error {
38     ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
39         *$bad = true;
40         eprint!("tidy error: ");
41         eprintln!($fmt, $($arg)*);
42     });
43 }
44
45 pub mod bins;
46 pub mod style;
47 pub mod errors;
48 pub mod features;
49 pub mod cargo;
50 pub mod pal;
51 pub mod deps;
52 pub mod ui_tests;
53 pub mod unstable_book;
54 pub mod libcoretest;
55
56 fn filter_dirs(path: &Path) -> bool {
57     let skip = [
58         "src/dlmalloc",
59         "src/jemalloc",
60         "src/llvm",
61         "src/llvm-emscripten",
62         "src/libbacktrace",
63         "src/libcompiler_builtins",
64         "src/librustc_data_structures/owning_ref",
65         "src/compiler-rt",
66         "src/liblibc",
67         "src/vendor",
68         "src/rt/hoedown",
69         "src/tools/cargo",
70         "src/tools/rls",
71         "src/tools/clippy",
72         "src/tools/rust-installer",
73         "src/tools/rustfmt",
74         "src/tools/miri",
75         "src/tools/lld",
76         "src/librustc/mir/interpret",
77         "src/librustc_mir/interpret",
78         "src/target",
79         "src/stdsimd",
80     ];
81     skip.iter().any(|p| path.ends_with(p))
82 }
83
84 fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
85     for path in paths {
86         walk(path, skip, f);
87     }
88 }
89
90 fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
91     for entry in t!(fs::read_dir(path), path) {
92         let entry = t!(entry);
93         let kind = t!(entry.file_type());
94         let path = entry.path();
95         if kind.is_dir() {
96             if !skip(&path) {
97                 walk(&path, skip, f);
98             }
99         } else {
100             f(&path);
101         }
102     }
103 }