Skip to content

Commit 57e8575

Browse files
jieyouxuyaahc
andcommitted
features-status-dump: add new build-metrics tool
Co-authored-by: Jane Losare-Lusby <[email protected]>
1 parent 2f0ad2a commit 57e8575

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-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"
@@ -5373,6 +5387,7 @@ dependencies = [
53735387
"regex",
53745388
"rustc-hash 2.1.0",
53755389
"semver",
5390+
"serde",
53765391
"similar",
53775392
"termcolor",
53785393
"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/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+
}

0 commit comments

Comments
 (0)