diff --git a/crates/util/src/channel.rs b/crates/util/src/channel.rs index 7e60b5e15f64baa12dc0a82572df75d6468f0987..55f13df0846ff1b9c9396a28826ae488ce074304 100644 --- a/crates/util/src/channel.rs +++ b/crates/util/src/channel.rs @@ -1,6 +1,5 @@ -use std::env; - use lazy_static::lazy_static; +use std::env; lazy_static! { pub static ref RELEASE_CHANNEL_NAME: String = if cfg!(debug_assertions) { @@ -18,6 +17,8 @@ lazy_static! { }; } +pub struct AppCommitSha(pub String); + #[derive(Copy, Clone, PartialEq, Eq, Default)] pub enum ReleaseChannel { #[default] @@ -40,7 +41,6 @@ impl ReleaseChannel { pub fn dev_name(&self) -> &'static str { match self { ReleaseChannel::Dev => "dev", - // TODO kb need to add DB data ReleaseChannel::Nightly => "nightly", ReleaseChannel::Preview => "preview", ReleaseChannel::Stable => "stable", @@ -69,7 +69,6 @@ impl ReleaseChannel { pub fn release_query_param(&self) -> Option<&'static str> { match self { Self::Dev => None, - // TODO kb need to add server handling Self::Nightly => Some("nightly=1"), Self::Preview => Some("preview=1"), Self::Stable => None, diff --git a/crates/zed2/build.rs b/crates/zed2/build.rs index 14bf9999fb725c6dae32bfc46341560b662f3d8b..619f2480298b5a4ee7c9a9798b6f12aac6458fb5 100644 --- a/crates/zed2/build.rs +++ b/crates/zed2/build.rs @@ -1,3 +1,5 @@ +use std::process::Command; + fn main() { println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.15.7"); @@ -21,4 +23,14 @@ fn main() { // Register exported Objective-C selectors, protocols, etc println!("cargo:rustc-link-arg=-Wl,-ObjC"); + + // Populate git sha environment variable if git is available + if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() { + if output.status.success() { + println!( + "cargo:rustc-env=ZED_COMMIT_SHA={}", + String::from_utf8_lossy(&output.stdout).trim() + ); + } + } } diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 700660a9b7e69b30cd28366cda2b7d2a325162a1..5206514dfefc1fb72ec4b27f2eed083478402b96 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -43,7 +43,7 @@ use std::{ use theme::ActiveTheme; use util::{ async_maybe, - channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL}, + channel::{parse_zed_link, AppCommitSha, ReleaseChannel, RELEASE_CHANNEL}, http::{self, HttpClient}, paths, ResultExt, }; @@ -113,6 +113,10 @@ fn main() { app.run(move |cx| { cx.set_global(*RELEASE_CHANNEL); + if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") { + cx.set_global(AppCommitSha(build_sha.into())) + } + cx.set_global(listener.clone()); load_embedded_fonts(cx); diff --git a/crates/zed2/src/zed2.rs b/crates/zed2/src/zed2.rs index 84cacccb5adb597b4b5fcd7650e11681b5ab7216..e2e113c9b0fe469278d5fe113d2eb15be2dc3d1f 100644 --- a/crates/zed2/src/zed2.rs +++ b/crates/zed2/src/zed2.rs @@ -23,7 +23,7 @@ use std::{borrow::Cow, ops::Deref, sync::Arc}; use terminal_view::terminal_panel::TerminalPanel; use util::{ asset_str, - channel::ReleaseChannel, + channel::{AppCommitSha, ReleaseChannel}, paths::{self, LOCAL_SETTINGS_RELATIVE_PATH}, ResultExt, }; @@ -432,9 +432,16 @@ pub fn initialize_workspace(app_state: Arc, cx: &mut AppContext) { } fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext) { + use std::fmt::Write as _; + let app_name = cx.global::().display_name(); let version = env!("CARGO_PKG_VERSION"); - let prompt = cx.prompt(PromptLevel::Info, &format!("{app_name} {version}"), &["OK"]); + let mut message = format!("{app_name} {version}"); + if let Some(sha) = cx.try_global::() { + write!(&mut message, "\n\n{}", sha.0).unwrap(); + } + + let prompt = cx.prompt(PromptLevel::Info, &message, &["OK"]); cx.foreground_executor() .spawn(async { prompt.await.ok();