Skip to content

Commit 6616d1b

Browse files
Desktop: Add commit info to binaries build with Nix (#3635)
1 parent 39849c9 commit 6616d1b

5 files changed

Lines changed: 33 additions & 19 deletions

File tree

.nix/pkgs/graphite.nix

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,20 @@ deps.crane.lib.buildPackage (
109109
}
110110
else
111111
{ }
112-
);
112+
) // {
113+
GRAPHITE_GIT_COMMIT_HASH = inputs.self.rev or "unknown";
114+
GRAPHITE_GIT_COMMIT_DATE = inputs.self.lastModified or "unknown";
115+
};
113116

114117
postUnpack = ''
115118
mkdir ./branding
116119
cp -r ${branding}/* ./branding
117120
'';
118121

122+
preBuild = if inputs.self ? rev then ''
123+
export GRAPHITE_GIT_COMMIT_DATE="$(date -u -d "@$GRAPHITE_GIT_COMMIT_DATE" +"%Y-%m-%dT%H:%M:%SZ")"
124+
'' else "";
125+
119126
installPhase = ''
120127
mkdir -p $out/bin
121128
cp target/${if dev then "debug" else "release"}/graphite $out/bin/graphite
@@ -125,6 +132,12 @@ deps.crane.lib.buildPackage (
125132
126133
mkdir -p $out/share/icons/hicolor/scalable/apps
127134
cp ${branding}/app-icons/graphite.svg $out/share/icons/hicolor/scalable/apps/art.graphite.Graphite.svg
135+
mkdir -p $out/share/icons/hicolor/512x512/apps
136+
cp ${branding}/app-icons/graphite-512.png $out/share/icons/hicolor/512x512/apps/art.graphite.Graphite.png
137+
mkdir -p $out/share/icons/hicolor/256x256/apps
138+
cp ${branding}/app-icons/graphite-256.png $out/share/icons/hicolor/256x256/apps/art.graphite.Graphite.png
139+
mkdir -p $out/share/icons/hicolor/128x128/apps
140+
cp ${branding}/app-icons/graphite-128.png $out/share/icons/hicolor/128x128/apps/art.graphite.Graphite.png
128141
'';
129142

130143
postFixup = ''

editor/build.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ fn main() {
1818
if !gh.trim().is_empty() {
1919
gh.trim().to_string()
2020
} else {
21-
git_or_unknown(&["rev-parse", "--abbrev-ref", "HEAD"])
21+
git(&["rev-parse", "--abbrev-ref", "HEAD"]).unwrap_or_default()
2222
}
2323
});
2424

2525
// Instruct Cargo to set environment variables for compile time.
2626
// They are accessed with the `env!("GRAPHITE_*")` macro in the codebase.
27-
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={commit_date}");
28-
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={commit_hash}");
29-
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={commit_branch}");
3027
println!("cargo:rustc-env=GRAPHITE_RELEASE_SERIES={GRAPHITE_RELEASE_SERIES}");
28+
if !commit_branch.is_empty() {
29+
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={commit_branch}");
30+
}
31+
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={commit_hash}");
32+
println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={commit_date}");
3133
}
3234

3335
/// Get an environment variable, or if it is not set or empty, use the provided fallback function. Returns a string with trimmed whitespace.

editor/src/application.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,17 @@ impl Default for Editor {
3939
}
4040

4141
pub const GRAPHITE_RELEASE_SERIES: &str = env!("GRAPHITE_RELEASE_SERIES");
42-
pub const GRAPHITE_GIT_COMMIT_DATE: &str = env!("GRAPHITE_GIT_COMMIT_DATE");
42+
pub const GRAPHITE_GIT_COMMIT_BRANCH: Option<&str> = option_env!("GRAPHITE_GIT_COMMIT_BRANCH");
4343
pub const GRAPHITE_GIT_COMMIT_HASH: &str = env!("GRAPHITE_GIT_COMMIT_HASH");
44-
pub const GRAPHITE_GIT_COMMIT_BRANCH: &str = env!("GRAPHITE_GIT_COMMIT_BRANCH");
44+
pub const GRAPHITE_GIT_COMMIT_DATE: &str = env!("GRAPHITE_GIT_COMMIT_DATE");
4545

4646
pub fn commit_info_localized(localized_commit_date: &str) -> String {
47-
format!(
48-
"Release Series: {}\n\
49-
Branch: {}\n\
50-
Commit: {}\n\
51-
{}",
52-
GRAPHITE_RELEASE_SERIES,
53-
GRAPHITE_GIT_COMMIT_BRANCH,
54-
GRAPHITE_GIT_COMMIT_HASH.get(..8).unwrap_or(GRAPHITE_GIT_COMMIT_HASH),
55-
localized_commit_date
56-
)
47+
let mut info = String::new();
48+
info.push_str(&format!("Release Series: {GRAPHITE_RELEASE_SERIES}\n"));
49+
if let Some(branch) = GRAPHITE_GIT_COMMIT_BRANCH {
50+
info.push_str(&format!("Branch: {branch}\n"));
51+
}
52+
info.push_str(&format!("Commit: {}\n", GRAPHITE_GIT_COMMIT_HASH.get(..8).unwrap_or(GRAPHITE_GIT_COMMIT_HASH)));
53+
info.push_str(localized_commit_date);
54+
info
5755
}

editor/src/messages/dialog/dialog_message_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::simple_dialogs::{self, AboutGraphiteDialog, DemoArtworkDialog, LicensesDialog};
2+
use crate::application::GRAPHITE_GIT_COMMIT_DATE;
23
use crate::messages::dialog::simple_dialogs::LicensesThirdPartyDialog;
34
use crate::messages::layout::utility_types::widget_prelude::*;
45
use crate::messages::prelude::*;
@@ -48,7 +49,7 @@ impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHa
4849
}
4950
DialogMessage::RequestAboutGraphiteDialog => {
5051
responses.add(FrontendMessage::TriggerAboutGraphiteLocalizedCommitDate {
51-
commit_date: env!("GRAPHITE_GIT_COMMIT_DATE").into(),
52+
commit_date: GRAPHITE_GIT_COMMIT_DATE.into(),
5253
});
5354
}
5455
DialogMessage::RequestAboutGraphiteDialogWithLocalizedCommitDate {

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
964964
}
965965
PortfolioMessage::RequestStatusBarInfoLayout => {
966966
#[cfg(not(target_family = "wasm"))]
967-
let widgets = vec![TextLabel::new("Graphite (beta) 1.0.0-RC2").disabled(true).widget_instance()];
967+
let widgets = vec![TextLabel::new("Graphite 1.0.0-RC2").disabled(true).widget_instance()];
968968
#[cfg(target_family = "wasm")]
969969
let widgets = vec![];
970970

0 commit comments

Comments
 (0)