]>
Commit | Line | Data |
---|---|---|
9fa01778 | 1 | //! Tidy checks source code in this repository. |
a7813a04 XL |
2 | //! |
3 | //! This program runs all of the various tidy checks for style, cleanliness, | |
ba9703b0 XL |
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`. | |
a7813a04 | 6 | |
041b39d2 | 7 | use tidy::*; |
a7813a04 | 8 | |
cdc7bbd5 XL |
9 | use crossbeam_utils::thread::{scope, ScopedJoinHandle}; |
10 | use std::collections::VecDeque; | |
041b39d2 | 11 | use std::env; |
cdc7bbd5 | 12 | use std::num::NonZeroUsize; |
dfeec247 XL |
13 | use std::path::PathBuf; |
14 | use std::process; | |
cdc7bbd5 XL |
15 | use std::str::FromStr; |
16 | use std::sync::atomic::{AtomicBool, Ordering}; | |
a7813a04 XL |
17 | |
18 | fn main() { | |
1b1a35ee | 19 | let root_path: PathBuf = env::args_os().nth(1).expect("need path to root of repo").into(); |
b7449926 | 20 | let cargo: PathBuf = env::args_os().nth(2).expect("need path to cargo").into(); |
29967ef6 XL |
21 | let output_directory: PathBuf = |
22 | env::args_os().nth(3).expect("need path to output directory").into(); | |
cdc7bbd5 XL |
23 | let concurrency: NonZeroUsize = |
24 | FromStr::from_str(&env::args().nth(4).expect("need concurrency")) | |
25 | .expect("concurrency must be a number"); | |
0531ce1d | 26 | |
1b1a35ee XL |
27 | let src_path = root_path.join("src"); |
28 | let library_path = root_path.join("library"); | |
29 | let compiler_path = root_path.join("compiler"); | |
3dfed10e | 30 | |
8bb4bdeb XL |
31 | let args: Vec<String> = env::args().skip(1).collect(); |
32 | ||
dc9dc135 | 33 | let verbose = args.iter().any(|s| *s == "--verbose"); |
3dfed10e | 34 | |
cdc7bbd5 XL |
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 | // Checks that are done on the cargo workspace. | |
59 | check!(deps, &root_path, &cargo); | |
60 | check!(extdeps, &root_path); | |
61 | ||
62 | // Checks over tests. | |
63 | check!(debug_artifacts, &src_path); | |
64 | check!(ui_tests, &src_path); | |
65 | ||
66 | // Checks that only make sense for the compiler. | |
67 | check!(errors, &compiler_path); | |
68 | check!(error_codes_check, &[&src_path, &compiler_path]); | |
69 | ||
70 | // Checks that only make sense for the std libs. | |
71 | check!(pal, &library_path); | |
72 | ||
73 | // Checks that need to be done for both the compiler and std libraries. | |
74 | check!(unit_tests, &src_path); | |
75 | check!(unit_tests, &compiler_path); | |
76 | check!(unit_tests, &library_path); | |
77 | ||
78 | if bins::check_filesystem_support( | |
79 | &[&src_path, &compiler_path, &library_path], | |
80 | &output_directory, | |
81 | ) { | |
82 | check!(bins, &src_path); | |
83 | check!(bins, &compiler_path); | |
84 | check!(bins, &library_path); | |
85 | } | |
86 | ||
87 | check!(style, &src_path); | |
88 | check!(style, &compiler_path); | |
89 | check!(style, &library_path); | |
90 | ||
91 | check!(edition, &src_path); | |
92 | check!(edition, &compiler_path); | |
93 | check!(edition, &library_path); | |
94 | ||
95 | let collected = { | |
96 | while handles.len() >= concurrency.get() { | |
97 | handles.pop_front().unwrap().join().unwrap(); | |
98 | } | |
99 | let mut flag = false; | |
100 | let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose); | |
101 | if flag { | |
102 | bad.store(true, Ordering::Relaxed); | |
103 | } | |
104 | r | |
105 | }; | |
106 | check!(unstable_book, &src_path, collected); | |
107 | }) | |
108 | .unwrap(); | |
109 | ||
110 | if bad.load(Ordering::Relaxed) { | |
abe05a73 | 111 | eprintln!("some tidy checks failed"); |
cc61c64b | 112 | process::exit(1); |
a7813a04 XL |
113 | } |
114 | } |