]> git.proxmox.com Git - rustc.git/blob - src/tools/tier-check/src/main.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / tools / tier-check / src / main.rs
1 //! This is a script for validating the platform support page in the rustc book.
2 //!
3 //! The script takes two arguments, the path to the Platform Support source
4 //! page, and the second argument is the path to `rustc`.
5
6 use std::collections::HashSet;
7
8 fn main() {
9 let mut args = std::env::args().skip(1);
10 let src = args.next().expect("expected source file as first argument");
11 let filename = std::path::Path::new(&src).file_name().unwrap().to_str().unwrap();
12 let rustc = args.next().expect("expected rustc as second argument");
13 let output = std::process::Command::new(rustc)
14 .arg("--print=target-list")
15 .output()
16 .expect("rustc should run");
17 if !output.status.success() {
18 eprintln!("rustc failed to run");
19 std::process::exit(0);
20 }
21 let stdout = std::str::from_utf8(&output.stdout).expect("utf8");
22 let target_list: HashSet<_> = stdout.lines().collect();
23
24 let doc_targets_md = std::fs::read_to_string(&src).expect("failed to read input source");
25 let doc_targets: HashSet<_> = doc_targets_md
26 .lines()
27 .filter(|line| line.starts_with('`') && line.contains('|'))
28 .map(|line| line.split('`').skip(1).next().expect("expected target code span"))
29 .collect();
30
31 let missing: Vec<_> = target_list.difference(&doc_targets).collect();
32 let extra: Vec<_> = doc_targets.difference(&target_list).collect();
33 for target in &missing {
34 eprintln!(
35 "error: target `{}` is missing from {}\n\
36 If this is a new target, please add it to {}.",
37 target, filename, src
38 );
39 }
40 for target in &extra {
41 eprintln!(
42 "error: target `{}` is in {}, but does not appear in the rustc target list\n\
43 If the target has been removed, please edit {} and remove the target.",
44 target, filename, src
45 );
46 }
47 if !missing.is_empty() || !extra.is_empty() {
48 std::process::exit(1);
49 }
50 }