Skip to content

Commit f960d77

Browse files
committed
loging git commit hash, build time, and light-client version at startup
Signed-off-by: Eval EXEC <execvy@gmail.com>
1 parent e1508cf commit f960d77

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

light-client-bin/build.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ use std::process::Command;
22
use vergen_gitcl::{Emitter, GitclBuilder};
33

44
fn main() -> Result<(), Box<dyn std::error::Error>> {
5-
let gitcl = GitclBuilder::default()
6-
.sha(true)
7-
.dirty(true)
8-
.build()?;
5+
let gitcl = GitclBuilder::default().sha(true).dirty(true).build()?;
96

10-
Emitter::default()
11-
.add_instructions(&gitcl)?
12-
.emit()?;
7+
Emitter::default().add_instructions(&gitcl)?.emit()?;
138

149
// Check if git working directory is dirty and create a suffix
1510
let is_dirty = Command::new("git")

light-client-bin/src/cli.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,34 @@ pub(crate) struct RunConfig {
1313
pub(crate) run_env: RunEnv,
1414
}
1515

16+
pub fn binary_version() -> &'static str {
17+
env!("CARGO_PKG_VERSION")
18+
}
19+
20+
pub fn git_hash() -> &'static str {
21+
concat!(env!("VERGEN_GIT_SHA"), env!("GIT_DIRTY_SUFFIX"))
22+
}
23+
24+
pub fn build_time() -> &'static str {
25+
env!("VERGEN_BUILD_TIMESTAMP")
26+
}
27+
28+
fn version_info() -> &'static str {
29+
concat!(
30+
env!("CARGO_PKG_VERSION"),
31+
" (",
32+
env!("VERGEN_GIT_SHA"),
33+
env!("GIT_DIRTY_SUFFIX"),
34+
" ",
35+
env!("VERGEN_BUILD_TIMESTAMP"),
36+
")"
37+
)
38+
}
39+
1640
impl AppConfig {
1741
pub(crate) fn load() -> Result<Self> {
18-
let version = concat!(
19-
env!("CARGO_PKG_VERSION"),
20-
" (",
21-
env!("VERGEN_GIT_SHA"),
22-
env!("GIT_DIRTY_SUFFIX"),
23-
" ",
24-
env!("VERGEN_BUILD_TIMESTAMP"),
25-
")"
26-
);
27-
2842
let cmd = clap::Command::new("CKB Light Client")
29-
.version(version)
43+
.version(version_info())
3044
.author(clap::crate_authors!("\n"))
3145
.about(clap::crate_description!())
3246
.subcommand_required(true)

light-client-bin/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ fn main() -> anyhow::Result<()> {
2020
.try_init()
2121
.expect("env_logger builder init should be ok");
2222

23-
log::info!("Starting ...");
23+
log::info!("Starting CKB Light Client ...");
24+
log::info!("Version: {}", cli::binary_version());
25+
log::info!("Git Hash: {}", cli::git_hash());
26+
log::info!("Built Time: {}", cli::build_time());
2427

2528
AppConfig::load()?.execute()?;
2629

0 commit comments

Comments
 (0)