-
Notifications
You must be signed in to change notification settings - Fork 22
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
populate SMBIOS system version with Git metadata #702
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
fn main() -> anyhow::Result<()> { | ||
// Generate Git version information. | ||
vergen::EmitBuilder::builder() | ||
// Don't emit timestamps and build info. | ||
.idempotent() | ||
.git_branch() | ||
.git_sha(true) | ||
.git_commit_count() | ||
.emit()?; | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,47 @@ pub mod vmm; | |
|
||
pub use exits::{VmEntry, VmExit}; | ||
pub use vmm::Machine; | ||
|
||
pub fn version() -> &'static str { | ||
lazy_static::lazy_static! { | ||
static ref VERSION: String = { | ||
use std::fmt::Write; | ||
|
||
let git = option_env!("VERGEN_GIT_BRANCH") | ||
.and_then(|branch| Some((branch, option_env!("VERGEN_GIT_SHA")?))) | ||
.and_then(|(branch, sha)| Some((branch, sha, option_env!("VERGEN_GIT_COMMIT_COUNT")?))); | ||
|
||
let mut version = format!("v{}", env!("CARGO_PKG_VERSION")); | ||
if let Some((branch, sha, commit)) = git { | ||
write!(version, "-{commit} ({sha}) {branch}, ") | ||
.expect("writing to a string never fails"); | ||
} else { | ||
version.push_str(" <unknown git commit>, "); | ||
} | ||
match bhyve_api::api_version() { | ||
Ok(v) => { | ||
write!(version, "Bhyve API v{v}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With everything else in the version being fixed at compile time, do we want to include runtime data (the bhyve api version) in the string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to remove it if you think that's better --- it would certainly make this code much simpler! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
.expect("writing to a string never fails"); | ||
} | ||
Err(_) => { | ||
version.push_str("<unknown Bhyve API version>"); | ||
} | ||
} | ||
version | ||
}; | ||
}; | ||
&VERSION | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn print_version() { | ||
let v = version(); | ||
eprintln!("propolis {v}"); | ||
assert!(version.contains(env!("CARGO_PKG_VERSION"))); | ||
assert!(version.contains("Bhyve API")); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove the bhyve API version from the string, we could include this condition as part of the
version()
unit tests