]>
git.proxmox.com Git - rustc.git/blob - src/tools/tier-check/src/main.rs
1 //! This is a script for validating the platform support page in the rustc book.
3 //! The script takes two arguments, the path to the Platform Support source
4 //! page, and the second argument is the path to `rustc`.
6 use std
::collections
::HashSet
;
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")
16 .expect("rustc should run");
17 if !output
.status
.success() {
18 eprintln
!("rustc failed to run");
19 std
::process
::exit(0);
21 let stdout
= std
::str::from_utf8(&output
.stdout
).expect("utf8");
22 let target_list
: HashSet
<_
> = stdout
.lines().collect();
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
27 .filter(|line
| line
.starts_with('`'
) && line
.contains('
|'
))
28 .map(|line
| line
.split('`'
).skip(1).next().expect("expected target code span"))
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
{
35 "error: target `{}` is missing from {}\n\
36 If this is a new target, please add it to {}.",
40 for target
in &extra
{
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.",
47 if !missing
.is_empty() || !extra
.is_empty() {
48 std
::process
::exit(1);