Skip to content

Commit

Permalink
feat: include git commit in version info (#249)
Browse files Browse the repository at this point in the history
* feat: report git commit in version info, check commit for mismatches

* feat: use vergen to get commit info

* fix: install git in recipes

* fix: include git dir in pkger builds
  • Loading branch information
ilya-zlobintsev authored Mar 2, 2024
1 parent 9fc0eae commit d99cfdf
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 17 deletions.
82 changes: 82 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ As some of the GPU settings may get reset when suspending the system, LACT will
Dependencies:
- rust
- gtk4
- git
- pkg-config
- make
- hwdata
Expand Down
3 changes: 2 additions & 1 deletion lact-daemon/src/server/system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, Context};
use lact_schema::{InitramfsType, SystemInfo};
use lact_schema::{InitramfsType, SystemInfo, GIT_COMMIT};
use os_release::{OsRelease, OS_RELEASE};
use std::{
fs::{self, File, Permissions},
Expand Down Expand Up @@ -41,6 +41,7 @@ pub fn info() -> anyhow::Result<SystemInfo<'static>> {
profile,
kernel_version,
amdgpu_overdrive_enabled,
commit: Some(GIT_COMMIT),
})
}

Expand Down
5 changes: 3 additions & 2 deletions lact-gui/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use gtk::glib::{timeout_future, ControlFlow};
use gtk::{gio::ApplicationFlags, prelude::*, *};
use header::Header;
use lact_client::schema::request::{ConfirmCommand, SetClocksCommand};
use lact_client::schema::GIT_COMMIT;
use lact_client::DaemonClient;
use lact_daemon::MODULE_CONF_PATH;
use root_stack::RootStack;
Expand Down Expand Up @@ -56,8 +57,8 @@ impl App {
.icon_name(APP_ID)
.build();

if system_info.version != GUI_VERSION {
let err = anyhow!("Version mismatch between GUI and daemon ({GUI_VERSION} vs {})! Make sure you have restarted the service if you have updated LACT.", system_info.version);
if system_info.version != GUI_VERSION || system_info.commit != Some(GIT_COMMIT) {
let err = anyhow!("Version mismatch between GUI and daemon ({GUI_VERSION}-{GIT_COMMIT} vs {}-{})! Make sure you have restarted the service if you have updated LACT.", system_info.version, system_info.commit.unwrap_or_default());
show_error(&window, err);
}

Expand Down
8 changes: 6 additions & 2 deletions lact-gui/src/app/root_stack/software_page.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::GUI_VERSION;
use gtk::glib::{self, Object};
use lact_client::schema::SystemInfo;
use lact_client::schema::{SystemInfo, GIT_COMMIT};
use std::fmt::Write;

glib::wrapper! {
pub struct SoftwarePage(ObjectSubclass<imp::SoftwarePage>)
Expand All @@ -14,13 +15,16 @@ impl SoftwarePage {
if embedded {
daemon_version.push_str("-embedded");
}
if let Some(commit) = system_info.commit {
write!(daemon_version, " (commit {commit})").unwrap();
}

let gui_profile = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
let gui_version = format!("{GUI_VERSION}-{gui_profile}");
let gui_version = format!("{GUI_VERSION}-{gui_profile} (commit {GIT_COMMIT})");

Object::builder()
.property("daemon-version", daemon_version)
Expand Down
3 changes: 3 additions & 0 deletions lact-schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ serde_with = { workspace = true }
indexmap = { version = "*", features = ["serde"] }
clap = { version = "4.4.18", features = ["derive"], optional = true }

[build-dependencies]
vergen = { version = "8.0.0", features = ["git", "gitcl"] }

[dev-dependencies]
serde_json = { workspace = true }
5 changes: 5 additions & 0 deletions lact-schema/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use vergen::EmitBuilder;

fn main() {
EmitBuilder::builder().git_sha(true).emit().unwrap()
}
3 changes: 3 additions & 0 deletions lact-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ use std::{
str::FromStr,
};

pub const GIT_COMMIT: &str = env!("VERGEN_GIT_SHA");

#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum FanControlMode {
Expand Down Expand Up @@ -58,6 +60,7 @@ pub struct Pong;
#[derive(Serialize, Deserialize, Debug)]
pub struct SystemInfo<'a> {
pub version: &'a str,
pub commit: Option<&'a str>,
pub profile: &'a str,
pub kernel_version: String,
pub amdgpu_overdrive_enabled: Option<bool>,
Expand Down
8 changes: 4 additions & 4 deletions pkg/recipes/lact-headless/recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
maintainer: ilya-zlobintsev
url: https://github.com/ilya-zlobintsev/lact
source:
- '../../..'
- '../../../../LACT'
provides: [ lact ]
conflicts: [ lact, lact-libadwaita ]
depends:
Expand All @@ -17,7 +17,7 @@ metadata:
arch: [ libdrm ]
opensuse-tumbleweed: [ libdrm ]
build_depends:
all: [ curl, make, clang ]
all: [ curl, make, clang, git ]
debian-12+ubuntu-2204: [ pkg-config, build-essential, libdrm-dev, dbus ]
fedora-38+fedora-39: [ gcc, libdrm-devel, dbus ]
arch: [ libdrm, dbus ]
Expand All @@ -31,8 +31,8 @@ configure:
- cmd: sh /tmp/install_rust.sh -y --default-toolchain stable
build:
steps:
- cmd: bash -c "source $HOME/.cargo/env && make build-release-headless"
- cmd: bash -c "source $HOME/.cargo/env && cd LACT && make build-release-headless"
install:
steps:
- cmd: bash -c "cd $PKGER_BLD_DIR && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"
- cmd: bash -c "cd $PKGER_BLD_DIR/LACT && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"

8 changes: 4 additions & 4 deletions pkg/recipes/lact-libadwaita/recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
maintainer: ilya-zlobintsev
url: https://github.com/ilya-zlobintsev/lact
source:
- '../../..'
- '../../../../LACT'
provides: [ lact ]
conflicts: [ lact, lact-headless ]
depends:
Expand All @@ -16,7 +16,7 @@ metadata:
arch: [ gtk4, libadwaita ]
opensuse-tumbleweed: [ libdrm, libadwaita ]
build_depends:
all: [ curl, make, clang ]
all: [ curl, make, clang, git ]
fedora-39: [ gtk4-devel, gcc, libdrm-devel, blueprint-compiler, libadwaita-devel, dbus ]
arch: [ gtk4, blueprint-compiler, libadwaita, dbus ]
opensuse-tumbleweed: [ libdrm-devel, blueprint-compiler, libadwaita-devel ]
Expand All @@ -33,8 +33,8 @@ configure:
deb: true
build:
steps:
- cmd: bash -c "source $HOME/.cargo/env && make build-release-libadwaita"
- cmd: bash -c "source $HOME/.cargo/env && cd LACT && make build-release-libadwaita"
install:
steps:
- cmd: bash -c "cd $PKGER_BLD_DIR && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"
- cmd: bash -c "cd $PKGER_BLD_DIR/LACT && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"

8 changes: 4 additions & 4 deletions pkg/recipes/lact/recipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
maintainer: ilya-zlobintsev
url: https://github.com/ilya-zlobintsev/lact
source:
- '../../..'
- '../../../../LACT'
provides: [ lact ]
conflicts: [ lact-headless, lact-libadwaita ]
depends:
Expand All @@ -17,7 +17,7 @@ metadata:
arch: [ gtk4 ]
opensuse-tumbleweed: [ gtk4 ]
build_depends:
all: [ curl, make, clang ]
all: [ curl, make, clang, git ]
debian-12+ubuntu-2204: [ libgtk-4-dev, pkg-config, build-essential, libdrm-dev, dbus ]
fedora-38+fedora-39: [ gtk4-devel, gcc, libdrm-devel, blueprint-compiler, dbus ]
arch: [ gtk4, blueprint-compiler, dbus ]
Expand All @@ -35,8 +35,8 @@ configure:
deb: true
build:
steps:
- cmd: bash -c "source $HOME/.cargo/env && make build-release"
- cmd: bash -c "source $HOME/.cargo/env && cd LACT && make build-release"
install:
steps:
- cmd: bash -c "cd $PKGER_BLD_DIR && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"
- cmd: bash -c "cd $PKGER_BLD_DIR/LACT && DESTDIR=$PKGER_OUT_DIR PREFIX=/usr make install"

0 comments on commit d99cfdf

Please sign in to comment.