Skip to content

Commit a5e5453

Browse files
committed
features-status-dump: pass key paths via cli flags + misc changes
1 parent b7d2d1f commit a5e5453

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,8 @@ checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
11911191
name = "features-status-dump"
11921192
version = "0.1.0"
11931193
dependencies = [
1194+
"anyhow",
1195+
"clap",
11941196
"serde",
11951197
"serde_json",
11961198
"tidy",

src/tools/features-status-dump/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ license = "MIT OR Apache-2.0"
55
edition = "2021"
66

77
[dependencies]
8+
anyhow = { version = "1", features = ["backtrace"] }
9+
clap = { version = "4", features = ["derive"] }
810
serde = { version = "1.0.125", features = [ "derive" ] }
911
serde_json = "1.0.59"
1012
tidy = { path = "../tidy" }
Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
11
use std::collections::HashMap;
2-
use std::env;
32
use std::fs::File;
43
use std::io::BufWriter;
5-
use std::path::Path;
4+
use std::path::PathBuf;
65

6+
use anyhow::{Context, Result};
7+
use clap::Parser;
78
use tidy::features::{Feature, collect_lang_features, collect_lib_features};
89

9-
#[derive(serde::Serialize)]
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)]
1024
struct FeaturesStatus {
1125
lang_features_status: HashMap<String, Feature>,
1226
lib_features_status: HashMap<String, Feature>,
1327
}
1428

15-
fn main() {
16-
let library_path_str = env::args_os().nth(1).expect("library/ path required");
17-
let compiler_path_str = env::args_os().nth(2).expect("compiler/ path required");
18-
let output_path_str = env::args_os().nth(3).expect("output path required");
19-
let library_path = Path::new(&library_path_str);
20-
let compiler_path = Path::new(&compiler_path_str);
21-
let output_path = Path::new(&output_path_str);
22-
let lang_features_status = collect_lang_features(compiler_path, &mut false);
23-
let lib_features_status = collect_lib_features(library_path)
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)
2434
.into_iter()
2535
.filter(|&(ref name, _)| !lang_features_status.contains_key(name))
2636
.collect();
2737
let features_status = FeaturesStatus { lang_features_status, lib_features_status };
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();
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(())
3153
}

0 commit comments

Comments
 (0)