1 //! Tidy checks source code in this repository.
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`.
9 use std::collections::VecDeque;
11 use std::num::NonZeroUsize;
12 use std::path::PathBuf;
14 use std::str::FromStr;
15 use std::sync::atomic::{AtomicBool, Ordering};
16 use std::thread::{scope, ScopedJoinHandle};
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");
27 let src_path = root_path.join("src");
28 let library_path = root_path.join("library");
29 let compiler_path = root_path.join("compiler");
31 let args: Vec<String> = env::args().skip(1).collect();
33 let verbose = args.iter().any(|s| *s == "--verbose");
35 let bad = std::sync::Arc::new(AtomicBool::new(false));
38 let mut handles: VecDeque<ScopedJoinHandle<'_, ()>> =
39 VecDeque::with_capacity(concurrency.get());
42 ($p:ident $(, $args:expr)* ) => {
43 while handles.len() >= concurrency.get() {
44 handles.pop_front().unwrap().join().unwrap();
47 let handle = s.spawn(|| {
49 $p::check($($args),* , &mut flag);
51 bad.store(true, Ordering::Relaxed);
54 handles.push_back(handle);
58 check!(target_specific_tests, &src_path);
60 // Checks that are done on the cargo workspace.
61 check!(deps, &root_path, &cargo);
62 check!(extdeps, &root_path);
65 check!(debug_artifacts, &src_path);
66 check!(ui_tests, &src_path);
68 // Checks that only make sense for the compiler.
69 check!(errors, &compiler_path);
70 check!(error_codes_check, &[&src_path, &compiler_path]);
72 // Checks that only make sense for the std libs.
73 check!(pal, &library_path);
74 check!(primitive_docs, &library_path);
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);
81 if bins::check_filesystem_support(&[&root_path], &output_directory) {
82 check!(bins, &root_path);
85 check!(style, &src_path);
86 check!(style, &compiler_path);
87 check!(style, &library_path);
89 check!(edition, &src_path);
90 check!(edition, &compiler_path);
91 check!(edition, &library_path);
93 check!(alphabetical, &compiler_path);
96 while handles.len() >= concurrency.get() {
97 handles.pop_front().unwrap().join().unwrap();
100 let r = features::check(&src_path, &compiler_path, &library_path, &mut flag, verbose);
102 bad.store(true, Ordering::Relaxed);
106 check!(unstable_book, &src_path, collected);
109 if bad.load(Ordering::Relaxed) {
110 eprintln!("some tidy checks failed");