Clients: log git commit info at start time (#965)

(cherry picked from commit 53829cb6e5)
This commit is contained in:
Serge Farny 2024-05-23 15:16:55 +02:00
parent 2a5fdc89e6
commit 15f623ce9f
7 changed files with 59 additions and 2 deletions

28
Cargo.lock generated
View File

@ -315,9 +315,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.75"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "arc-swap"
@ -3491,6 +3491,7 @@ dependencies = [
"tokio-tungstenite 0.17.2",
"tracing",
"tracing-subscriber",
"vergen",
]
[[package]]
@ -4229,6 +4230,15 @@ dependencies = [
"syn 2.0.37",
]
[[package]]
name = "num_threads"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
dependencies = [
"libc",
]
[[package]]
name = "number_prefix"
version = "0.4.0"
@ -8392,6 +8402,8 @@ checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe"
dependencies = [
"deranged",
"itoa",
"libc",
"num_threads",
"serde",
"time-core",
"time-macros",
@ -9277,6 +9289,18 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "vergen"
version = "8.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525"
dependencies = [
"anyhow",
"cfg-if 1.0.0",
"rustversion",
"time 0.3.29",
]
[[package]]
name = "version_check"
version = "0.1.5"

View File

@ -89,6 +89,7 @@ enum Command {
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
mango_v4_client::tracing_subscriber_init();
mango_v4_client::print_git_version();
let args = if let Ok(cli_dotenv) = CliDotenv::try_parse() {
dotenv::from_path(cli_dotenv.dotenv)?;

View File

@ -44,6 +44,7 @@ pub fn encode_address(addr: &Pubkey) -> String {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
mango_v4_client::tracing_subscriber_init();
mango_v4_client::print_git_version();
let args: Vec<std::ffi::OsString> = if let Ok(cli_dotenv) = CliDotenv::try_parse() {
dotenv::from_path(cli_dotenv.dotenv)?;

View File

@ -80,6 +80,7 @@ pub fn encode_address(addr: &Pubkey) -> String {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
mango_v4_client::tracing_subscriber_init();
mango_v4_client::print_git_version();
let args = if let Ok(cli_dotenv) = CliDotenv::try_parse() {
dotenv::from_path(cli_dotenv.dotenv)?;

View File

@ -2,10 +2,15 @@
name = "mango-v4-client"
version = "0.3.0"
edition = "2021"
build = "build.rs"
[lib]
doctest = false
[build-dependencies]
anyhow = "1.0"
vergen = { version = "8.3.1", features = ["git", "gitcl"] }
[dependencies]
anchor-client = { workspace = true }
anchor-lang = { workspace = true }

11
lib/client/build.rs Normal file
View File

@ -0,0 +1,11 @@
use vergen::EmitBuilder;
pub fn main() -> anyhow::Result<()> {
EmitBuilder::builder()
.git_sha(true)
.git_dirty(false)
.git_commit_date()
.emit()?;
Ok(())
}

View File

@ -3,6 +3,7 @@ use solana_sdk::instruction::Instruction;
use anchor_lang::prelude::{AccountMeta, Pubkey};
use anyhow::Context;
use tracing::info;
/// Some Result<> types don't convert to anyhow::Result nicely. Force them through stringification.
pub trait AnyhowWrap {
@ -59,6 +60,19 @@ pub fn tracing_subscriber_init() {
.init();
}
pub fn print_git_version() {
info!(
"version is {}[{}{}]",
env!("VERGEN_GIT_SHA"),
env!("VERGEN_GIT_COMMIT_DATE"),
if env!("VERGEN_GIT_DIRTY") == "true" {
"-dirty"
} else {
""
}
);
}
pub async fn http_error_handling<T: serde::de::DeserializeOwned>(
response: reqwest::Response,
) -> anyhow::Result<T> {