diff --git a/build.rs b/build.rs index 601d32fa..d2dd6643 100644 --- a/build.rs +++ b/build.rs @@ -3,12 +3,14 @@ use std::env; use std::fs::{self, read_to_string, File}; use std::io::Write; use std::path::Path; +use std::process::Command; use std::result::Result; const COMMAND_REGEX: &str = r"pub fn (.*)\(app: &mut Application\) -> Result"; fn main() { generate_commands(); + set_build_revision(); } /// This build task generates a Rust snippet which, when included later on in @@ -90,3 +92,20 @@ fn module_name(path: &Path) -> Result { }) .ok_or("Unable to parse command module from file name") } + +fn set_build_revision() { + // Run the Git command to get the current commit hash + let output = Command::new("git") + .args(&["rev-parse", "--short", "HEAD"]) + .output() + .expect("Failed to execute git command"); + + // Parse the hash + let build_revision = String::from_utf8(output.stdout) + .expect("Invalid UTF-8 sequence") + .trim() + .to_string(); + + // Write the hash as an environment variable + println!("cargo:rustc-env=BUILD_REVISION={}", build_revision); +} diff --git a/src/presenters/modes/normal.rs b/src/presenters/modes/normal.rs index 4bbb6f8a..5ef8a227 100644 --- a/src/presenters/modes/normal.rs +++ b/src/presenters/modes/normal.rs @@ -43,6 +43,7 @@ pub fn display( } else { let content = [ format!("Amp v{}", env!("CARGO_PKG_VERSION")), + format!("Build revision {}", env!("BUILD_REVISION")), String::from("© 2015-2024 Jordan MacDonald"), String::from(" "), String::from("Press \"?\" to view quick start guide"),