Skip to content

Commit d6669b2

Browse files
authored
Add version prints (#69)
Add git commit and git tag (if exists) prints for the Zebra node startup.
2 parents d2a0b64 + 72fa2e4 commit d6669b2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

zebrad/build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! When compiling the `lightwalletd` gRPC tests, also builds a gRPC client
77
//! Rust API for `lightwalletd`.
88
9+
use std::process::Command;
910
use vergen::EmitBuilder;
1011

1112
/// Returns a new `vergen` builder, configured for everything except for `git` env vars.
@@ -18,6 +19,18 @@ fn base_vergen_builder() -> EmitBuilder {
1819
vergen
1920
}
2021

22+
/// Run a git command and return the output, or a fallback value if it fails
23+
fn run_git_command(args: &[&str], fallback: &str) -> String {
24+
Command::new("git")
25+
.args(args)
26+
.output()
27+
.ok()
28+
.and_then(|o| String::from_utf8(o.stdout).ok())
29+
.map(|s| s.trim().to_string())
30+
.filter(|s| !s.is_empty())
31+
.unwrap_or_else(|| fallback.to_owned())
32+
}
33+
2134
/// Process entry point for `zebrad`'s build script
2235
#[allow(clippy::print_stderr)]
2336
fn main() {
@@ -52,4 +65,11 @@ fn main() {
5265
&["tests/common/lightwalletd/proto"],
5366
)
5467
.expect("Failed to generate lightwalletd gRPC files");
68+
69+
// Add custom git tag and commit information
70+
let git_tag = run_git_command(&["describe", "--exact-match", "--tags"], "none"); // Will be set to 'none' if .git is missing or git fails.
71+
let git_commit = run_git_command(&["rev-parse", "HEAD"], "none"); // Will be set to 'none' if .git is missing or git fails.
72+
73+
println!("cargo:rustc-env=GIT_TAG={}", git_tag);
74+
println!("cargo:rustc-env=GIT_COMMIT_FULL={}", git_commit);
5575
}

zebrad/src/application.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ impl Application for ZebradApp {
295295
let git_metadata: &[(_, Option<_>)] = &[
296296
("branch", option_env!("VERGEN_GIT_BRANCH")),
297297
("git commit", Self::git_commit()),
298+
("git tag", option_env!("GIT_TAG")),
299+
("git commit full", option_env!("GIT_COMMIT_FULL")),
298300
(
299301
"commit timestamp",
300302
option_env!("VERGEN_GIT_COMMIT_TIMESTAMP"),

0 commit comments

Comments
 (0)