From 8fd5b2358f13bf9f9d629329f5ad59f9e53189fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Wed, 16 Sep 2020 12:50:55 +0200 Subject: [PATCH] switching veloren naming scheme, to either one of the following: `stable-0.7.0 (-)` for release versions. And `nightly- ()` for nightly and master versions Reason is, many players only give information that they are running `0.x.0` but are not giving us the information which day, or commit they are running. So we should make master builds less confusing. --- common/build.rs | 28 +++++++++++++++++++++++++++ common/src/util/mod.rs | 15 +++++++++++++- server-cli/src/main.rs | 9 +-------- server/src/lib.rs | 7 +++++-- voxygen/src/hud/mod.rs | 8 ++------ voxygen/src/menu/char_selection/ui.rs | 21 ++++++++++---------- voxygen/src/menu/main/ui.rs | 21 ++++++++++---------- 7 files changed, 70 insertions(+), 39 deletions(-) diff --git a/common/build.rs b/common/build.rs index baea7b2a9c..f83352cfd1 100644 --- a/common/build.rs +++ b/common/build.rs @@ -36,6 +36,23 @@ fn main() { }, Err(e) => panic!("failed to retrieve current git commit hash: {}", e), } + + // Get the current githash + // Note: It will compare commits. As long as the commits do not diverge from the + // server no version change will be detected. + match Command::new("git") + .args(&["describe", "--exact-match", "--tags", "HEAD"]) + .output() + { + Ok(output) => match String::from_utf8(output.stdout) { + Ok(tag) => { + create_tag_file(&tag); + }, + Err(e) => panic!("failed to convert git output to UTF-8: {}", e), + }, + Err(e) => panic!("failed to retrieve current git commit hash: {}", e), + } + // Check if git-lfs is working if std::env::var("DISABLE_GIT_LFS_CHECK").is_err() && cfg!(not(feature = "no-assets")) { let asset_path: PathBuf = ["..", "assets", "voxygen", "background", "bg_main.png"] @@ -79,3 +96,14 @@ fn create_hash_file(hash: &str) { .write_all(hash.trim().as_bytes()) .expect("failed to write to file!"); } + +fn create_tag_file(tag: &str) { + let mut target = File::create( + Path::new(&env::var("OUT_DIR").expect("failed to query OUT_DIR environment variable")) + .join("gittag"), + ) + .expect("failed to create git tag file!"); + target + .write_all(tag.trim().as_bytes()) + .expect("failed to write to file!"); +} diff --git a/common/src/util/mod.rs b/common/src/util/mod.rs index dff7e80031..831145cc11 100644 --- a/common/src/util/mod.rs +++ b/common/src/util/mod.rs @@ -3,10 +3,23 @@ mod dir; mod option; pub const GIT_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/githash")); +pub const GIT_TAG: &str = include_str!(concat!(env!("OUT_DIR"), "/gittag")); lazy_static::lazy_static! { pub static ref GIT_HASH: &'static str = GIT_VERSION.split('/').next().expect("failed to retrieve git_hash!"); - pub static ref GIT_DATE: &'static str = GIT_VERSION.split('/').nth(1).expect("failed to retrieve git_date!"); + static ref GIT_DATETIME: &'static str = GIT_VERSION.split('/').nth(1).expect("failed to retrieve git_datetime!"); + pub static ref GIT_DATE: String = GIT_DATETIME.split('-').take(3).collect::>().join("-"); + pub static ref GIT_TIME: &'static str = GIT_DATETIME.split('-').nth(3).expect("failed to retrieve git_time!"); + pub static ref DISPLAY_VERSION: String = if GIT_TAG == "" { + format!("nightly-{}", GIT_DATE.to_string()) + } else { + format!("stable-{}", GIT_TAG.to_string()) + }; + pub static ref DISPLAY_VERSION_LONG: String = if GIT_TAG == "" { + format!("{} ({})", DISPLAY_VERSION.as_str(), GIT_HASH.to_string()) + } else { + format!("{} ({})", DISPLAY_VERSION.as_str(), GIT_VERSION.to_string()) + }; } pub use color::*; diff --git a/server-cli/src/main.rs b/server-cli/src/main.rs index 04898fc9d2..bae9cc6a50 100644 --- a/server-cli/src/main.rs +++ b/server-cli/src/main.rs @@ -28,14 +28,7 @@ lazy_static! { fn main() -> io::Result<()> { let matches = App::new("Veloren server cli") - .version( - format!( - "{}-{}", - env!("CARGO_PKG_VERSION"), - common::util::GIT_HASH.to_string() - ) - .as_str(), - ) + .version(common::util::DISPLAY_VERSION_LONG.as_str()) .author("The veloren devs ") .about("The veloren server cli provides an easy to use interface to start a veloren server") .arg( diff --git a/server/src/lib.rs b/server/src/lib.rs index 89683d1b28..aeb887e6eb 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -328,8 +328,11 @@ impl Server { debug!(?settings, "created veloren server with"); let git_hash = *common::util::GIT_HASH; - let git_date = *common::util::GIT_DATE; - info!(?git_hash, ?git_date, "Server version",); + let git_date = common::util::GIT_DATE.clone(); + let git_time = *common::util::GIT_TIME; + let version = common::util::DISPLAY_VERSION_LONG.clone(); + info!(?version, "Server version"); + debug!(?git_hash, ?git_date, ?git_time, "detailed Server version"); Ok(this) } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 17a5ffa1c3..3f8465e4da 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -696,11 +696,7 @@ impl Hud { self.pulse = self.pulse + dt.as_secs_f32(); // FPS let fps = global_state.clock.get_tps(); - let version = format!( - "{}-{}", - env!("CARGO_PKG_VERSION"), - common::util::GIT_VERSION.to_string() - ); + let version = common::util::DISPLAY_VERSION_LONG.clone(); if self.show.ingame { let ecs = client.state().ecs(); @@ -736,7 +732,7 @@ impl Hud { .set(self.ids.hurt_bg, ui_widgets); } // Alpha Disclaimer - Text::new(&format!("Veloren Pre-Alpha {}", env!("CARGO_PKG_VERSION"))) + Text::new(&format!("Veloren Pre-Alpha {}", &version)) .font_id(self.fonts.cyri.conrod_id) .font_size(self.fonts.cyri.scale(10)) .color(TEXT_COLOR) diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index ea56d1ba6b..22565ee452 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -442,11 +442,7 @@ impl CharSelectionUi { } } let (ref mut ui_widgets, ref mut tooltip_manager) = self.ui.set_widgets(); - let version = format!( - "{}-{}", - env!("CARGO_PKG_VERSION"), - common::util::GIT_VERSION.to_string() - ); + let version = common::util::DISPLAY_VERSION_LONG.clone(); // Tooltip let tooltip_human = Tooltip::new({ @@ -720,12 +716,15 @@ impl CharSelectionUi { .color(TEXT_COLOR) .set(self.ids.version, ui_widgets); // Alpha Disclaimer - Text::new(&format!("Veloren Pre-Alpha {}", env!("CARGO_PKG_VERSION"))) - .font_id(self.fonts.cyri.conrod_id) - .font_size(self.fonts.cyri.scale(10)) - .color(TEXT_COLOR) - .mid_top_with_margin_on(ui_widgets.window, 2.0) - .set(self.ids.alpha_text, ui_widgets); + Text::new(&format!( + "Veloren Pre-Alpha {}", + common::util::DISPLAY_VERSION.as_str() + )) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(10)) + .color(TEXT_COLOR) + .mid_top_with_margin_on(ui_widgets.window, 2.0) + .set(self.ids.alpha_text, ui_widgets); // Resize character selection widgets self.ids diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index bd51f3476b..57d6010c8b 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -267,11 +267,7 @@ impl<'a> MainMenuUi { ); let tip_show = global_state.settings.gameplay.loading_tips; let mut rng = thread_rng(); - let version = format!( - "{}-{}", - env!("CARGO_PKG_VERSION"), - common::util::GIT_VERSION.to_string() - ); + let version = common::util::DISPLAY_VERSION_LONG.clone(); let scale = 0.8; const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); const TEXT_COLOR_2: Color = Color::Rgba(1.0, 1.0, 1.0, 0.2); @@ -364,12 +360,15 @@ impl<'a> MainMenuUi { .font_size(self.fonts.cyri.scale(14)) .set(self.ids.version, ui_widgets); // Alpha Disclaimer - Text::new(&format!("Veloren Pre-Alpha {}", env!("CARGO_PKG_VERSION"))) - .font_id(self.fonts.cyri.conrod_id) - .font_size(self.fonts.cyri.scale(10)) - .color(TEXT_COLOR) - .mid_top_with_margin_on(ui_widgets.window, 2.0) - .set(self.ids.alpha_text, ui_widgets); + Text::new(&format!( + "Veloren Pre-Alpha {}", + common::util::DISPLAY_VERSION.as_str() + )) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(10)) + .color(TEXT_COLOR) + .mid_top_with_margin_on(ui_widgets.window, 2.0) + .set(self.ids.alpha_text, ui_widgets); // Popup (Error/Info/AuthTrustPrompt) let mut change_popup = None; if let Some(PopupData { msg, popup_type }) = &self.popup {