diff options
| author | est31 <MTest31@outlook.com> | 2017-06-12 15:06:12 +0200 |
|---|---|---|
| committer | est31 <MTest31@outlook.com> | 2017-06-14 04:59:07 +0200 |
| commit | d81089875153046f80057f08eaf3ea5f40676010 (patch) | |
| tree | 7fbb8b56acbd8739faf745c9023baf4ac0d5582e | |
| parent | e40ef964fe491b19c22dfb8dd36d1eab14223c36 (diff) | |
| download | rust-d81089875153046f80057f08eaf3ea5f40676010.tar.gz rust-d81089875153046f80057f08eaf3ea5f40676010.zip | |
Librarify tidy
Convert tidy into a library so that the data it creates can be used by external tools.
| -rw-r--r-- | src/tools/tidy/src/lib.rs | 88 | ||||
| -rw-r--r-- | src/tools/tidy/src/main.rs | 80 |
2 files changed, 96 insertions, 72 deletions
diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs new file mode 100644 index 00000000000..bcf86e4489b --- /dev/null +++ b/src/tools/tidy/src/lib.rs @@ -0,0 +1,88 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Library used by tidy and other tools +//! +//! This library contains the tidy lints and exposes it +//! to be used by tools. + +#![deny(warnings)] + +use std::fs; + +use std::path::Path; + +macro_rules! t { + ($e:expr, $p:expr) => (match $e { + Ok(e) => e, + Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e), + }); + + ($e:expr) => (match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with {}", stringify!($e), e), + }) +} + +macro_rules! tidy_error { + ($bad:expr, $fmt:expr, $($arg:tt)*) => ({ + use std::io::Write; + *$bad = true; + write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr"); + writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr"); + }); +} + +pub mod bins; +pub mod style; +pub mod errors; +pub mod features; +pub mod cargo; +pub mod pal; +pub mod deps; +pub mod unstable_book; + +fn filter_dirs(path: &Path) -> bool { + let skip = [ + "src/jemalloc", + "src/llvm", + "src/libbacktrace", + "src/compiler-rt", + "src/rustllvm", + "src/liblibc", + "src/vendor", + "src/rt/hoedown", + "src/tools/cargo", + "src/tools/rls", + "src/tools/rust-installer", + ]; + skip.iter().any(|p| path.ends_with(p)) +} + +fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) { + for path in paths { + walk(path, skip, f); + } +} + +fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) { + for entry in t!(fs::read_dir(path), path) { + let entry = t!(entry); + let kind = t!(entry.file_type()); + let path = entry.path(); + if kind.is_dir() { + if !skip(&path) { + walk(&path, skip, f); + } + } else { + f(&path); + } + } +} diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 23a31131f7a..433192a21ec 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -8,47 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Tidy checks for source code in this repository +//! Tidy checks source code in this repository //! //! This program runs all of the various tidy checks for style, cleanliness, //! etc. This is run by default on `make check` and as part of the auto //! builders. -use std::env; -use std::fs; -use std::io::{self, Write}; -use std::path::{PathBuf, Path}; -use std::process; +#![deny(warnings)] -macro_rules! t { - ($e:expr, $p:expr) => (match $e { - Ok(e) => e, - Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e), - }); - - ($e:expr) => (match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with {}", stringify!($e), e), - }) -} +extern crate tidy; +use tidy::*; -macro_rules! tidy_error { - ($bad:expr, $fmt:expr, $($arg:tt)*) => ({ - use std::io::Write; - *$bad = true; - write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr"); - writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr"); - }); -} - -mod bins; -mod style; -mod errors; -mod features; -mod cargo; -mod pal; -mod deps; -mod unstable_book; +use std::process; +use std::path::PathBuf; +use std::env; +use std::io::{self, Write}; fn main() { let path = env::args_os().skip(1).next().expect("need an argument"); @@ -74,41 +48,3 @@ fn main() { process::exit(1); } } - -fn filter_dirs(path: &Path) -> bool { - let skip = [ - "src/jemalloc", - "src/llvm", - "src/libbacktrace", - "src/compiler-rt", - "src/rustllvm", - "src/liblibc", - "src/vendor", - "src/rt/hoedown", - "src/tools/cargo", - "src/tools/rls", - "src/tools/rust-installer", - ]; - skip.iter().any(|p| path.ends_with(p)) -} - -fn walk_many(paths: &[&Path], skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) { - for path in paths { - walk(path, skip, f); - } -} - -fn walk(path: &Path, skip: &mut FnMut(&Path) -> bool, f: &mut FnMut(&Path)) { - for entry in t!(fs::read_dir(path), path) { - let entry = t!(entry); - let kind = t!(entry.file_type()); - let path = entry.path(); - if kind.is_dir() { - if !skip(&path) { - walk(&path, skip, f); - } - } else { - f(&path); - } - } -} |
