Skip to content

Commit a14aeae

Browse files
committed
Add new tool for dumping feature status based on tidy
1 parent 7db7489 commit a14aeae

File tree

7 files changed

+56
-0
lines changed

7 files changed

+56
-0
lines changed

Cargo.lock

+10
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,15 @@ version = "2.1.1"
11871187
source = "registry+https://github.com/rust-lang/crates.io-index"
11881188
checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
11891189

1190+
[[package]]
1191+
name = "features-status-dump"
1192+
version = "0.1.0"
1193+
dependencies = [
1194+
"serde",
1195+
"serde_json",
1196+
"tidy",
1197+
]
1198+
11901199
[[package]]
11911200
name = "field-offset"
11921201
version = "0.3.6"
@@ -5249,6 +5258,7 @@ dependencies = [
52495258
"regex",
52505259
"rustc-hash 2.0.0",
52515260
"semver",
5261+
"serde",
52525262
"similar",
52535263
"termcolor",
52545264
"walkdir",

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ members = [
4747
"src/tools/coverage-dump",
4848
"src/tools/rustc-perf-wrapper",
4949
"src/tools/wasm-component-ld",
50+
"src/tools/features-status-dump",
5051
]
5152

5253
exclude = [
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "features-status-dump"
3+
version = "0.1.0"
4+
license = "MIT OR Apache-2.0"
5+
edition = "2021"
6+
7+
[dependencies]
8+
serde = { version = "1.0.125", features = [ "derive" ] }
9+
serde_json = "1.0.59"
10+
tidy = { path = "../tidy" }
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::collections::HashMap;
2+
use std::io::BufWriter;
3+
use std::{env, fs::File};
4+
use std::path::Path;
5+
use tidy::features::{collect_lang_features, collect_lib_features, Feature};
6+
7+
#[derive(serde::Serialize)]
8+
struct FeaturesStatus {
9+
lang_features_status: HashMap<String, Feature>,
10+
lib_features_status: HashMap<String, Feature>,
11+
}
12+
13+
fn main() {
14+
let library_path_str = env::args_os().nth(1).expect("library/ path required");
15+
let compiler_path_str = env::args_os().nth(2).expect("compiler/ path required");
16+
let output_path_str = env::args_os().nth(3).expect("output path required");
17+
let library_path = Path::new(&library_path_str);
18+
let compiler_path = Path::new(&compiler_path_str);
19+
let output_path = Path::new(&output_path_str);
20+
let lang_features_status = collect_lang_features(compiler_path, &mut false);
21+
let lib_features_status = collect_lib_features(library_path)
22+
.into_iter()
23+
.filter(|&(ref name, _)| !lang_features_status.contains_key(name))
24+
.collect();
25+
let features_status = FeaturesStatus {
26+
lang_features_status, lib_features_status
27+
};
28+
let writer = File::create(output_path).expect("output path should be a valid path");
29+
let writer = BufWriter::new(writer);
30+
serde_json::to_writer_pretty(writer, &features_status).unwrap();
31+
}

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
1212
walkdir = "2"
1313
ignore = "0.4.18"
1414
semver = "1.0"
15+
serde = { version = "1.0.125", features = [ "derive" ] }
1516
termcolor = "1.1.3"
1617
rustc-hash = "2.0.0"
1718
fluent-syntax = "0.11.1"

src/tools/tidy/src/features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const FEATURE_GROUP_START_PREFIX: &str = "// feature-group-start";
2727
const FEATURE_GROUP_END_PREFIX: &str = "// feature-group-end";
2828

2929
#[derive(Debug, PartialEq, Clone)]
30+
#[derive(serde::Serialize)]
3031
pub enum Status {
3132
Accepted,
3233
Removed,
@@ -45,6 +46,7 @@ impl fmt::Display for Status {
4546
}
4647

4748
#[derive(Debug, Clone)]
49+
#[derive(serde::Serialize)]
4850
pub struct Feature {
4951
pub level: Status,
5052
pub since: Option<Version>,

src/tools/tidy/src/features/version.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod tests;
88
pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
99

1010
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
11+
#[derive(serde::Serialize)]
1112
pub enum Version {
1213
Explicit { parts: [u32; 3] },
1314
CurrentPlaceholder,

0 commit comments

Comments
 (0)