From eb28ba94f6b02c637037022c0dc08bf9f88fd2ad Mon Sep 17 00:00:00 2001 From: Songtronix <505534-Songtronix@users.noreply.gitlab.com> Date: Fri, 28 Jun 2019 12:08:12 +0000 Subject: [PATCH] add git commit hash to debug window --- voxygen/build.rs | 14 ++++++++++++++ voxygen/src/hud/mod.rs | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 voxygen/build.rs diff --git a/voxygen/build.rs b/voxygen/build.rs new file mode 100644 index 0000000000..5f9bb58fa4 --- /dev/null +++ b/voxygen/build.rs @@ -0,0 +1,14 @@ +use std::process::Command; + +fn main() { + match Command::new("git") + .args(&["rev-parse", "--short", "HEAD"]) + .output() + { + Ok(output) => match String::from_utf8(output.stdout) { + Ok(hash) => println!("cargo:rustc-env=GIT_HASH={}", hash), + Err(e) => println!("failed to convert git output to UTF-8: {}", e), + }, + Err(e) => println!("failed to retrieve current git commit hash: {}", e), + } +} diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 9e9e9c4d8b..04f74b94fc 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -305,7 +305,11 @@ impl Hud { ) -> Vec { let mut events = Vec::new(); let ref mut ui_widgets = self.ui.set_widgets(); - let version = env!("CARGO_PKG_VERSION"); + + let version = match std::env::var("GIT_HASH") { + Ok(hash) => format!("{}-{}", env!("CARGO_PKG_VERSION"), hash), + Err(_) => env!("CARGO_PKG_VERSION").to_owned(), + }; // Don't show anything if the UI is toggled off. if !self.show.ui { @@ -421,7 +425,7 @@ impl Hud { // Display debug window. if self.show.debug { // Alpha Version - Text::new(version) + Text::new(&version) .top_left_with_margins_on(ui_widgets.window, 5.0, 5.0) .font_size(14) .font_id(self.fonts.opensans)