Desktop: Add commit info to binaries build with Nix (#3635)

This commit is contained in:
Timon 2026-01-15 11:34:01 +01:00 committed by GitHub
parent 39849c9c02
commit 6616d1bfb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 33 additions and 19 deletions

View File

@ -109,13 +109,20 @@ deps.crane.lib.buildPackage (
} }
else else
{ } { }
); ) // {
GRAPHITE_GIT_COMMIT_HASH = inputs.self.rev or "unknown";
GRAPHITE_GIT_COMMIT_DATE = inputs.self.lastModified or "unknown";
};
postUnpack = '' postUnpack = ''
mkdir ./branding mkdir ./branding
cp -r ${branding}/* ./branding cp -r ${branding}/* ./branding
''; '';
preBuild = if inputs.self ? rev then ''
export GRAPHITE_GIT_COMMIT_DATE="$(date -u -d "@$GRAPHITE_GIT_COMMIT_DATE" +"%Y-%m-%dT%H:%M:%SZ")"
'' else "";
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp target/${if dev then "debug" else "release"}/graphite $out/bin/graphite cp target/${if dev then "debug" else "release"}/graphite $out/bin/graphite
@ -125,6 +132,12 @@ deps.crane.lib.buildPackage (
mkdir -p $out/share/icons/hicolor/scalable/apps mkdir -p $out/share/icons/hicolor/scalable/apps
cp ${branding}/app-icons/graphite.svg $out/share/icons/hicolor/scalable/apps/art.graphite.Graphite.svg cp ${branding}/app-icons/graphite.svg $out/share/icons/hicolor/scalable/apps/art.graphite.Graphite.svg
mkdir -p $out/share/icons/hicolor/512x512/apps
cp ${branding}/app-icons/graphite-512.png $out/share/icons/hicolor/512x512/apps/art.graphite.Graphite.png
mkdir -p $out/share/icons/hicolor/256x256/apps
cp ${branding}/app-icons/graphite-256.png $out/share/icons/hicolor/256x256/apps/art.graphite.Graphite.png
mkdir -p $out/share/icons/hicolor/128x128/apps
cp ${branding}/app-icons/graphite-128.png $out/share/icons/hicolor/128x128/apps/art.graphite.Graphite.png
''; '';
postFixup = '' postFixup = ''

View File

@ -18,16 +18,18 @@ fn main() {
if !gh.trim().is_empty() { if !gh.trim().is_empty() {
gh.trim().to_string() gh.trim().to_string()
} else { } else {
git_or_unknown(&["rev-parse", "--abbrev-ref", "HEAD"]) git(&["rev-parse", "--abbrev-ref", "HEAD"]).unwrap_or_default()
} }
}); });
// Instruct Cargo to set environment variables for compile time. // Instruct Cargo to set environment variables for compile time.
// They are accessed with the `env!("GRAPHITE_*")` macro in the codebase. // They are accessed with the `env!("GRAPHITE_*")` macro in the codebase.
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={commit_date}");
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={commit_hash}");
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={commit_branch}");
println!("cargo:rustc-env=GRAPHITE_RELEASE_SERIES={GRAPHITE_RELEASE_SERIES}"); println!("cargo:rustc-env=GRAPHITE_RELEASE_SERIES={GRAPHITE_RELEASE_SERIES}");
if !commit_branch.is_empty() {
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={commit_branch}");
}
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={commit_hash}");
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={commit_date}");
} }
/// Get an environment variable, or if it is not set or empty, use the provided fallback function. Returns a string with trimmed whitespace. /// Get an environment variable, or if it is not set or empty, use the provided fallback function. Returns a string with trimmed whitespace.

View File

@ -39,19 +39,17 @@ impl Default for Editor {
} }
pub const GRAPHITE_RELEASE_SERIES: &str = env!("GRAPHITE_RELEASE_SERIES"); pub const GRAPHITE_RELEASE_SERIES: &str = env!("GRAPHITE_RELEASE_SERIES");
pub const GRAPHITE_GIT_COMMIT_DATE: &str = env!("GRAPHITE_GIT_COMMIT_DATE"); pub const GRAPHITE_GIT_COMMIT_BRANCH: Option<&str> = option_env!("GRAPHITE_GIT_COMMIT_BRANCH");
pub const GRAPHITE_GIT_COMMIT_HASH: &str = env!("GRAPHITE_GIT_COMMIT_HASH"); pub const GRAPHITE_GIT_COMMIT_HASH: &str = env!("GRAPHITE_GIT_COMMIT_HASH");
pub const GRAPHITE_GIT_COMMIT_BRANCH: &str = env!("GRAPHITE_GIT_COMMIT_BRANCH"); pub const GRAPHITE_GIT_COMMIT_DATE: &str = env!("GRAPHITE_GIT_COMMIT_DATE");
pub fn commit_info_localized(localized_commit_date: &str) -> String { pub fn commit_info_localized(localized_commit_date: &str) -> String {
format!( let mut info = String::new();
"Release Series: {}\n\ info.push_str(&format!("Release Series: {GRAPHITE_RELEASE_SERIES}\n"));
Branch: {}\n\ if let Some(branch) = GRAPHITE_GIT_COMMIT_BRANCH {
Commit: {}\n\ info.push_str(&format!("Branch: {branch}\n"));
{}", }
GRAPHITE_RELEASE_SERIES, info.push_str(&format!("Commit: {}\n", GRAPHITE_GIT_COMMIT_HASH.get(..8).unwrap_or(GRAPHITE_GIT_COMMIT_HASH)));
GRAPHITE_GIT_COMMIT_BRANCH, info.push_str(localized_commit_date);
GRAPHITE_GIT_COMMIT_HASH.get(..8).unwrap_or(GRAPHITE_GIT_COMMIT_HASH), info
localized_commit_date
)
} }

View File

@ -1,4 +1,5 @@
use super::simple_dialogs::{self, AboutGraphiteDialog, DemoArtworkDialog, LicensesDialog}; use super::simple_dialogs::{self, AboutGraphiteDialog, DemoArtworkDialog, LicensesDialog};
use crate::application::GRAPHITE_GIT_COMMIT_DATE;
use crate::messages::dialog::simple_dialogs::LicensesThirdPartyDialog; use crate::messages::dialog::simple_dialogs::LicensesThirdPartyDialog;
use crate::messages::layout::utility_types::widget_prelude::*; use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::prelude::*; use crate::messages::prelude::*;
@ -48,7 +49,7 @@ impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHa
} }
DialogMessage::RequestAboutGraphiteDialog => { DialogMessage::RequestAboutGraphiteDialog => {
responses.add(FrontendMessage::TriggerAboutGraphiteLocalizedCommitDate { responses.add(FrontendMessage::TriggerAboutGraphiteLocalizedCommitDate {
commit_date: env!("GRAPHITE_GIT_COMMIT_DATE").into(), commit_date: GRAPHITE_GIT_COMMIT_DATE.into(),
}); });
} }
DialogMessage::RequestAboutGraphiteDialogWithLocalizedCommitDate { DialogMessage::RequestAboutGraphiteDialogWithLocalizedCommitDate {

View File

@ -964,7 +964,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
} }
PortfolioMessage::RequestStatusBarInfoLayout => { PortfolioMessage::RequestStatusBarInfoLayout => {
#[cfg(not(target_family = "wasm"))] #[cfg(not(target_family = "wasm"))]
let widgets = vec![TextLabel::new("Graphite (beta) 1.0.0-RC2").disabled(true).widget_instance()]; let widgets = vec![TextLabel::new("Graphite 1.0.0-RC2").disabled(true).widget_instance()];
#[cfg(target_family = "wasm")] #[cfg(target_family = "wasm")]
let widgets = vec![]; let widgets = vec![];