From a14aeaeee05d0c3568767f95fd506e3f7c925298 Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Mon, 25 Nov 2024 16:00:57 -0800 Subject: [PATCH 1/2] Add new tool for dumping feature status based on tidy --- Cargo.lock | 10 +++++++ Cargo.toml | 1 + src/tools/features-status-dump/Cargo.toml | 10 +++++++ src/tools/features-status-dump/src/main.rs | 31 ++++++++++++++++++++++ src/tools/tidy/Cargo.toml | 1 + src/tools/tidy/src/features.rs | 2 ++ src/tools/tidy/src/features/version.rs | 1 + 7 files changed, 56 insertions(+) create mode 100644 src/tools/features-status-dump/Cargo.toml create mode 100644 src/tools/features-status-dump/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 29176a3ae8e20..190eaed1a0095 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1187,6 +1187,15 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +[[package]] +name = "features-status-dump" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "tidy", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -5249,6 +5258,7 @@ dependencies = [ "regex", "rustc-hash 2.0.0", "semver", + "serde", "similar", "termcolor", "walkdir", diff --git a/Cargo.toml b/Cargo.toml index b773030b4cab4..68d142ebe9265 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ members = [ "src/tools/coverage-dump", "src/tools/rustc-perf-wrapper", "src/tools/wasm-component-ld", + "src/tools/features-status-dump", ] exclude = [ diff --git a/src/tools/features-status-dump/Cargo.toml b/src/tools/features-status-dump/Cargo.toml new file mode 100644 index 0000000000000..fd5ac7c13ee23 --- /dev/null +++ b/src/tools/features-status-dump/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "features-status-dump" +version = "0.1.0" +license = "MIT OR Apache-2.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0.125", features = [ "derive" ] } +serde_json = "1.0.59" +tidy = { path = "../tidy" } diff --git a/src/tools/features-status-dump/src/main.rs b/src/tools/features-status-dump/src/main.rs new file mode 100644 index 0000000000000..24ea4f758b433 --- /dev/null +++ b/src/tools/features-status-dump/src/main.rs @@ -0,0 +1,31 @@ +use std::collections::HashMap; +use std::io::BufWriter; +use std::{env, fs::File}; +use std::path::Path; +use tidy::features::{collect_lang_features, collect_lib_features, Feature}; + +#[derive(serde::Serialize)] +struct FeaturesStatus { + lang_features_status: HashMap, + lib_features_status: HashMap, +} + +fn main() { + let library_path_str = env::args_os().nth(1).expect("library/ path required"); + let compiler_path_str = env::args_os().nth(2).expect("compiler/ path required"); + let output_path_str = env::args_os().nth(3).expect("output path required"); + let library_path = Path::new(&library_path_str); + let compiler_path = Path::new(&compiler_path_str); + let output_path = Path::new(&output_path_str); + let lang_features_status = collect_lang_features(compiler_path, &mut false); + let lib_features_status = collect_lib_features(library_path) + .into_iter() + .filter(|&(ref name, _)| !lang_features_status.contains_key(name)) + .collect(); + let features_status = FeaturesStatus { + lang_features_status, lib_features_status + }; + let writer = File::create(output_path).expect("output path should be a valid path"); + let writer = BufWriter::new(writer); + serde_json::to_writer_pretty(writer, &features_status).unwrap(); +} diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index bc75787fb1abe..60402f829ab86 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -12,6 +12,7 @@ miropt-test-tools = { path = "../miropt-test-tools" } walkdir = "2" ignore = "0.4.18" semver = "1.0" +serde = { version = "1.0.125", features = [ "derive" ] } termcolor = "1.1.3" rustc-hash = "2.0.0" fluent-syntax = "0.11.1" diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 4f24eb2124207..6390d1eeccacd 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -27,6 +27,7 @@ const FEATURE_GROUP_START_PREFIX: &str = "// feature-group-start"; const FEATURE_GROUP_END_PREFIX: &str = "// feature-group-end"; #[derive(Debug, PartialEq, Clone)] +#[derive(serde::Serialize)] pub enum Status { Accepted, Removed, @@ -45,6 +46,7 @@ impl fmt::Display for Status { } #[derive(Debug, Clone)] +#[derive(serde::Serialize)] pub struct Feature { pub level: Status, pub since: Option, diff --git a/src/tools/tidy/src/features/version.rs b/src/tools/tidy/src/features/version.rs index 0830c226caf41..13d55b4845851 100644 --- a/src/tools/tidy/src/features/version.rs +++ b/src/tools/tidy/src/features/version.rs @@ -8,6 +8,7 @@ mod tests; pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION"; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(serde::Serialize)] pub enum Version { Explicit { parts: [u32; 3] }, CurrentPlaceholder, From fbf9653328d77054b5c5a90386f8f5d750362d20 Mon Sep 17 00:00:00 2001 From: Jane Losare-Lusby Date: Tue, 26 Nov 2024 14:33:30 -0800 Subject: [PATCH 2/2] format files --- src/tools/features-status-dump/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tools/features-status-dump/src/main.rs b/src/tools/features-status-dump/src/main.rs index 24ea4f758b433..9738310f0717c 100644 --- a/src/tools/features-status-dump/src/main.rs +++ b/src/tools/features-status-dump/src/main.rs @@ -1,8 +1,10 @@ use std::collections::HashMap; +use std::env; +use std::fs::File; use std::io::BufWriter; -use std::{env, fs::File}; use std::path::Path; -use tidy::features::{collect_lang_features, collect_lib_features, Feature}; + +use tidy::features::{Feature, collect_lang_features, collect_lib_features}; #[derive(serde::Serialize)] struct FeaturesStatus { @@ -22,9 +24,7 @@ fn main() { .into_iter() .filter(|&(ref name, _)| !lang_features_status.contains_key(name)) .collect(); - let features_status = FeaturesStatus { - lang_features_status, lib_features_status - }; + let features_status = FeaturesStatus { lang_features_status, lib_features_status }; let writer = File::create(output_path).expect("output path should be a valid path"); let writer = BufWriter::new(writer); serde_json::to_writer_pretty(writer, &features_status).unwrap();