Skip to content

Commit 69e6910

Browse files
authored
Add build SHA to panic reports and zed --version (on nightly/dev) (#24258)
Release Notes: - N/A
1 parent f08b1d7 commit 69e6910

File tree

8 files changed

+76
-33
lines changed

8 files changed

+76
-33
lines changed

crates/cli/build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::process::Command;
2+
13
fn main() {
24
if std::env::var("ZED_UPDATE_EXPLANATION").is_ok() {
35
println!(r#"cargo:rustc-cfg=feature="no-bundled-uninstall""#);
@@ -8,4 +10,18 @@ fn main() {
810
// Weakly link ScreenCaptureKit to ensure can be used on macOS 10.15+.
911
println!("cargo:rustc-link-arg=-Wl,-weak_framework,ScreenCaptureKit");
1012
}
13+
14+
// Populate git sha environment variable if git is available
15+
println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
16+
if let Some(output) = Command::new("git")
17+
.args(["rev-parse", "HEAD"])
18+
.output()
19+
.ok()
20+
.filter(|output| output.status.success())
21+
{
22+
let git_sha = String::from_utf8_lossy(&output.stdout);
23+
let git_sha = git_sha.trim();
24+
25+
println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
26+
}
1127
}

crates/cli/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,17 @@ mod linux {
339339
impl InstalledApp for App {
340340
fn zed_version_string(&self) -> String {
341341
format!(
342-
"Zed {}{} – {}",
342+
"Zed {}{}{} – {}",
343343
if *RELEASE_CHANNEL == "stable" {
344344
"".to_string()
345345
} else {
346346
format!("{} ", *RELEASE_CHANNEL)
347347
},
348348
option_env!("RELEASE_VERSION").unwrap_or_default(),
349+
match option_env!("ZED_COMMIT_SHA") {
350+
Some(commit_sha) => format!(" {commit_sha} "),
351+
None => "".to_string(),
352+
},
349353
self.0.display(),
350354
)
351355
}

crates/remote_server/build.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,17 @@ fn main() {
1414
std::env::var("TARGET").unwrap()
1515
);
1616

17-
// If we're building this for nightly, we want to set the ZED_COMMIT_SHA
18-
if let Some(release_channel) = std::env::var("ZED_RELEASE_CHANNEL").ok() {
19-
if release_channel.as_str() == "nightly" {
20-
// Populate git sha environment variable if git is available
21-
println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
22-
if let Some(output) = Command::new("git")
23-
.args(["rev-parse", "HEAD"])
24-
.output()
25-
.ok()
26-
.filter(|output| output.status.success())
27-
{
28-
let git_sha = String::from_utf8_lossy(&output.stdout);
29-
let git_sha = git_sha.trim();
17+
// Populate git sha environment variable if git is available
18+
println!("cargo:rerun-if-changed=../../.git/logs/HEAD");
19+
if let Some(output) = Command::new("git")
20+
.args(["rev-parse", "HEAD"])
21+
.output()
22+
.ok()
23+
.filter(|output| output.status.success())
24+
{
25+
let git_sha = String::from_utf8_lossy(&output.stdout);
26+
let git_sha = git_sha.trim();
3027

31-
println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
32-
}
33-
}
28+
println!("cargo:rustc-env=ZED_COMMIT_SHA={git_sha}");
3429
}
3530
}

crates/remote_server/src/main.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn main() {
4040

4141
#[cfg(not(windows))]
4242
fn main() {
43+
use release_channel::{ReleaseChannel, RELEASE_CHANNEL};
4344
use remote::proxy::ProxyLaunchError;
4445
use remote_server::unix::{execute_proxy, execute_run};
4546

@@ -72,12 +73,15 @@ fn main() {
7273
}
7374
},
7475
Some(Commands::Version) => {
75-
if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") {
76-
println!("{}", build_sha);
77-
} else {
78-
println!("{}", env!("ZED_PKG_VERSION"));
79-
}
80-
76+
let release_channel = *RELEASE_CHANNEL;
77+
match release_channel {
78+
ReleaseChannel::Stable | ReleaseChannel::Preview => {
79+
println!("{}", env!("ZED_PKG_VERSION"))
80+
}
81+
ReleaseChannel::Nightly | ReleaseChannel::Dev => {
82+
println!("{}", env!("ZED_COMMIT_SHA"))
83+
}
84+
};
8185
std::process::exit(0);
8286
}
8387
None => {

crates/remote_server/src/unix.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use node_runtime::{NodeBinaryOptions, NodeRuntime};
1616
use paths::logs_dir;
1717
use project::project_settings::ProjectSettings;
1818

19-
use release_channel::AppVersion;
19+
use release_channel::{AppVersion, ReleaseChannel, RELEASE_CHANNEL};
2020
use remote::proxy::ProxyLaunchError;
2121
use remote::ssh_session::ChannelClient;
2222
use remote::{
@@ -149,18 +149,24 @@ fn init_panic_hook() {
149149
(&backtrace).join("\n")
150150
);
151151

152+
let release_channel = *RELEASE_CHANNEL;
153+
let version = match release_channel {
154+
ReleaseChannel::Stable | ReleaseChannel::Preview => env!("ZED_PKG_VERSION"),
155+
ReleaseChannel::Nightly | ReleaseChannel::Dev => {
156+
option_env!("ZED_COMMIT_SHA").unwrap_or("missing-zed-commit-sha")
157+
}
158+
};
159+
152160
let panic_data = telemetry_events::Panic {
153161
thread: thread_name.into(),
154162
payload: payload.clone(),
155163
location_data: info.location().map(|location| LocationData {
156164
file: location.file().into(),
157165
line: location.line(),
158166
}),
159-
app_version: format!(
160-
"remote-server-{}",
161-
option_env!("ZED_COMMIT_SHA").unwrap_or(&env!("ZED_PKG_VERSION"))
162-
),
163-
release_channel: release_channel::RELEASE_CHANNEL.display_name().into(),
167+
app_version: format!("remote-server-{version}"),
168+
app_commit_sha: option_env!("ZED_COMMIT_SHA").map(|sha| sha.into()),
169+
release_channel: release_channel.display_name().into(),
164170
target: env!("TARGET").to_owned().into(),
165171
os_name: telemetry::os_name(),
166172
os_version: Some(telemetry::os_version()),

crates/telemetry_events/src/telemetry_events.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ pub struct Panic {
267267
pub backtrace: Vec<String>,
268268
/// Zed version number
269269
pub app_version: String,
270+
/// The Git commit SHA that Zed was built at.
271+
#[serde(skip_serializing_if = "Option::is_none")]
272+
pub app_commit_sha: Option<String>,
270273
/// Zed release channel (stable, preview, dev)
271274
pub release_channel: String,
272275
pub target: Option<String>,

crates/zed/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,12 @@ fn main() {
188188
let session_id = Uuid::new_v4().to_string();
189189
let session = app.background_executor().block(Session::new());
190190
let app_version = AppVersion::init(env!("CARGO_PKG_VERSION"));
191+
let app_commit_sha =
192+
option_env!("ZED_COMMIT_SHA").map(|commit_sha| AppCommitSha(commit_sha.to_string()));
191193

192194
reliability::init_panic_hook(
193195
app_version,
196+
app_commit_sha.clone(),
194197
system_id.as_ref().map(|id| id.to_string()),
195198
installation_id.as_ref().map(|id| id.to_string()),
196199
session_id.clone(),
@@ -281,8 +284,8 @@ fn main() {
281284
app.run(move |cx| {
282285
release_channel::init(app_version, cx);
283286
gpui_tokio::init(cx);
284-
if let Some(build_sha) = option_env!("ZED_COMMIT_SHA") {
285-
AppCommitSha::set_global(AppCommitSha(build_sha.into()), cx);
287+
if let Some(app_commit_sha) = app_commit_sha {
288+
AppCommitSha::set_global(app_commit_sha, cx);
286289
}
287290
settings::init(cx);
288291
handle_settings_file_changes(user_settings_file_rx, cx, handle_settings_changed);

crates/zed/src/reliability.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use gpui::{App, SemanticVersion};
88
use http_client::{self, HttpClient, HttpClientWithUrl, HttpRequestExt, Method};
99
use paths::{crashes_dir, crashes_retired_dir};
1010
use project::Project;
11-
use release_channel::{ReleaseChannel, RELEASE_CHANNEL};
11+
use release_channel::{AppCommitSha, ReleaseChannel, RELEASE_CHANNEL};
1212
use settings::Settings;
1313
use smol::stream::StreamExt;
1414
use std::{
@@ -25,6 +25,7 @@ static PANIC_COUNT: AtomicU32 = AtomicU32::new(0);
2525

2626
pub fn init_panic_hook(
2727
app_version: SemanticVersion,
28+
app_commit_sha: Option<AppCommitSha>,
2829
system_id: Option<String>,
2930
installation_id: Option<String>,
3031
session_id: String,
@@ -54,12 +55,22 @@ pub fn init_panic_hook(
5455
let location = info.location().unwrap();
5556
let backtrace = Backtrace::new();
5657
eprintln!(
57-
"Thread {:?} panicked with {:?} at {}:{}:{}\n{:?}",
58+
"Thread {:?} panicked with {:?} at {}:{}:{}\n{}{:?}",
5859
thread_name,
5960
payload,
6061
location.file(),
6162
location.line(),
6263
location.column(),
64+
match app_commit_sha.as_ref() {
65+
Some(commit_sha) => format!(
66+
"https://github.com/zed-industries/zed/blob/{}/src/{}#L{} \
67+
(may not be uploaded, line may be incorrect if files modified)\n",
68+
commit_sha.0,
69+
location.file(),
70+
location.line()
71+
),
72+
None => "".to_string(),
73+
},
6374
backtrace,
6475
);
6576
std::process::exit(-1);
@@ -103,6 +114,7 @@ pub fn init_panic_hook(
103114
line: location.line(),
104115
}),
105116
app_version: app_version.to_string(),
117+
app_commit_sha: app_commit_sha.as_ref().map(|sha| sha.0.clone()),
106118
release_channel: RELEASE_CHANNEL.dev_name().into(),
107119
target: env!("TARGET").to_owned().into(),
108120
os_name: telemetry::os_name(),

0 commit comments

Comments
 (0)