]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/main.rs
Lint against executable files in the root directory
[rust.git] / src / tools / tidy / src / main.rs
1 //! Tidy checks source code in this repository.
2 //!
3 //! This program runs all of the various tidy checks for style, cleanliness,
4 //! etc. This is run by default on `./x.py test` and as part of the auto
5 //! builders. The tidy checks can be executed with `./x.py test tidy`.
6
7 use tidy::*;
8
9 use crossbeam_utils::thread::{scope, ScopedJoinHandle};
10 use std::collections::VecDeque;
11 use std::env;
12 use std::num::NonZeroUsize;
13 use std::path::PathBuf;
14 use std::process;
15 use std::str::FromStr;
16 use std::sync::atomic::{AtomicBool, Ordering};
17
18 fn main() {
19     let root_path: PathBuf = env::args_os().nth(1).expect("need path to root of repo").into();
20     let cargo: PathBuf = env::args_os().nth(2).expect("need path to cargo").into();
21     let output_directory: PathBuf =
22         env::args_os().nth(3).expect("need path to output directory").into();
23     let concurrency: NonZeroUsize =
24         FromStr::from_str(&env::args().nth(4).expect("need concurrency"))
25             .expect("concurrency must be a number");
26
27     let src_path = root_path.join("src");
28     let library_path = root_path.join("library");
29     let compiler_path = root_path.join("compiler");
30
31     let args: Vec<String> = env::args().skip(1).collect();
32
33     let verbose = args.iter().any(|s| *s == "--verbose");
34
35     let bad = std::sync::Arc::new(AtomicBool::new(false));
36
37     scope(|s| {
38         let mut handles: VecDeque<ScopedJoinHandle<'_, ()>> =
39             VecDeque::with_capacity(concurrency.get());
40
41         macro_rules! check {
42             ($p:ident $(, $args:expr)* ) => {
43                 while handles.len() >= concurrency.get() {
44                     handles.pop_front().unwrap().join().unwrap();
45                 }
46
47                 let handle = s.spawn(|_| {
48                     let mut flag = false;
49                     $p::check($($args),* , &mut flag);
50                     if (flag) {
51                         bad.store(true, Ordering::Relaxed);
52                     }
53                 });
54                 handles.push_back(handle);
55             }
56         }
57
58         check!(target_specific_tests, &src_path);
59
60         // Checks that are done on the cargo workspace.
61         check!(deps, &root_path, &cargo);
62         check!(extdeps, &root_path);
63
64         // Checks over tests.
65         check!(debug_artifacts, &src_path);
66         check!(ui_tests, &src_path);
67
68         // Checks that only make sense for the compiler.
69         check!(errors, &compiler_path);
70         check!(error_codes_check, &[&src_path, &compiler_path]);
71
72         // Checks that only make sense for the std libs.
73         check!(pal, &library_path);
74         check!(primitive_docs, &library_path);
75
76         // Checks that need to be done for both the compiler and std libraries.
77         check!(unit_tests, &src_path);
78         check!(unit_tests, &compiler_path);
79         check!(unit_tests, &library_path);
80
81         if bins::check_filesystem_support(&[&root_path], &output_directory) {
82             check!(bins, &root_path);
83         }
84
85         check!(style, &src_path);
86         check!(style, &compiler_path);
87         check!(style, &library_path);
88
89         check!(edition, &src_path);
90         check!(edition, &compiler_path);
91         check!(edition, &library_path);
92
93         let collected = {
94             while handles.len() >= concurrency.get() {
95                 handles.pop_front().unwrap().join().unwrap();
96             }
97             let mut flag = false;
98             let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
99             if flag {
100                 bad.store(true, Ordering::Relaxed);
101             }
102             r
103         };
104         check!(unstable_book, &src_path, collected);
105     })
106     .unwrap();
107
108     if bad.load(Ordering::Relaxed) {
109         eprintln!("some tidy checks failed");
110         process::exit(1);
111     }
112 }