Skip to content

Commit

Permalink
Show git short sha on splash screen
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Aug 10, 2024
1 parent b5f229b commit 09dedce
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 1 deletion.
177 changes: 177 additions & 0 deletions firmware/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ lto = "fat"
opt-level = "s"
overflow-checks = false

[build-dependencies]
git2 = "0.19"

[dependencies]
display-interface = "0.5"
embassy-executor = { version = "0.5", features = ["log"] }
Expand Down
24 changes: 24 additions & 0 deletions firmware/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use core::str;
use git2::{Repository, StatusOptions};
use std::{env, error::Error};

fn main() -> Result<(), Box<dyn Error>> {
// In contrast to git describe, we don't want to show a tag name, but always the short sha and
// dirty status as a useful addition to the version number in CARGO_PKG_VERSION.
let repo = Repository::discover(env::var("CARGO_MANIFEST_DIR")?)?;
let head_obj = repo.revparse_single("HEAD")?;
let short_sha_buf = head_obj.short_id()?;
let short_sha = str::from_utf8(&short_sha_buf)?;
let mut status_options = StatusOptions::default();
// let _ = status_options.include_untracked(true);
let statuses = repo.statuses(Some(&mut status_options))?;
let dirty = statuses.iter().any(|st| !st.status().is_ignored());
let dirty_str = if dirty { "+" } else { "" };
println!("cargo::rustc-env=GIT_SHORT_SHA={}{}", short_sha, dirty_str);

println!("cargo::rerun-if-changed=build.rs");
println!("cargo::rerun-if-changed=.git/");
println!("cargo::rerun-if-changed=.git/HEAD");

Ok(())
}
9 changes: 8 additions & 1 deletion firmware/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use embedded_graphics::mono_font::ascii::{FONT_10X20, FONT_6X10, FONT_9X18_BOLD};
use embedded_graphics::mono_font::ascii::{FONT_10X20, FONT_5X8, FONT_6X10, FONT_9X18_BOLD};
use embedded_graphics::mono_font::MonoTextStyle;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
Expand Down Expand Up @@ -65,6 +65,13 @@ impl<I2C: I2c> Display<I2C> {
Alignment::Center,
)
.draw(&mut self.driver)?;
Text::with_alignment(
env!("GIT_SHORT_SHA"),
Point::new(127, 63),
MonoTextStyle::new(&FONT_5X8, BinaryColor::On),
Alignment::Right,
)
.draw(&mut self.driver)?;
self.driver.flush()?;
Ok(())
}
Expand Down

0 comments on commit 09dedce

Please sign in to comment.