Skip to content

Commit

Permalink
Merge pull request #19 from Fraser999/vergen
Browse files Browse the repository at this point in the history
Add git short hash to version string when available
  • Loading branch information
Fraser999 authored Apr 6, 2022
2 parents 1aca584 + 7e45bdc commit 2ae11f4
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ tokio = { version = "1.14", features = ["macros", "net", "rt-multi-thread", "syn

[build-dependencies]
cbindgen = { version = "0.20", optional = true }
vergen = { version = "7", default-features = false, features = ["git"] }

[dev-dependencies]
anyhow = "1"
6 changes: 6 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use vergen::{Config, ShaKind};

fn main() {
#[cfg(feature = "ffi")]
{
@@ -30,4 +32,8 @@ fn main() {
.expect("Unable to generate bindings")
.write_to_file(&output_file);
}

let mut config = Config::default();
*config.git_mut().sha_kind_mut() = ShaKind::Short;
let _ = vergen::vergen(config);
}
17 changes: 16 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ mod query_global_state;
use std::process;

use clap::{crate_version, App};
use once_cell::sync::Lazy;

use casper_client::Error;
use casper_node::rpcs::{
@@ -36,6 +37,20 @@ use keygen::Keygen;

const APP_NAME: &str = "Casper client";

static VERSION: Lazy<String> =
Lazy::new(
|| match option_env!("VERGEN_GIT_SHA_SHORT").map(|sha| sha.to_lowercase()) {
None => crate_version!().to_string(),
Some(git_sha_short) => {
if git_sha_short.to_lowercase() == "unknown" {
crate_version!().to_string()
} else {
format!("{}-{}", crate_version!(), git_sha_short)
}
}
},
);

/// This struct defines the order in which the subcommands are shown in the app's help message.
enum DisplayOrder {
PutDeploy,
@@ -64,7 +79,7 @@ enum DisplayOrder {

fn cli<'a, 'b>() -> App<'a, 'b> {
App::new(APP_NAME)
.version(crate_version!())
.version(VERSION.as_str())
.about("A client for interacting with the Casper network")
.subcommand(PutDeploy::build(DisplayOrder::PutDeploy as usize))
.subcommand(MakeDeploy::build(DisplayOrder::MakeDeploy as usize))

0 comments on commit 2ae11f4

Please sign in to comment.