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

populate SMBIOS system version with Git metadata #702

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ tracing-bunyan-formatter = "0.3.3"
tracing-subscriber = "0.3.14"
usdt = { version = "0.5", default-features = false }
uuid = "1.3.2"
vergen = { version = "8.0.0", features = ["git", "gitcl"]}
2 changes: 1 addition & 1 deletion bin/propolis-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use propolis_server::{
};

#[derive(Debug, Parser)]
#[clap(about, version)]
#[clap(about, version = propolis::version())]
/// An HTTP server providing access to Propolis
enum Args {
/// Generates the OpenAPI specification.
Expand Down
1 change: 1 addition & 0 deletions bin/propolis-standalone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ fn api_version_checks(log: &slog::Logger) -> std::io::Result<()> {
}

#[derive(clap::Parser)]
#[clap(version = propolis::version())]
/// Propolis command-line frontend for running a VM.
struct Args {
/// Either the VM config file or a previously captured snapshot image.
Expand Down
4 changes: 4 additions & 0 deletions lib/propolis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ rand = { workspace = true, optional = true }
softnpu-lib = { workspace = true, optional = true }
dlpi = { workspace = true, optional = true }

[build-dependencies]
anyhow.workspace = true
vergen.workspace = true

[dev-dependencies]
crossbeam-channel.workspace = true
tempfile.workspace = true
Expand Down
16 changes: 16 additions & 0 deletions lib/propolis/build.rs
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(())
}
18 changes: 17 additions & 1 deletion lib/propolis/src/firmware/smbios/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub mod type0 {
BiosExtCharacteristics => u16,
}
}
#[derive(Default)]

pub struct Type1 {
pub manufacturer: SmbString,
pub product_name: SmbString,
Expand Down Expand Up @@ -381,6 +381,22 @@ impl Table for Type1 {
}
}

impl Default for Type1 {
fn default() -> Self {
Type1 {
manufacturer: SmbString::default(),
product_name: SmbString::default(),
version: SmbString::try_from(crate::version())
.expect("version string should not contain NULs"),
Copy link
Collaborator

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

serial_number: SmbString::default(),
uuid: [0; 16],
wake_up_type: type1::WakeUpType::default(),
sku_number: SmbString::default(),
family: SmbString::default(),
}
}
}

pub mod type1 {
use super::*;

Expand Down
43 changes: 43 additions & 0 deletions lib/propolis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,46 @@ 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!("Propolis v{}", env!("CARGO_PKG_VERSION"));
hawkw marked this conversation as resolved.
Show resolved Hide resolved
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}")
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: bhyve should not be capitalized

.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!("version: {v}");
assert!(v.starts_with("Propolis v"));
}
}
Loading