]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/main.rs
rustdoc: Hide `self: Box<Self>` in list of deref methods
[rust.git] / src / tools / tidy / src / main.rs
1 // Copyright 2016 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 //! Tidy checks for source code in this repository
12 //!
13 //! This program runs all of the various tidy checks for style, cleanliness,
14 //! etc. This is run by default on `make check` and as part of the auto
15 //! builders.
16
17 use std::env;
18 use std::fs;
19 use std::io::{self, Write};
20 use std::path::{PathBuf, Path};
21 use std::process;
22
23 macro_rules! t {
24     ($e:expr, $p:expr) => (match $e {
25         Ok(e) => e,
26         Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
27     });
28
29     ($e:expr) => (match $e {
30         Ok(e) => e,
31         Err(e) => panic!("{} failed with {}", stringify!($e), e),
32     })
33 }
34
35 macro_rules! tidy_error {
36     ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
37         use std::io::Write;
38         *$bad = true;
39         write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr");
40         writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr");
41     });
42 }
43
44 mod bins;
45 mod style;
46 mod errors;
47 mod features;
48 mod cargo;
49 mod pal;
50 mod deps;
51 mod unstable_book;
52
53 fn main() {
54     let path = env::args_os().skip(1).next().expect("need an argument");
55     let path = PathBuf::from(path);
56
57     let args: Vec<String> = env::args().skip(1).collect();
58
59     let mut bad = false;
60     bins::check(&path, &mut bad);
61     style::check(&path, &mut bad);
62     errors::check(&path, &mut bad);
63     cargo::check(&path, &mut bad);
64     features::check(&path, &mut bad);
65     pal::check(&path, &mut bad);
66     unstable_book::check(&path, &mut bad);
67     if !args.iter().any(|s| *s == "--no-vendor") {
68         deps::check(&path, &mut bad);
69     }
70
71     if bad {
72         writeln!(io::stderr(), "some tidy checks failed").expect("could not write to stderr");
73         process::exit(1);
74     }
75 }
76
77 fn filter_dirs(path: &Path) -> bool {
78     let skip = [
79         "src/jemalloc",
80         "src/llvm",
81         "src/libbacktrace",
82         "src/compiler-rt",
83         "src/rustllvm",
84         "src/liblibc",
85         "src/vendor",
86         "src/rt/hoedown",
87         "src/tools/cargo",
88         "src/tools/rls",
89         "src/tools/rust-installer",
90     ];
91     skip.iter().any(|p| path.ends_with(p))
92 }
93
94 fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
95     for path in paths {
96         walk(path, skip, f);
97     }
98 }
99
100 fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
101     for entry in t!(fs::read_dir(path), path) {
102         let entry = t!(entry);
103         let kind = t!(entry.file_type());
104         let path = entry.path();
105         if kind.is_dir() {
106             if !skip(&path) {
107                 walk(&path, skip, f);
108             }
109         } else {
110             f(&path);
111         }
112     }
113 }