]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/lib.rs
Add x86_64-fortanix-unknown-sgx target to libstd and dependencies
[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 extdeps;
53 pub mod ui_tests;
54 pub mod unstable_book;
55 pub mod libcoretest;
56
57 fn filter_dirs(path: &Path) -> bool {
58     let skip = [
59         "src/dlmalloc",
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/rt/hoedown",
68         "src/tools/cargo",
69         "src/tools/clang",
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/tools/lldb",
77         "src/target",
78         "src/stdsimd",
79         "src/rust-sgx",
80         "target",
81         "vendor",
82     ];
83     skip.iter().any(|p| path.ends_with(p))
84 }
85
86 fn walk_many(paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
87     for path in paths {
88         walk(path, skip, f);
89     }
90 }
91
92 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&Path)) {
93     if let Ok(dir) = fs::read_dir(path) {
94         for entry in dir {
95             let entry = t!(entry);
96             let kind = t!(entry.file_type());
97             let path = entry.path();
98             if kind.is_dir() {
99                 if !skip(&path) {
100                     walk(&path, skip, f);
101                 }
102             } else {
103                 f(&path);
104             }
105         }
106     }
107 }