]> git.proxmox.com Git - rustc.git/blame - src/tools/tidy/src/lib.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / tools / tidy / src / lib.rs
CommitLineData
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
18use std::fs;
19
20use std::path::Path;
21
22macro_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
34macro_rules! tidy_error {
35 ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
041b39d2 36 *$bad = true;
abe05a73
XL
37 eprint!("tidy error: ");
38 eprintln!($fmt, $($arg)*);
041b39d2
XL
39 });
40}
41
42pub mod bins;
43pub mod style;
44pub mod errors;
45pub mod features;
46pub mod cargo;
47pub mod pal;
48pub mod deps;
49pub mod unstable_book;
50
51fn filter_dirs(path: &Path) -> bool {
52 let skip = [
abe05a73
XL
53 "src/binaryen",
54 "src/dlmalloc",
041b39d2
XL
55 "src/jemalloc",
56 "src/llvm",
57 "src/libbacktrace",
58 "src/libcompiler_builtins",
59 "src/compiler-rt",
60 "src/rustllvm",
61 "src/liblibc",
62 "src/vendor",
63 "src/rt/hoedown",
64 "src/tools/cargo",
65 "src/tools/rls",
ea8adc8c 66 "src/tools/clippy",
041b39d2 67 "src/tools/rust-installer",
ea8adc8c
XL
68 "src/tools/rustfmt",
69 "src/tools/miri",
041b39d2
XL
70 ];
71 skip.iter().any(|p| path.ends_with(p))
72}
73
74fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
75 for path in paths {
76 walk(path, skip, f);
77 }
78}
79
80fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
81 for entry in t!(fs::read_dir(path), path) {
82 let entry = t!(entry);
83 let kind = t!(entry.file_type());
84 let path = entry.path();
85 if kind.is_dir() {
86 if !skip(&path) {
87 walk(&path, skip, f);
88 }
89 } else {
90 f(&path);
91 }
92 }
93}