Skip to content

Commit 648fd0e

Browse files
authored
Rollup merge of rust-lang#135844 - yaahc:tidy-feature-status-dump, r=jieyouxu
Add new tool for dumping feature status based on tidy sequel to rust-lang#133514 meaning ... supercedes rust-lang#133351 part of rust-lang#129485 r? `@jieyouxu` cc `@estebank`
2 parents d2aa3de + cbcba57 commit 648fd0e

File tree

11 files changed

+123
-0
lines changed

11 files changed

+123
-0
lines changed

Diff for: Cargo.lock

+15
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ name = "anyhow"
186186
version = "1.0.95"
187187
source = "registry+https://github.com/rust-lang/crates.io-index"
188188
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
189+
dependencies = [
190+
"backtrace",
191+
]
189192

190193
[[package]]
191194
name = "ar_archive_writer"
@@ -1195,6 +1198,17 @@ version = "2.3.0"
11951198
source = "registry+https://github.com/rust-lang/crates.io-index"
11961199
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
11971200

1201+
[[package]]
1202+
name = "features-status-dump"
1203+
version = "0.1.0"
1204+
dependencies = [
1205+
"anyhow",
1206+
"clap",
1207+
"serde",
1208+
"serde_json",
1209+
"tidy",
1210+
]
1211+
11981212
[[package]]
11991213
name = "field-offset"
12001214
version = "0.3.6"
@@ -5418,6 +5432,7 @@ dependencies = [
54185432
"regex",
54195433
"rustc-hash 2.1.0",
54205434
"semver",
5435+
"serde",
54215436
"similar",
54225437
"termcolor",
54235438
"walkdir",

Diff for: 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 = [

Diff for: src/bootstrap/src/core/build_steps/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ tool_check_step!(Rls { path: "src/tools/rls" });
455455
tool_check_step!(Rustfmt { path: "src/tools/rustfmt" });
456456
tool_check_step!(MiroptTestTools { path: "src/tools/miropt-test-tools" });
457457
tool_check_step!(TestFloatParse { path: "src/etc/test-float-parse" });
458+
tool_check_step!(FeaturesStatusDump { path: "src/tools/features-status-dump" });
458459

459460
tool_check_step!(Bootstrap { path: "src/bootstrap", default: false });
460461

Diff for: src/bootstrap/src/core/build_steps/run.rs

+31
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,34 @@ impl Step for UnicodeTableGenerator {
311311
cmd.run(builder);
312312
}
313313
}
314+
315+
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
316+
pub struct FeaturesStatusDump;
317+
318+
impl Step for FeaturesStatusDump {
319+
type Output = ();
320+
const ONLY_HOSTS: bool = true;
321+
322+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
323+
run.path("src/tools/features-status-dump")
324+
}
325+
326+
fn make_run(run: RunConfig<'_>) {
327+
run.builder.ensure(FeaturesStatusDump);
328+
}
329+
330+
fn run(self, builder: &Builder<'_>) {
331+
let mut cmd = builder.tool_cmd(Tool::FeaturesStatusDump);
332+
333+
cmd.arg("--library-path");
334+
cmd.arg(builder.src.join("library"));
335+
336+
cmd.arg("--compiler-path");
337+
cmd.arg(builder.src.join("compiler"));
338+
339+
cmd.arg("--output-path");
340+
cmd.arg(builder.out.join("features-status-dump.json"));
341+
342+
cmd.run(builder);
343+
}
344+
}

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ bootstrap_tool!(
365365
RustcPerfWrapper, "src/tools/rustc-perf-wrapper", "rustc-perf-wrapper";
366366
WasmComponentLd, "src/tools/wasm-component-ld", "wasm-component-ld", is_unstable_tool = true, allow_features = "min_specialization";
367367
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
368+
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
368369
);
369370

370371
/// These are the submodules that are required for rustbook to work due to

Diff for: src/bootstrap/src/core/builder/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ impl<'a> Builder<'a> {
938938
check::Bootstrap,
939939
check::RunMakeSupport,
940940
check::Compiletest,
941+
check::FeaturesStatusDump,
941942
),
942943
Kind::Test => describe!(
943944
crate::core::build_steps::toolstate::ToolStateCheck,
@@ -1089,6 +1090,7 @@ impl<'a> Builder<'a> {
10891090
run::GenerateWindowsSys,
10901091
run::GenerateCompletions,
10911092
run::UnicodeTableGenerator,
1093+
run::FeaturesStatusDump,
10921094
),
10931095
Kind::Setup => {
10941096
describe!(setup::Profile, setup::Hook, setup::Link, setup::Editor)

Diff for: src/tools/features-status-dump/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
anyhow = { version = "1", features = ["backtrace"] }
9+
clap = { version = "4", features = ["derive"] }
10+
serde = { version = "1.0.125", features = [ "derive" ] }
11+
serde_json = "1.0.59"
12+
tidy = { path = "../tidy", features = ["build-metrics"] }

Diff for: src/tools/features-status-dump/src/main.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::collections::HashMap;
2+
use std::fs::File;
3+
use std::io::BufWriter;
4+
use std::path::PathBuf;
5+
6+
use anyhow::{Context, Result};
7+
use clap::Parser;
8+
use tidy::features::{Feature, collect_lang_features, collect_lib_features};
9+
10+
#[derive(Debug, Parser)]
11+
struct Cli {
12+
/// Path to `library/` directory.
13+
#[arg(long)]
14+
library_path: PathBuf,
15+
/// Path to `compiler/` directory.
16+
#[arg(long)]
17+
compiler_path: PathBuf,
18+
/// Path to `output/` directory.
19+
#[arg(long)]
20+
output_path: PathBuf,
21+
}
22+
23+
#[derive(Debug, serde::Serialize)]
24+
struct FeaturesStatus {
25+
lang_features_status: HashMap<String, Feature>,
26+
lib_features_status: HashMap<String, Feature>,
27+
}
28+
29+
fn main() -> Result<()> {
30+
let Cli { compiler_path, library_path, output_path } = Cli::parse();
31+
32+
let lang_features_status = collect_lang_features(&compiler_path, &mut false);
33+
let lib_features_status = collect_lib_features(&library_path)
34+
.into_iter()
35+
.filter(|&(ref name, _)| !lang_features_status.contains_key(name))
36+
.collect();
37+
let features_status = FeaturesStatus { lang_features_status, lib_features_status };
38+
39+
let output_dir = output_path.parent().with_context(|| {
40+
format!("failed to get parent dir of output path `{}`", output_path.display())
41+
})?;
42+
std::fs::create_dir_all(output_dir).with_context(|| {
43+
format!("failed to create output directory at `{}`", output_dir.display())
44+
})?;
45+
46+
let output_file = File::create(&output_path).with_context(|| {
47+
format!("failed to create file at given output path `{}`", output_path.display())
48+
})?;
49+
let writer = BufWriter::new(output_file);
50+
serde_json::to_writer_pretty(writer, &features_status)
51+
.context("failed to write json output")?;
52+
Ok(())
53+
}

Diff for: src/tools/tidy/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ 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"], optional = true }
1516
termcolor = "1.1.3"
1617
rustc-hash = "2.0.0"
1718
fluent-syntax = "0.11.1"
1819
similar = "2.5.0"
1920

21+
[features]
22+
build-metrics = ["dep:serde"]
23+
2024
[[bin]]
2125
name = "rust-tidy"
2226
path = "src/main.rs"

Diff for: 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+
#[cfg_attr(feature = "build-metrics", 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+
#[cfg_attr(feature = "build-metrics", derive(serde::Serialize))]
4850
pub struct Feature {
4951
pub level: Status,
5052
pub since: Option<Version>,

Diff for: 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+
#[cfg_attr(feature = "build-metrics", derive(serde::Serialize))]
1112
pub enum Version {
1213
Explicit { parts: [u32; 3] },
1314
CurrentPlaceholder,

0 commit comments

Comments
 (0)