From c83b60a28cb7b4c73e92ee0ec06a9f2c55b83dd5 Mon Sep 17 00:00:00 2001 From: minneelyyyy Date: Thu, 24 Oct 2024 14:23:41 -0400 Subject: [PATCH] add git branch and commit to version information --- build.rs | 15 +++++++++++++++ src/lib.rs | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..c6445e1 --- /dev/null +++ b/build.rs @@ -0,0 +1,15 @@ +use std::process::Command; + +fn main() { + // get + let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output() + .expect("git rev-parse HEAD failed"); + let hash = String::from_utf8(output.stdout).expect("not UTF-8 output"); + + let output = Command::new("git").args(&["rev-parse", "--abbrev-ref", "HEAD"]).output() + .expect("git rev-parse HEAD failed"); + let branch = String::from_utf8(output.stdout).expect("not UTF-8 output"); + + println!("cargo:rustc-env=GIT_HASH={}", hash); + println!("cargo:rustc-env=GIT_BRANCH={}", branch); +} diff --git a/src/lib.rs b/src/lib.rs index 58a2ca7..99f10c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -184,7 +184,11 @@ impl<'a, R: BufRead> Runtime<'a, R> { globals: HashMap::from([ ("version'".into(), Arc::new( Mutex::new( - Object::value(Value::String(env!("CARGO_PKG_VERSION").into()), HashMap::new(), HashMap::new())))) + Object::value(Value::String( + format!("{} ({}/{})", + env!("CARGO_PKG_VERSION"), + env!("GIT_BRANCH"), + env!("GIT_HASH"))), HashMap::new(), HashMap::new())))) ]), parser: None, }