Skip to content

Commit

Permalink
Move version! from core:: to clap_utils:: (solana-labs#6944)
Browse files Browse the repository at this point in the history
* Move version! from core to clap-utils

* Completely move version! from core:: to clap_utils::

* rustfmt

* Do remaining transition after rebase
  • Loading branch information
ryoqun authored Nov 14, 2019
1 parent cc96848 commit 4fc767b
Show file tree
Hide file tree
Showing 36 changed files with 146 additions and 126 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions archiver/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{crate_description, crate_name, crate_version, App, Arg};
use clap::{crate_description, crate_name, App, Arg};
use console::style;
use solana_clap_utils::input_validators::is_keypair;
use solana_core::{
Expand All @@ -17,7 +17,7 @@ fn main() {

let matches = App::new(crate_name!())
.about(crate_description!())
.version(crate_version!())
.version(solana_clap_utils::version!())
.arg(
Arg::with_name("identity")
.short("i")
Expand Down Expand Up @@ -97,7 +97,7 @@ fn main() {
println!(
"{} version {} (branch={}, commit={})",
style(crate_name!()).bold(),
crate_version!(),
solana_clap_utils::version!(),
option_env!("CI_BRANCH").unwrap_or("unknown"),
option_env!("CI_COMMIT").unwrap_or("unknown")
);
Expand Down
1 change: 1 addition & 0 deletions bench-exchange/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde_derive = "1.0.102"
serde_json = "1.0.41"
serde_yaml = "0.8.11"
# solana-runtime = { path = "../solana/runtime"}
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-genesis = { path = "../genesis", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
Expand Down
6 changes: 3 additions & 3 deletions bench-exchange/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{crate_description, crate_name, crate_version, value_t, App, Arg, ArgMatches};
use clap::{crate_description, crate_name, value_t, App, Arg, ArgMatches};
use solana_core::gen_keys::GenKeys;
use solana_drone::drone::DRONE_PORT;
use solana_sdk::signature::{read_keypair_file, Keypair, KeypairUtil};
Expand Down Expand Up @@ -44,10 +44,10 @@ impl Default for Config {
}
}

pub fn build_args<'a, 'b>() -> App<'a, 'b> {
pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
App::new(crate_name!())
.about(crate_description!())
.version(crate_version!())
.version(version)
.arg(
Arg::with_name("entrypoint")
.short("n")
Expand Down
2 changes: 1 addition & 1 deletion bench-exchange/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
solana_logger::setup();
solana_metrics::set_panic_hook("bench-exchange");

let matches = cli::build_args().get_matches();
let matches = cli::build_args(solana_clap_utils::version!()).get_matches();
let cli_config = cli::extract_args(&matches);

let cli::Config {
Expand Down
1 change: 1 addition & 0 deletions bench-streamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ homepage = "https://solana.com/"

[dependencies]
clap = "2.33.0"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-logger = { path = "../logger", version = "0.21.0" }
solana-net-utils = { path = "../net-utils", version = "0.21.0" }
4 changes: 2 additions & 2 deletions bench-streamer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{crate_description, crate_name, crate_version, App, Arg};
use clap::{crate_description, crate_name, App, Arg};
use solana_core::blob::BLOB_SIZE;
use solana_core::packet::{Packet, Packets, PacketsRecycler, PACKET_DATA_SIZE};
use solana_core::result::Result;
Expand Down Expand Up @@ -54,7 +54,7 @@ fn main() -> Result<()> {

let matches = App::new(crate_name!())
.about(crate_description!())
.version(crate_version!())
.version(solana_clap_utils::version!())
.arg(
Arg::with_name("num-recv-sockets")
.long("num-recv-sockets")
Expand Down
1 change: 1 addition & 0 deletions bench-tps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde = "1.0.102"
serde_derive = "1.0.102"
serde_json = "1.0.41"
serde_yaml = "0.8.11"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-core = { path = "../core", version = "0.21.0" }
solana-genesis = { path = "../genesis", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
Expand Down
6 changes: 3 additions & 3 deletions bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{crate_description, crate_name, crate_version, App, Arg, ArgMatches};
use clap::{crate_description, crate_name, App, Arg, ArgMatches};
use solana_drone::drone::DRONE_PORT;
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::signature::{read_keypair_file, Keypair, KeypairUtil};
Expand Down Expand Up @@ -50,9 +50,9 @@ impl Default for Config {
}

/// Defines and builds the CLI args for a run of the benchmark
pub fn build_args<'a, 'b>() -> App<'a, 'b> {
pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
App::new(crate_name!()).about(crate_description!())
.version(crate_version!())
.version(version)
.arg(
Arg::with_name("entrypoint")
.short("n")
Expand Down
2 changes: 1 addition & 1 deletion bench-tps/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
solana_logger::setup_with_filter("solana=info");
solana_metrics::set_panic_hook("bench-tps");

let matches = cli::build_args().get_matches();
let matches = cli::build_args(solana_clap_utils::version!()).get_matches();
let cli_config = cli::extract_args(&matches);

let cli::Config {
Expand Down
19 changes: 19 additions & 0 deletions clap-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
#[macro_export]
macro_rules! version {
() => {
&*format!(
"{}{}",
env!("CARGO_PKG_VERSION"),
if option_env!("CI_TAG").is_none() {
format!(
" [channel={} commit={}]",
option_env!("CHANNEL").unwrap_or("unknown"),
option_env!("CI_COMMIT").unwrap_or("unknown"),
)
} else {
"".to_string()
},
)
};
}

pub mod input_parsers;
pub mod input_validators;
120 changes: 62 additions & 58 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{crate_description, crate_name, crate_version, Arg, ArgGroup, ArgMatches, SubCommand};
use clap::{crate_description, crate_name, Arg, ArgGroup, ArgMatches, SubCommand};
use console::style;

use solana_clap_utils::input_validators::is_url;
Expand Down Expand Up @@ -126,63 +126,67 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<CliConfig, Box<dyn error::

fn main() -> Result<(), Box<dyn error::Error>> {
solana_logger::setup();
let matches = app(crate_name!(), crate_description!(), crate_version!())
.arg({
let arg = Arg::with_name("config_file")
.short("C")
.long("config")
.value_name("PATH")
.takes_value(true)
.global(true)
.help("Configuration file to use");
if let Some(ref config_file) = *config::CONFIG_FILE {
arg.default_value(&config_file)
} else {
arg
}
})
.arg(
Arg::with_name("json_rpc_url")
.short("u")
.long("url")
.value_name("URL")
.takes_value(true)
.global(true)
.validator(is_url)
.help("JSON RPC URL for the solana cluster"),
)
.arg(
Arg::with_name("keypair")
.short("k")
.long("keypair")
.value_name("PATH")
.global(true)
.takes_value(true)
.help("/path/to/id.json"),
)
.subcommand(
SubCommand::with_name("get")
.about("Get cli config settings")
.arg(
Arg::with_name("specific_setting")
.index(1)
.value_name("CONFIG_FIELD")
.takes_value(true)
.possible_values(&["url", "keypair"])
.help("Return a specific config setting"),
),
)
.subcommand(
SubCommand::with_name("set")
.about("Set a cli config setting")
.group(
ArgGroup::with_name("config_settings")
.args(&["json_rpc_url", "keypair"])
.multiple(true)
.required(true),
),
)
.get_matches();
let matches = app(
crate_name!(),
crate_description!(),
solana_clap_utils::version!(),
)
.arg({
let arg = Arg::with_name("config_file")
.short("C")
.long("config")
.value_name("PATH")
.takes_value(true)
.global(true)
.help("Configuration file to use");
if let Some(ref config_file) = *config::CONFIG_FILE {
arg.default_value(&config_file)
} else {
arg
}
})
.arg(
Arg::with_name("json_rpc_url")
.short("u")
.long("url")
.value_name("URL")
.takes_value(true)
.global(true)
.validator(is_url)
.help("JSON RPC URL for the solana cluster"),
)
.arg(
Arg::with_name("keypair")
.short("k")
.long("keypair")
.value_name("PATH")
.global(true)
.takes_value(true)
.help("/path/to/id.json"),
)
.subcommand(
SubCommand::with_name("get")
.about("Get cli config settings")
.arg(
Arg::with_name("specific_setting")
.index(1)
.value_name("CONFIG_FIELD")
.takes_value(true)
.possible_values(&["url", "keypair"])
.help("Return a specific config setting"),
),
)
.subcommand(
SubCommand::with_name("set")
.about("Set a cli config setting")
.group(
ArgGroup::with_name("config_settings")
.args(&["json_rpc_url", "keypair"])
.multiple(true)
.required(true),
),
)
.get_matches();

if parse_settings(&matches)? {
let config = parse_args(&matches)?;
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ serde_json = "1.0.41"
sha2 = "0.8.0"
solana-budget-api = { path = "../programs/budget_api", version = "0.21.0" }
solana-budget-program = { path = "../programs/budget_program", version = "0.21.0" }
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-chacha-sys = { path = "../chacha-sys", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-drone = { path = "../drone", version = "0.21.0" }
Expand Down
18 changes: 0 additions & 18 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@
//! command-line tools to spin up validators and a Rust library
//!
#[macro_export]
macro_rules! version {
() => {
&*format!(
"{}{}",
env!("CARGO_PKG_VERSION"),
if option_env!("CI_TAG").is_none() {
format!(
" [channel={} commit={}]",
option_env!("CHANNEL").unwrap_or("unknown"),
option_env!("CI_COMMIT").unwrap_or("unknown"),
)
} else {
"".to_string()
},
)
};
}
pub mod banking_stage;
pub mod blob;
pub mod broadcast_stage;
Expand Down
Loading

0 comments on commit 4fc767b

Please sign in to comment.