features-status-dump: add new build-metrics tool
Co-authored-by: Jane Losare-Lusby <jlusby42@gmail.com>
This commit is contained in:
parent
2f0ad2a71e
commit
57e8575760
4 changed files with 81 additions and 0 deletions
15
Cargo.lock
15
Cargo.lock
|
@ -186,6 +186,9 @@ name = "anyhow"
|
|||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ar_archive_writer"
|
||||
|
@ -1195,6 +1198,17 @@ version = "2.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "features-status-dump"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tidy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "field-offset"
|
||||
version = "0.3.6"
|
||||
|
@ -5373,6 +5387,7 @@ dependencies = [
|
|||
"regex",
|
||||
"rustc-hash 2.1.0",
|
||||
"semver",
|
||||
"serde",
|
||||
"similar",
|
||||
"termcolor",
|
||||
"walkdir",
|
||||
|
|
|
@ -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 = [
|
||||
|
|
12
src/tools/features-status-dump/Cargo.toml
Normal file
12
src/tools/features-status-dump/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "features-status-dump"
|
||||
version = "0.1.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = { version = "1", features = ["backtrace"] }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
serde = { version = "1.0.125", features = [ "derive" ] }
|
||||
serde_json = "1.0.59"
|
||||
tidy = { path = "../tidy", features = ["build-metrics"] }
|
53
src/tools/features-status-dump/src/main.rs
Normal file
53
src/tools/features-status-dump/src/main.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Parser;
|
||||
use tidy::features::{Feature, collect_lang_features, collect_lib_features};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct Cli {
|
||||
/// Path to `library/` directory.
|
||||
#[arg(long)]
|
||||
library_path: PathBuf,
|
||||
/// Path to `compiler/` directory.
|
||||
#[arg(long)]
|
||||
compiler_path: PathBuf,
|
||||
/// Path to `output/` directory.
|
||||
#[arg(long)]
|
||||
output_path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
struct FeaturesStatus {
|
||||
lang_features_status: HashMap<String, Feature>,
|
||||
lib_features_status: HashMap<String, Feature>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let Cli { compiler_path, library_path, output_path } = Cli::parse();
|
||||
|
||||
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 output_dir = output_path.parent().with_context(|| {
|
||||
format!("failed to get parent dir of output path `{}`", output_path.display())
|
||||
})?;
|
||||
std::fs::create_dir_all(output_dir).with_context(|| {
|
||||
format!("failed to create output directory at `{}`", output_dir.display())
|
||||
})?;
|
||||
|
||||
let output_file = File::create(&output_path).with_context(|| {
|
||||
format!("failed to create file at given output path `{}`", output_path.display())
|
||||
})?;
|
||||
let writer = BufWriter::new(output_file);
|
||||
serde_json::to_writer_pretty(writer, &features_status)
|
||||
.context("failed to write json output")?;
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue