From d99cfdf3f3cf6a54cbc86da1b34dd6f200eb12ae Mon Sep 17 00:00:00 2001 From: Ilya Zlobintsev Date: Sat, 2 Mar 2024 13:07:23 +0200 Subject: [PATCH] feat: include git commit in version info (#249) * 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 --- Cargo.lock | 82 ++++++++++++++++++++ README.md | 1 + lact-daemon/src/server/system.rs | 3 +- lact-gui/src/app/mod.rs | 5 +- lact-gui/src/app/root_stack/software_page.rs | 8 +- lact-schema/Cargo.toml | 3 + lact-schema/build.rs | 5 ++ lact-schema/src/lib.rs | 3 + pkg/recipes/lact-headless/recipe.yml | 8 +- pkg/recipes/lact-libadwaita/recipe.yml | 8 +- pkg/recipes/lact/recipe.yml | 8 +- 11 files changed, 117 insertions(+), 17 deletions(-) create mode 100644 lact-schema/build.rs diff --git a/Cargo.lock b/Cargo.lock index 25d53a3d..6b3702d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -633,6 +633,15 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7762d17f1241643615821a8455a0b2c3e803784b058693d990b11f2dce25a0ca" +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "derivative" version = "2.2.0" @@ -1383,6 +1392,7 @@ dependencies = [ "serde", "serde_json", "serde_with", + "vergen", ] [[package]] @@ -1605,6 +1615,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-traits" version = "0.2.17" @@ -1614,6 +1630,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_threads" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" +dependencies = [ + "libc", +] + [[package]] name = "objc" version = "0.2.7" @@ -1784,6 +1809,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1998,6 +2029,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.16" @@ -2273,6 +2310,39 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +dependencies = [ + "deranged", + "itoa", + "libc", + "num-conv", + "num_threads", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tokio" version = "1.35.1" @@ -2460,6 +2530,18 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vergen" +version = "8.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" +dependencies = [ + "anyhow", + "cfg-if", + "rustversion", + "time", +] + [[package]] name = "version-compare" version = "0.1.1" diff --git a/README.md b/README.md index e667497a..60ccf48c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lact-daemon/src/server/system.rs b/lact-daemon/src/server/system.rs index 120583e3..4abd5fdf 100644 --- a/lact-daemon/src/server/system.rs +++ b/lact-daemon/src/server/system.rs @@ -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}, @@ -41,6 +41,7 @@ pub fn info() -> anyhow::Result> { profile, kernel_version, amdgpu_overdrive_enabled, + commit: Some(GIT_COMMIT), }) } diff --git a/lact-gui/src/app/mod.rs b/lact-gui/src/app/mod.rs index 9f3d6141..3ff42dd1 100644 --- a/lact-gui/src/app/mod.rs +++ b/lact-gui/src/app/mod.rs @@ -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; @@ -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); } diff --git a/lact-gui/src/app/root_stack/software_page.rs b/lact-gui/src/app/root_stack/software_page.rs index d215524b..74e20d77 100644 --- a/lact-gui/src/app/root_stack/software_page.rs +++ b/lact-gui/src/app/root_stack/software_page.rs @@ -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) @@ -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) diff --git a/lact-schema/Cargo.toml b/lact-schema/Cargo.toml index eb4eb8fb..7c1f9558 100644 --- a/lact-schema/Cargo.toml +++ b/lact-schema/Cargo.toml @@ -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 } diff --git a/lact-schema/build.rs b/lact-schema/build.rs new file mode 100644 index 00000000..221059b2 --- /dev/null +++ b/lact-schema/build.rs @@ -0,0 +1,5 @@ +use vergen::EmitBuilder; + +fn main() { + EmitBuilder::builder().git_sha(true).emit().unwrap() +} diff --git a/lact-schema/src/lib.rs b/lact-schema/src/lib.rs index eb502a5e..604667dd 100644 --- a/lact-schema/src/lib.rs +++ b/lact-schema/src/lib.rs @@ -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 { @@ -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, diff --git a/pkg/recipes/lact-headless/recipe.yml b/pkg/recipes/lact-headless/recipe.yml index 77e2ba7e..e3c6d4d5 100644 --- a/pkg/recipes/lact-headless/recipe.yml +++ b/pkg/recipes/lact-headless/recipe.yml @@ -7,7 +7,7 @@ metadata: maintainer: ilya-zlobintsev url: https://github.com/ilya-zlobintsev/lact source: - - '../../..' + - '../../../../LACT' provides: [ lact ] conflicts: [ lact, lact-libadwaita ] depends: @@ -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 ] @@ -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" diff --git a/pkg/recipes/lact-libadwaita/recipe.yml b/pkg/recipes/lact-libadwaita/recipe.yml index d9640009..9df11772 100644 --- a/pkg/recipes/lact-libadwaita/recipe.yml +++ b/pkg/recipes/lact-libadwaita/recipe.yml @@ -7,7 +7,7 @@ metadata: maintainer: ilya-zlobintsev url: https://github.com/ilya-zlobintsev/lact source: - - '../../..' + - '../../../../LACT' provides: [ lact ] conflicts: [ lact, lact-headless ] depends: @@ -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 ] @@ -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" diff --git a/pkg/recipes/lact/recipe.yml b/pkg/recipes/lact/recipe.yml index a8a15c48..4ee89b9d 100644 --- a/pkg/recipes/lact/recipe.yml +++ b/pkg/recipes/lact/recipe.yml @@ -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: @@ -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 ] @@ -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"