From f9bd3cdc522fba2d5e19b018308113a4258c0f43 Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Thu, 1 Aug 2019 08:47:24 +0800 Subject: [PATCH] add git hash --- build.rs | 7 +++++++ src/main.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 62bfee9..97b76c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ use build_json::*; const BUILDJ: &str = "buildj"; const BUDERJ_VER: &str = env!("CARGO_PKG_VERSION"); +const GIT_HASH: &str = env!("GIT_HASH"); fn print_usage() { @@ -150,7 +151,7 @@ fn do_with_buildin_args(args: &Vec) { fn main() { - print_message(MessageType::INFO, &format!("{} - version {}", BUILDJ, BUDERJ_VER)); + print_message(MessageType::INFO, &format!("{} - version {} - {}", BUILDJ, BUDERJ_VER, &GIT_HASH[0..7])); let args = local_util::get_args_as_vec(); print_message(MessageType::INFO, &format!("Arguments: {:?}", args));