From cfab36cb1d2803cc6cefce066598360f4defcd7a Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Sun, 10 Nov 2019 22:39:13 -0700 Subject: [PATCH] Include channel and commit info in the version of pre-release builds (#6819) --- core/src/lib.rs | 19 ++++++++++++++++++- core/src/rpc.rs | 5 ++--- core/src/version.rs | 1 - core/tests/client.rs | 2 +- validator/src/main.rs | 10 ++++------ 5 files changed, 25 insertions(+), 12 deletions(-) delete mode 100644 core/src/version.rs diff --git a/core/src/lib.rs b/core/src/lib.rs index 7b499c7b5..4b5d70494 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 blob; pub mod broadcast_stage; @@ -57,7 +75,6 @@ pub mod streamer; 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 9696bca0c..0177c35ec 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::serialize; use jsonrpc_core::{Error, Metadata, Result}; @@ -922,7 +921,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(), }) } @@ -1591,7 +1590,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 fb62f308e..000000000 --- a/core/src/version.rs +++ /dev/null @@ -1 +0,0 @@ -pub(crate) const VERSION: &str = env!("CARGO_PKG_VERSION"); diff --git a/core/tests/client.rs b/core/tests/client.rs index e548faa74..a3f81f36d 100644 --- a/core/tests/client.rs +++ b/core/tests/client.rs @@ -18,7 +18,7 @@ fn test_rpc_client() { assert_eq!( client.get_version().unwrap(), - format!("{{\"solana-core\":\"{}\"}}", env!("CARGO_PKG_VERSION")) + format!("{{\"solana-core\":\"{}\"}}", solana_core::version!()) ); assert_eq!(client.get_balance(&bob_pubkey).unwrap(), 0); diff --git a/validator/src/main.rs b/validator/src/main.rs index 9c9cec2c3..6e76b1d66 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::*; @@ -242,7 +242,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") @@ -532,11 +532,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 = {