Skip to content

Commit

Permalink
Move all clap users to 4.0 with derive (#3153)
Browse files Browse the repository at this point in the history
* Move all clap users to 4.0 with derive
  • Loading branch information
Manishearth authored Mar 28, 2023
1 parent 01fb648 commit ca28250
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 265 deletions.
195 changes: 29 additions & 166 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components/calendar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ databake = { version = "0.1.3", path = "../../utils/databake", features = ["deri
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }

[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
icu = { path = "../icu", default-features = false }
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
icu_testdata = { path = "../../provider/testdata", default-features = false, features = ["buffer", "icu_calendar"] }
Expand Down
2 changes: 1 addition & 1 deletion components/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ arraystring = "0.3.0"
atoi = "1.0.0"
icu = { path = "../icu" }
icu_testdata = { path = "../../provider/testdata", default-features = false, features = ["icu_collator", "icu_normalizer"] }
criterion = "0.4.0"
criterion = "0.4"

[features]
std = ["icu_collections/std", "icu_locid/std", "icu_normalizer/std", "icu_properties/std", "icu_provider/std"]
Expand Down
2 changes: 1 addition & 1 deletion components/collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ postcard = { version = "1.0.0", features = ["alloc"], default-features = false }
toml = "0.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
criterion = "0.3.4"
criterion = "0.4"
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
iai = "0.1.1"
icu = { path = "../icu", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion components/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ databake = { version = "0.1.3", path = "../../utils/databake", features = ["deri
litemap = { version = "0.6.1", path = "../../utils/litemap", optional = true }

[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
icu = { path = "../icu", default-features = false }
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
icu_provider = { path = "../../provider/core" }
Expand Down
2 changes: 1 addition & 1 deletion components/decimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ databake = { version = "0.1.3", path = "../../utils/databake", features = ["deri
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }

[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
icu = { path = "../icu", default-features = false }
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
icu_testdata = { path = "../../provider/testdata", default-features = false, features = ["icu_decimal"] }
Expand Down
2 changes: 1 addition & 1 deletion components/locid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ serde = { version = "1.0", default-features = false, features = ["alloc", "deriv
zerovec = { version = "0.9.2", path = "../../utils/zerovec", optional = true }

[dev-dependencies]
criterion = "0.3.3"
criterion = "0.4"
iai = "0.1.1"
icu = { path = "../icu", default-features = false }
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
Expand Down
2 changes: 1 addition & 1 deletion components/locid_transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ databake = { version = "0.1.3", path = "../../utils/databake", optional = true,
displaydoc = { version = "0.2.3", default-features = false }

[dev-dependencies]
criterion = "0.3.3"
criterion = "0.4"
icu_testdata = { path = "../../provider/testdata", default-features = false, features = ["icu_locid_transform"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion components/plurals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ databake = { version = "0.1.3", path = "../../utils/databake", features = ["deri
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }

[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
icu = { path = "../icu" }
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
icu_provider = { path = "../../provider/core" }
Expand Down
2 changes: 1 addition & 1 deletion experimental/bies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ strum = { version = "0.20", features = ["derive"] }
writeable = { version = "0.5.1", path = "../../utils/writeable" }

[dev-dependencies]
criterion = "0.3.3"
criterion = "0.4"
rand = "0.8"
rand_distr = "0.4"
rand_pcg = "0.3"
2 changes: 1 addition & 1 deletion experimental/ixdtf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ all-features = true
[dependencies]

[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
icu_testdata = { path = "../../provider/testdata" }
serde-json-core = { version = "0.4", features = ["std"] }
2 changes: 1 addition & 1 deletion experimental/segmenter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo
num-traits = { version = "0.2", default-features = false, features = ["libm"], optional = true }

[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
icu_testdata = { path = "../../provider/testdata", default-features = false, features = ["buffer", "icu_segmenter"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion provider/fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ postcard = { version = "1.0.0", features = ["use-std"], default-features = false
serde_json = { version = "1.0", optional = true }

[dev-dependencies]
criterion = "0.3.3"
criterion = "0.4"
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
icu_locid = { path = "../../components/locid", features = ["serde"] }
icu_provider = { path = "../core", features = ["deserialize_json", "deserialize_bincode_1", "deserialize_postcard_1", "datagen"] }
Expand Down
2 changes: 1 addition & 1 deletion provider/testdata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ icu_timezone = { version = "1.1.0", path = "../../components/timezone", default-
[dev-dependencies]
icu = { path = "../../components/icu" }
icu_provider = { path = "../../provider/core", features = ["deserialize_json"] }
criterion = "0.3"
criterion = "0.4"

[features]
default = [
Expand Down
2 changes: 1 addition & 1 deletion tools/benchmark/memory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ edition = "2021"

[dependencies]
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
clap = "2.33"
clap = {version = "4", features = ["derive"] }
cargo_metadata = "0.13"
libc = "0.2"
87 changes: 33 additions & 54 deletions tools/benchmark/memory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use cargo_metadata::Metadata;
use clap::{App, Arg};
use clap::Parser;
use serde_json::json;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
Expand All @@ -12,68 +12,47 @@ use std::process::Command;
use std::{env, process::Stdio};
use std::{fs, io::BufReader};

#[derive(Parser)]
#[command(about = "Collect a memory report for examples using dhat-rs.")]
struct ProcessedArgs {
#[arg(
long,
value_name = "OS",
help = "Nests the results of the benchmark in a folder per-OS, primarily needed by CI."
)]
os: Option<String>,
#[arg(value_name = "EXAMPLES", num_args = 1.., index=1)]
#[arg(help = "The space separated list of examples to run, with the form <PACKAGE>/<EXAMPLE>")]
examples: Vec<String>,
#[arg(
long,
value_name = "TOOLCHAIN",
default_value = "stable",
help = "The toolchain for cargo to use.."
)]
toolchain: String,
}

fn process_cli_args() -> ProcessedArgs {
let matches = App::new("ICU4X Memory Benchmarks")
.about("Collect a memory report for examples using dhat-rs.")
.arg(
Arg::with_name("EXAMPLES")
.index(1)
.multiple(true)
.required(true)
.help("The space separated list of examples to run, with the form <PACKAGE>/<EXAMPLE>")
)
.arg(
Arg::with_name("OS")
.long("os")
.takes_value(true)
.value_name("OS")
.required(false)
.help("Nests the results of the benchmark in a folder per-OS, primarily needed by CI.")
)
.arg(
Arg::with_name("TOOLCHAIN")
.long("toolchain")
.takes_value(true)
.value_name("TOOLCHAIN")
.default_value("stable")
.help("The toolchain for cargo to use..")
).get_matches();

ProcessedArgs {
// Validate the OS, and copy into an owned String.
os: matches.value_of("OS").map(|os| {
if !os
.chars()
.all(|c| c.is_alphanumeric() || c == '_' || c == '-')
{
panic!("The OS had an unexpected character");
}
os.to_string()
}),

// Validate the examples, and map them into owned Strings.
examples: matches
.values_of("EXAMPLES")
.expect("At least one example must be provided.")
.map(|example| {
if !example
.chars()
.all(|c| c.is_alphanumeric() || c == '_' || c == '/')
{
panic!("An example had an unexpected character \"{example:?}\"");
}
example.to_string()
})
.collect(),
let processed = ProcessedArgs::parse();

toolchain: matches.value_of("TOOLCHAIN").unwrap().to_string(),
if let Some(ref os) = processed.os {
if !os
.chars()
.all(|c| c.is_alphanumeric() || c == '_' || c == '-')
{
panic!("The OS had an unexpected character");
}
}
for example in &processed.examples {
if !example
.chars()
.all(|c| c.is_alphanumeric() || c == '_' || c == '/')
{
panic!("An example had an unexpected character \"{example:?}\"");
}
}
processed
}

fn parse_dhat_log(dhat_log: &[String]) -> (u64, u64, u64) {
Expand Down
2 changes: 1 addition & 1 deletion tools/testdata-scripts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ icu_provider = { path = "../../provider/core" }
repodata = { path = "../../provider/repodata" }

cached-path = ">=0.5, <0.7"
clap = "2.33"
clap = {version = "4", features = ["derive"] }
eyre = "0.6"
log = "0.4"
quote = "1"
Expand Down
45 changes: 20 additions & 25 deletions tools/testdata-scripts/src/bin/download-repo-sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use clap::{App, Arg};
use clap::{ArgAction, Parser};
use eyre::WrapErr;
use icu_datagen::SourceData;
use icu_locid::*;
Expand All @@ -15,31 +15,26 @@ use zip::ZipArchive;
include!("../../globs.rs.data");
include!("../../locales.rs.data");

#[derive(Parser)]
#[command(
author = "The ICU4X Project Developers",
about = "Download data from CLDR and ICU for ICU4X testing"
)]
struct Args {
#[arg(short, long, help = "Sets the level of verbosity (-v, -vv, or -vvv)", action = ArgAction::Count)]
verbose: u8,
#[arg(
short,
long,
help = "Path to output data directory. The subdirectories 'cldr' and 'icuexport' will be overwritten. Omit this option to write data into the package tree"
)]
out: PathBuf,
}

fn main() -> eyre::Result<()> {
let args = App::new("ICU4X Test Data Downloader")
.version("0.0.1")
.author("The ICU4X Project Developers")
.about("Download data from CLDR and ICU for ICU4X testing")
.arg(
Arg::with_name("VERBOSE")
.short("v")
.long("verbose")
.multiple(true)
.help("Sets the level of verbosity (-v, -vv, or -vvv)"),
)
.arg(
Arg::with_name("OUTPUT")
.short("o")
.long("out")
.help(
"Path to output data directory. The subdirectories 'cldr' and 'icuexport' will be overwritten. Omit this option to write data into the package tree.",
)
.takes_value(true)
.required(true),
)
.get_matches();
let args = Args::parse();

match args.occurrences_of("VERBOSE") {
match args.verbose {
0 => SimpleLogger::new()
.env()
.with_level(log::LevelFilter::Info)
Expand All @@ -60,7 +55,7 @@ fn main() -> eyre::Result<()> {
_ => eyre::bail!("Only -v, -vv, and -vvv are supported"),
}

let output_path = PathBuf::from(args.value_of_os("OUTPUT").expect("arg is required"));
let output_path = &args.out;

let cached = cached_path::CacheBuilder::new()
.freshness_lifetime(u64::MAX)
Expand Down
2 changes: 1 addition & 1 deletion utils/fixed_decimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ writeable = { version = "0.5.1", path = "../../utils/writeable" }
ryu = { version = "1.0.5", features = ["small"], optional = true }

[dev-dependencies]
criterion = "0.3.4"
criterion = "0.4"
getrandom = { version = "0.2", features = ["js"] }
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion utils/litemap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ yoke = { version = "0.7.0", path = "../yoke", features = ["derive"], optional =
[dev-dependencies]
bincode = "1"
bytecheck = "0.6"
criterion = "0.3.4"
criterion = "0.4"
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
icu_locid = { path = "../../components/locid" }
postcard = { version = "1.0.0", features = ["use-std"], default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion utils/tinystr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ databake = { version = "0.1.3", path = "../../utils/databake", optional = true }

[dev-dependencies]
bincode = "1.3"
criterion = "0.3"
criterion = "0.4"
postcard = { version = "1.0.0", features = ["use-std"], default-features = false }
rand = { version = "0.8.5", features = ["small_rng"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion utils/writeable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ independent = true
all-features = true

[dev-dependencies]
criterion = "0.3"
criterion = "0.4"
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
rand = { version = "0.8", features = ["small_rng"] }

Expand Down
2 changes: 1 addition & 1 deletion utils/zerovec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ t1ha = { version = "0.1", optional = true }

[dev-dependencies]
bincode = "1.3"
criterion = "0.3.4"
criterion = "0.4"
getrandom = { version = "0.2", features = ["js"] }
iai = "0.1"
icu_benchmark_macros = { path = "../../tools/benchmark/macros" }
Expand Down

0 comments on commit ca28250

Please sign in to comment.