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.
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.
11 //! Tidy checks for source code in this repository
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
21 use std::io::{self, Write};
22 use std::path::{PathBuf, Path};
26 ($e:expr, $p:expr) => (match $e {
28 Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
31 ($e:expr) => (match $e {
33 Err(e) => panic!("{} failed with {}", stringify!($e), e),
37 macro_rules! tidy_error {
38 ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
41 write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr");
42 writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr");
56 let path = env::args_os().skip(1).next().expect("need an argument");
57 let path = PathBuf::from(path);
59 let args: Vec<String> = env::args().skip(1).collect();
62 bins::check(&path, &mut bad);
63 style::check(&path, &mut bad);
64 errors::check(&path, &mut bad);
65 cargo::check(&path, &mut bad);
66 features::check(&path, &mut bad);
67 pal::check(&path, &mut bad);
68 unstable_book::check(&path, &mut bad);
69 if !args.iter().any(|s| *s == "--no-vendor") {
70 deps::check(&path, &mut bad);
74 writeln!(io::stderr(), "some tidy checks failed").expect("could not write to stderr");
79 fn filter_dirs(path: &Path) -> bool {
92 skip.iter().any(|p| path.ends_with(p))
95 fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
101 fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) {
102 for entry in t!(fs::read_dir(path), path) {
103 let entry = t!(entry);
104 let kind = t!(entry.file_type());
105 let path = entry.path();
108 walk(&path, skip, f);