update clap to v3: bpf-tools

This commit is contained in:
klykov 2022-03-07 16:25:01 +01:00 committed by kirill lykov
parent 949006b5a2
commit 8abaa5d350
2 changed files with 23 additions and 25 deletions

View File

@ -11,7 +11,7 @@ publish = false
[dependencies] [dependencies]
bzip2 = "0.4.3" bzip2 = "0.4.3"
clap = "2.33.3" clap = {version = "3.1.5", features = ["cargo", "env"]}
regex = "1.5.4" regex = "1.5.4"
cargo_metadata = "0.14.2" cargo_metadata = "0.14.2"
solana-sdk = { path = "..", version = "=1.10.1" } solana-sdk = { path = "..", version = "=1.10.1" }

View File

@ -1,8 +1,6 @@
use { use {
bzip2::bufread::BzDecoder, bzip2::bufread::BzDecoder,
clap::{ clap::{crate_description, crate_name, crate_version, Arg},
crate_description, crate_name, crate_version, value_t, value_t_or_exit, values_t, App, Arg,
},
regex::Regex, regex::Regex,
solana_download_utils::download_file, solana_download_utils::download_file,
solana_sdk::signature::{write_keypair_file, Keypair}, solana_sdk::signature::{write_keypair_file, Keypair},
@ -714,11 +712,11 @@ fn main() {
// separate cargo caches according to the version of sbf-tools. // separate cargo caches according to the version of sbf-tools.
let bpf_tools_version = "v1.23"; let bpf_tools_version = "v1.23";
let version = format!("{}\nbpf-tools {}", crate_version!(), bpf_tools_version); let version = format!("{}\nbpf-tools {}", crate_version!(), bpf_tools_version);
let matches = App::new(crate_name!()) let matches = clap::Command::new(crate_name!())
.about(crate_description!()) .about(crate_description!())
.version(version.as_str()) .version(version.as_str())
.arg( .arg(
Arg::with_name("bpf_out_dir") Arg::new("bpf_out_dir")
.env("BPF_OUT_PATH") .env("BPF_OUT_PATH")
.long("bpf-out-dir") .long("bpf-out-dir")
.value_name("DIRECTORY") .value_name("DIRECTORY")
@ -726,7 +724,7 @@ fn main() {
.help("Place final BPF build artifacts in this directory"), .help("Place final BPF build artifacts in this directory"),
) )
.arg( .arg(
Arg::with_name("bpf_sdk") Arg::new("bpf_sdk")
.env("BPF_SDK_PATH") .env("BPF_SDK_PATH")
.long("bpf-sdk") .long("bpf-sdk")
.value_name("PATH") .value_name("PATH")
@ -735,59 +733,61 @@ fn main() {
.help("Path to the Solana BPF SDK"), .help("Path to the Solana BPF SDK"),
) )
.arg( .arg(
Arg::with_name("cargo_args") Arg::new("cargo_args")
.help("Arguments passed directly to `cargo build`") .help("Arguments passed directly to `cargo build`")
.multiple(true) .multiple_occurrences(true)
.multiple_values(true)
.last(true), .last(true),
) )
.arg( .arg(
Arg::with_name("dump") Arg::new("dump")
.long("dump") .long("dump")
.takes_value(false) .takes_value(false)
.help("Dump ELF information to a text file on success"), .help("Dump ELF information to a text file on success"),
) )
.arg( .arg(
Arg::with_name("features") Arg::new("features")
.long("features") .long("features")
.value_name("FEATURES") .value_name("FEATURES")
.takes_value(true) .takes_value(true)
.multiple(true) .multiple_occurrences(true)
.multiple_values(true)
.help("Space-separated list of features to activate"), .help("Space-separated list of features to activate"),
) )
.arg( .arg(
Arg::with_name("generate_child_script_on_failure") Arg::new("generate_child_script_on_failure")
.long("generate-child-script-on-failure") .long("generate-child-script-on-failure")
.takes_value(false) .takes_value(false)
.help("Generate a shell script to rerun a failed subcommand"), .help("Generate a shell script to rerun a failed subcommand"),
) )
.arg( .arg(
Arg::with_name("manifest_path") Arg::new("manifest_path")
.long("manifest-path") .long("manifest-path")
.value_name("PATH") .value_name("PATH")
.takes_value(true) .takes_value(true)
.help("Path to Cargo.toml"), .help("Path to Cargo.toml"),
) )
.arg( .arg(
Arg::with_name("no_default_features") Arg::new("no_default_features")
.long("no-default-features") .long("no-default-features")
.takes_value(false) .takes_value(false)
.help("Do not activate the `default` feature"), .help("Do not activate the `default` feature"),
) )
.arg( .arg(
Arg::with_name("offline") Arg::new("offline")
.long("offline") .long("offline")
.takes_value(false) .takes_value(false)
.help("Run without accessing the network"), .help("Run without accessing the network"),
) )
.arg( .arg(
Arg::with_name("verbose") Arg::new("verbose")
.short("v") .short('v')
.long("verbose") .long("verbose")
.takes_value(false) .takes_value(false)
.help("Use verbose output"), .help("Use verbose output"),
) )
.arg( .arg(
Arg::with_name("workspace") Arg::new("workspace")
.long("workspace") .long("workspace")
.takes_value(false) .takes_value(false)
.alias("all") .alias("all")
@ -795,8 +795,8 @@ fn main() {
) )
.get_matches_from(args); .get_matches_from(args);
let bpf_sdk = value_t_or_exit!(matches, "bpf_sdk", PathBuf); let bpf_sdk: PathBuf = matches.value_of_t_or_exit("bpf_sdk");
let bpf_out_dir = value_t!(matches, "bpf_out_dir", PathBuf).ok(); let bpf_out_dir: Option<PathBuf> = matches.value_of_t("bpf_out_dir").ok();
let config = Config { let config = Config {
cargo_args: matches cargo_args: matches
@ -821,15 +821,13 @@ fn main() {
}), }),
bpf_tools_version, bpf_tools_version,
dump: matches.is_present("dump"), dump: matches.is_present("dump"),
features: values_t!(matches, "features", String) features: matches.values_of_t("features").ok().unwrap_or_default(),
.ok()
.unwrap_or_default(),
generate_child_script_on_failure: matches.is_present("generate_child_script_on_failure"), generate_child_script_on_failure: matches.is_present("generate_child_script_on_failure"),
no_default_features: matches.is_present("no_default_features"), no_default_features: matches.is_present("no_default_features"),
offline: matches.is_present("offline"), offline: matches.is_present("offline"),
verbose: matches.is_present("verbose"), verbose: matches.is_present("verbose"),
workspace: matches.is_present("workspace"), workspace: matches.is_present("workspace"),
}; };
let manifest_path = value_t!(matches, "manifest_path", PathBuf).ok(); let manifest_path: Option<PathBuf> = matches.value_of_t("manifest_path").ok();
build_bpf(config, manifest_path); build_bpf(config, manifest_path);
} }