From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/tools/tier-check/Cargo.toml | 7 ++++++ src/tools/tier-check/src/main.rs | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/tools/tier-check/Cargo.toml create mode 100644 src/tools/tier-check/src/main.rs (limited to 'src/tools/tier-check') 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); + } +} -- cgit v1.2.3