]>
Commit | Line | Data |
---|---|---|
041b39d2 XL |
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 | #![deny(warnings)] | |
17 | ||
18 | use std::fs; | |
19 | ||
20 | use std::path::Path; | |
21 | ||
22 | macro_rules! t { | |
23 | ($e:expr, $p:expr) => (match $e { | |
24 | Ok(e) => e, | |
25 | Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e), | |
26 | }); | |
27 | ||
28 | ($e:expr) => (match $e { | |
29 | Ok(e) => e, | |
30 | Err(e) => panic!("{} failed with {}", stringify!($e), e), | |
31 | }) | |
32 | } | |
33 | ||
34 | macro_rules! tidy_error { | |
35 | ($bad:expr, $fmt:expr, $($arg:tt)*) => ({ | |
36 | use std::io::Write; | |
37 | *$bad = true; | |
38 | write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr"); | |
39 | writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr"); | |
40 | }); | |
41 | } | |
42 | ||
43 | pub mod bins; | |
44 | pub mod style; | |
45 | pub mod errors; | |
46 | pub mod features; | |
47 | pub mod cargo; | |
48 | pub mod pal; | |
49 | pub mod deps; | |
50 | pub mod unstable_book; | |
51 | ||
52 | fn filter_dirs(path: &Path) -> bool { | |
53 | let skip = [ | |
54 | "src/jemalloc", | |
55 | "src/llvm", | |
56 | "src/libbacktrace", | |
57 | "src/libcompiler_builtins", | |
58 | "src/compiler-rt", | |
59 | "src/rustllvm", | |
60 | "src/liblibc", | |
61 | "src/vendor", | |
62 | "src/rt/hoedown", | |
63 | "src/tools/cargo", | |
64 | "src/tools/rls", | |
65 | "src/tools/rust-installer", | |
66 | ]; | |
67 | skip.iter().any(|p| path.ends_with(p)) | |
68 | } | |
69 | ||
70 | fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) { | |
71 | for path in paths { | |
72 | walk(path, skip, f); | |
73 | } | |
74 | } | |
75 | ||
76 | fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) { | |
77 | for entry in t!(fs::read_dir(path), path) { | |
78 | let entry = t!(entry); | |
79 | let kind = t!(entry.file_type()); | |
80 | let path = entry.path(); | |
81 | if kind.is_dir() { | |
82 | if !skip(&path) { | |
83 | walk(&path, skip, f); | |
84 | } | |
85 | } else { | |
86 | f(&path); | |
87 | } | |
88 | } | |
89 | } |