Skip to content

Commit

Permalink
Add build revision to splash screen
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Jul 25, 2024
1 parent a96ad41 commit 247621d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,3 +92,20 @@ fn module_name(path: &Path) -> Result<String, &str> {
})
.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);
}
1 change: 1 addition & 0 deletions src/presenters/modes/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 247621d

Please sign in to comment.