summaryrefslogtreecommitdiffstats
path: root/src/tools/tier-check
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/tier-check
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/tier-check')
-rw-r--r--src/tools/tier-check/Cargo.toml7
-rw-r--r--src/tools/tier-check/src/main.rs50
2 files changed, 57 insertions, 0 deletions
diff --git a/src/tools/tier-check/Cargo.toml b/src/tools/tier-check/Cargo.toml
new file mode 100644
index 000000000..3f08165a3
--- /dev/null
+++ b/src/tools/tier-check/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "tier-check"
+version = "0.1.0"
+edition = "2021"
+license = "MIT OR Apache-2.0"
+
+[dependencies]
diff --git a/src/tools/tier-check/src/main.rs b/src/tools/tier-check/src/main.rs
new file mode 100644
index 000000000..a41e2d6e3
--- /dev/null
+++ b/src/tools/tier-check/src/main.rs
@@ -0,0 +1,50 @@
+//! This is a script for validating the platform support page in the rustc book.
+//!
+//! The script takes two arguments, the path to the Platform Support source
+//! page, and the second argument is the path to `rustc`.
+
+use std::collections::HashSet;
+
+fn main() {
+ let mut args = std::env::args().skip(1);
+ let src = args.next().expect("expected source file as first argument");
+ let filename = std::path::Path::new(&src).file_name().unwrap().to_str().unwrap();
+ let rustc = args.next().expect("expected rustc as second argument");
+ let output = std::process::Command::new(rustc)
+ .arg("--print=target-list")
+ .output()
+ .expect("rustc should run");
+ if !output.status.success() {
+ eprintln!("rustc failed to run");
+ std::process::exit(0);
+ }
+ let stdout = std::str::from_utf8(&output.stdout).expect("utf8");
+ let target_list: HashSet<_> = stdout.lines().collect();
+
+ let doc_targets_md = std::fs::read_to_string(&src).expect("failed to read input source");
+ let doc_targets: HashSet<_> = doc_targets_md
+ .lines()
+ .filter(|line| line.starts_with(&['`', '['][..]) && line.contains('|'))
+ .map(|line| line.split('`').skip(1).next().expect("expected target code span"))
+ .collect();
+
+ let missing: Vec<_> = target_list.difference(&doc_targets).collect();
+ let extra: Vec<_> = doc_targets.difference(&target_list).collect();
+ for target in &missing {
+ eprintln!(
+ "error: target `{}` is missing from {}\n\
+ If this is a new target, please add it to {}.",
+ target, filename, src
+ );
+ }
+ for target in &extra {
+ eprintln!(
+ "error: target `{}` is in {}, but does not appear in the rustc target list\n\
+ If the target has been removed, please edit {} and remove the target.",
+ target, filename, src
+ );
+ }
+ if !missing.is_empty() || !extra.is_empty() {
+ std::process::exit(1);
+ }
+}