|
| 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