Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop assuming there will always be a git commit #2037

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion zebrad/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ fn main() {
*config.git_mut().semver_mut() = false;
*config.git_mut().sha_kind_mut() = ShaKind::Short;

vergen(config).expect("Unable to generate the cargo keys!");
match vergen(config) {
Ok(_) => {}
Err(e) => eprintln!(
"skipping detailed git and target info due to vergen error: {:?}",
e
),
}
}
51 changes: 34 additions & 17 deletions zebrad/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ impl ZebradApp {
atty::is(atty::Stream::Stdout) && atty::is(atty::Stream::Stderr)
}

pub fn git_commit() -> &'static str {
const GIT_COMMIT_VERGEN: &str = env!("VERGEN_GIT_SHA_SHORT");
/// Returns the git commit for this build, if available.
///
///
/// # Accuracy
///
/// If the user makes changes, but does not commit them, the git commit will
/// not match the compiled source code.
pub fn git_commit() -> Option<&'static str> {
const GIT_COMMIT_GCLOUD: Option<&str> = option_env!("SHORT_SHA");
const GIT_COMMIT_VERGEN: Option<&str> = option_env!("VERGEN_GIT_SHA_SHORT");

GIT_COMMIT_GCLOUD.unwrap_or(GIT_COMMIT_VERGEN)
GIT_COMMIT_GCLOUD.or(GIT_COMMIT_VERGEN)
}
}

Expand Down Expand Up @@ -154,18 +161,26 @@ impl Application for ZebradApp {
color_eyre::config::Theme::new()
};

// collect the common metadata for the issue URL and panic report
let panic_metadata = vec![
// collect the common metadata for the issue URL and panic report,
// skipping any env vars that aren't present
let panic_metadata: Vec<(&'static str, &'static str)> = [
// cargo or git tag + short commit
("version", Some(env!("CARGO_PKG_VERSION"))),
// git
("version", env!("CARGO_PKG_VERSION")),
("branch", env!("VERGEN_GIT_BRANCH")),
("branch", option_env!("VERGEN_GIT_BRANCH")),
("git commit", Self::git_commit()),
("commit timestamp", env!("VERGEN_GIT_COMMIT_TIMESTAMP")),
(
"commit timestamp",
option_env!("VERGEN_GIT_COMMIT_TIMESTAMP"),
),
// build
("target triple", env!("VERGEN_CARGO_TARGET_TRIPLE")),
("target triple", option_env!("VERGEN_CARGO_TARGET_TRIPLE")),
// config
("Zcash network", (&config.network.network).into()),
];
("Zcash network", Some((&config.network.network).into())),
]
.iter()
.filter_map(|(k, opt_v)| Some((*k, *opt_v.as_ref()?)))
.collect();

let mut builder = color_eyre::config::HookBuilder::default();
let mut metadata_section = "Metadata:".to_string();
Expand Down Expand Up @@ -218,7 +233,7 @@ impl Application for ZebradApp {
let guard = sentry::init(
sentry::ClientOptions {
debug: true,
release: Some(Self::git_commit().into()),
release: Self::git_commit().map(Into::into),
..Default::default()
}
.add_integration(sentry_tracing::TracingIntegration::default()),
Expand Down Expand Up @@ -270,11 +285,13 @@ impl Application for ZebradApp {
// Activate the global span, so it's visible when we load the other
// components. Space is at a premium here, so we use an empty message,
// short commit hash, and the unique part of the network name.
let global_span = error_span!(
"",
zebrad = ZebradApp::git_commit(),
net = &self.config.clone().unwrap().network.network.to_string()[..4],
);
let net = &self.config.clone().unwrap().network.network.to_string()[..4];
let global_span = if let Some(git_commit) = ZebradApp::git_commit() {
error_span!("", zebrad = git_commit, net)
} else {
error_span!("", net)
};

let global_guard = global_span.enter();
// leak the global span, to make sure it stays active
std::mem::forget(global_guard);
Expand Down