add global git hash constant

This commit is contained in:
Songtronix 2019-07-21 17:45:31 +00:00 committed by Joshua Barretto
parent 02180db437
commit de2dbcef45
7 changed files with 42 additions and 19 deletions

View File

@ -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()

29
common/build.rs Normal file
View File

@ -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),
}
}

View File

@ -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)]

View File

@ -1 +1 @@
pub const GIT_HASH: &str = include_str!(concat!(env!("OUT_DIR"), "/githash"));

View File

@ -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,
};

View File

@ -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),
}
}

View File

@ -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 {