From 807d34b66b6e7407fac8e3b83eb2e97edd1931cc Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Fri, 2 Aug 2019 01:23:55 +0800 Subject: [PATCH] add git hash --- build.rs | 7 +++++++ src/main.rs | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..63ac78b --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +use std::process::Command; +fn main() { + // note: add error checking yourself. + let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap(); + let git_hash = String::from_utf8(output.stdout).unwrap(); + println!("cargo:rustc-env=GIT_HASH={}", git_hash); +} diff --git a/src/main.rs b/src/main.rs index 4ac3812..d1abeba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,14 +14,15 @@ use argparse::{ArgumentParser, StoreTrue, Store}; use rust_util::*; const VERSION: &str = env!("CARGO_PKG_VERSION"); +const GIT_HASH: &str = env!("GIT_HASH"); fn print_version() { - print!(r#"prettyjson {} + print!(r#"prettyjson {} - {} Copyright (C) 2019 Hatter Jiang. License MIT Written by Hatter Jiang -"#, VERSION); +"#, VERSION, &GIT_HASH[0..7]); } fn read_to_string(read: &mut Read) -> XResult {