From de2dbcef45777256e691e81a5ae7969f216373aa Mon Sep 17 00:00:00 2001 From: Songtronix <505534-Songtronix@users.noreply.gitlab.com> Date: Sun, 21 Jul 2019 17:45:31 +0000 Subject: [PATCH] add global git hash constant --- client/src/lib.rs | 9 +++++++++ common/build.rs | 29 +++++++++++++++++++++++++++++ common/src/msg/server.rs | 1 + common/src/util/mod.rs | 2 +- server/src/lib.rs | 1 + voxygen/build.rs | 14 -------------- voxygen/src/hud/mod.rs | 5 +---- 7 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 common/build.rs delete mode 100644 voxygen/build.rs diff --git a/client/src/lib.rs b/client/src/lib.rs index 52070b2eca..a75a4a34fe 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -66,6 +66,15 @@ impl Client { entity_uid, server_info, }) => { + // TODO: Voxygen should display this. + if server_info.git_hash != common::util::GIT_HASH.to_string() { + log::warn!( + "Git hash mismatch between client and server: {} vs {}", + server_info.git_hash, + common::util::GIT_HASH + ); + } + let state = State::from_state_package(ecs_state); let entity = state .ecs() diff --git a/common/build.rs b/common/build.rs new file mode 100644 index 0000000000..326e4e17cc --- /dev/null +++ b/common/build.rs @@ -0,0 +1,29 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::Path; +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) => { + let mut target = File::create( + Path::new( + &env::var("OUT_DIR").expect("failed to query OUT_DIR environment variable"), + ) + .join("githash"), + ) + .expect("failed to create git hash file!"); + target + .write_all(hash.trim().as_bytes()) + .expect("failed to write to file!"); + } + Err(e) => panic!("failed to convert git output to UTF-8: {}", e), + }, + Err(e) => panic!("failed to retrieve current git commit hash: {}", e), + } +} diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index 71bdff23f0..06c53af40f 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -18,6 +18,7 @@ pub enum RequestStateError { pub struct ServerInfo { pub name: String, pub description: String, + pub git_hash: String, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/common/src/util/mod.rs b/common/src/util/mod.rs index 8b13789179..6ab36f75c4 100644 --- a/common/src/util/mod.rs +++ b/common/src/util/mod.rs @@ -1 +1 @@ - +pub const GIT_HASH: &str = include_str!(concat!(env!("OUT_DIR"), "/githash")); diff --git a/server/src/lib.rs b/server/src/lib.rs index f485dda503..6958c62b7e 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -106,6 +106,7 @@ impl Server { server_info: ServerInfo { name: settings.server_name.clone(), description: settings.server_description.clone(), + git_hash: common::util::GIT_HASH.to_string(), }, server_settings: settings, }; diff --git a/voxygen/build.rs b/voxygen/build.rs deleted file mode 100644 index 5f9bb58fa4..0000000000 --- a/voxygen/build.rs +++ /dev/null @@ -1,14 +0,0 @@ -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 c327ddd4c6..c63425e18e 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -322,10 +322,7 @@ impl Hud { let mut events = Vec::new(); let ref mut ui_widgets = self.ui.set_widgets(); - let version = match std::env::var("GIT_HASH") { - Ok(hash) => format!("{}-{}", env!("CARGO_PKG_VERSION"), hash), - Err(_) => env!("CARGO_PKG_VERSION").to_owned(), - }; + let version = format!("{}-{}", env!("CARGO_PKG_VERSION"), common::util::GIT_HASH); // Nametags and healthbars if self.show.ingame {