diff --git a/core/src/lib.rs b/core/src/lib.rs index 122823f2d2..cd19291001 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -5,6 +5,24 @@ //! 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 broadcast_stage; pub mod chacha; @@ -58,7 +76,6 @@ pub mod test_tx; pub mod tpu; pub mod tvu; pub mod validator; -pub(crate) mod version; pub mod weighted_shuffle; pub mod window_service; diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 434ccb1f46..5ccce2c371 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -7,7 +7,6 @@ use crate::{ packet::PACKET_DATA_SIZE, storage_stage::StorageState, validator::ValidatorExit, - version::VERSION, }; use bincode::{deserialize, serialize}; use jsonrpc_core::{Error, Metadata, Result}; @@ -723,7 +722,7 @@ impl RpcSol for RpcSolImpl { fn get_version(&self, _: Self::Metadata) -> Result { Ok(RpcVersionInfo { - solana_core: VERSION.to_string(), + solana_core: crate::version!().to_string(), }) } @@ -1388,7 +1387,7 @@ pub mod tests { let expected = json!({ "jsonrpc": "2.0", "result": { - "solana-core": VERSION + "solana-core": crate::version!().to_string() }, "id": 1 }); diff --git a/core/src/version.rs b/core/src/version.rs deleted file mode 100644 index fb62f308e4..0000000000 --- a/core/src/version.rs +++ /dev/null @@ -1 +0,0 @@ -pub(crate) const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/validator/src/main.rs b/validator/src/main.rs index 8d3a98669a..bedeabb234 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -1,5 +1,5 @@ use bzip2::bufread::BzDecoder; -use clap::{crate_description, crate_name, crate_version, value_t, value_t_or_exit, App, Arg}; +use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg}; use console::{style, Emoji}; use indicatif::{ProgressBar, ProgressStyle}; use log::*; @@ -236,7 +236,7 @@ pub fn main() { &format!("{}-{}", VALIDATOR_PORT_RANGE.0, VALIDATOR_PORT_RANGE.1); let matches = App::new(crate_name!()).about(crate_description!()) - .version(crate_version!()) + .version(solana_core::version!()) .arg( Arg::with_name("blockstream_unix_socket") .long("blockstream") @@ -526,11 +526,9 @@ pub fn main() { .map(|s| Hash::from_str(&s).unwrap()); println!( - "{} version {} (branch={}, commit={})", + "{} {}", style(crate_name!()).bold(), - crate_version!(), - option_env!("CI_BRANCH").unwrap_or("unknown"), - option_env!("CI_COMMIT").unwrap_or("unknown") + solana_core::version!() ); let _log_redirect = {