From 9fc0112f8c6445eaf7fdf7e51b1ef2449caae5ca Mon Sep 17 00:00:00 2001 From: Tad Hardesty Date: Fri, 15 Nov 2019 22:32:26 -0800 Subject: [PATCH] Add version info to editor help menu --- src/editor/Cargo.toml | 4 ++++ src/editor/build.rs | 25 +++++++++++++++++++++++-- src/editor/main.rs | 14 +++++++++++--- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/editor/Cargo.toml b/src/editor/Cargo.toml index dc0f1968..f35cee59 100644 --- a/src/editor/Cargo.toml +++ b/src/editor/Cargo.toml @@ -31,3 +31,7 @@ slice-of-array = "0.2.0" [dependencies.nfd] git = "https://github.com/SpaceManiac/nfd-rs" branch = "zenity" + +[build-dependencies] +chrono = "0.4.0" +git2 = { version = "0.10", default-features = false } diff --git a/src/editor/build.rs b/src/editor/build.rs index 1becf4e1..fa2ca3cf 100644 --- a/src/editor/build.rs +++ b/src/editor/build.rs @@ -1,8 +1,23 @@ -use std::process::Command; +extern crate chrono; +extern crate git2; + use std::env; -use std::path::Path; +use std::fs::File; +use std::io::Write; +use std::process::Command; +use std::path::{Path, PathBuf}; fn main() { + // build info + let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + let mut f = File::create(&out_dir.join("build-info.txt")).unwrap(); + + if let Ok(commit) = read_commit() { + writeln!(f, "commit: {}", commit).unwrap(); + } + writeln!(f, "build date: {}", chrono::Utc::today()).unwrap(); + + // windres icon if cfg!(windows) { let out_dir = env::var("OUT_DIR").ok().expect("can't find out_dir"); @@ -37,3 +52,9 @@ fn main() { println!("cargo:rustc-link-lib=static=editor_rc"); } } + +fn read_commit() -> Result { + let repo = git2::Repository::discover(".")?; + let hash = repo.head()?.peel_to_commit()?.id().to_string(); + Ok(hash) +} diff --git a/src/editor/main.rs b/src/editor/main.rs index 24f016ea..e75a68d2 100644 --- a/src/editor/main.rs +++ b/src/editor/main.rs @@ -570,9 +570,17 @@ impl EditorScene { }); } ui.menu(im_str!("Help"), true, || { - MenuItem::new(im_str!("About SpacemanDMM")) - .enabled(false) - .build(ui); + ui.menu(im_str!("About SpacemanDMM"), true, || { + ui.bullet_text(&im_str!( + "{} {} Copyright (C) 2017-2019 Tad Hardesty", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + )); + ui.bullet_text(&im_str!("{}", include_str!(concat!(env!("OUT_DIR"), "/build-info.txt")))); + ui.bullet_text(im_str!("This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ + and you are welcome to redistribute it under the conditions of the GNU\n\ + General Public License version 3.")); + }); MenuItem::new(im_str!("Open-source licenses")) .enabled(false) .build(ui);