openvmm: report a version - #4038
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for openvmm --version in openvmm_entry, formatting the reported version as the crate version plus (when available) the git revision captured at build time, while allowing builds from tarballs/vendored sources to succeed without a git repository.
Changes:
- Wire up clap’s
--versionoutput to useCARGO_PKG_VERSIONplus optionalBUILD_GIT_SHA. - Ensure the clap-reported command name is
openvmm(instead of the crate name). - Add unit tests for the version string formatting logic and emit git info from the build script (non-fatal on failure).
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| openvmm/openvmm_entry/src/cli_args.rs | Adds version string formatting, a lazily-initialized version string, sets clap command name/version, and adds unit tests. |
| openvmm/openvmm_entry/Cargo.toml | Adds build_rs_git_info as a build dependency. |
| openvmm/openvmm_entry/build.rs | Emits git metadata in the build script but tolerates missing git/repo. |
| Cargo.lock | Records the new build dependency in the lockfile. |
`openvmm --version` did not exist, so a deployed binary could not identify itself. In practice that leaves hashing the file and comparing it against a build record kept somewhere else, which answers "is this the same binary as before" but never "which revision is this one". A binary that reports its own revision answers it directly, and the answer travels with the file. Wire up clap's version flag and build the string from the crate version plus the git revision, which is what actually distinguishes two builds of the same tree. The revision comes from the existing `build_rs_git_info` helper, already used by build_info, burette and underhill_init. Unlike those, the error is ignored here rather than unwrapped: they are always built inside a checkout, while openvmm is built from release tarballs and vendored sources too, where a missing repository must degrade the version string instead of failing the build. Set the command name explicitly. clap otherwise takes it from the crate, reporting `openvmm_entry`, which is neither the binary name nor what the usage line already prints.
3148a7c to
4d24a01
Compare
|
@benhillis has been working on some version changes as well. |
|
Thanks for doing this. The We are actually in the process of formalizing our version and release process (see draft PR #3989), and we're planning on doing tag-based versioning versus using the crate version. If you're open to dropping the other versioning changes I'd be happy to take the clap fix. |
|
Whatever you want to cherry-pick works for me, so take the clap fix in whatever shape suits #3989. One request for the version work itself, from the development side: could the build carry the git revision somewhere? Tag-based versioning identifies releases well, but during development most builds sit between tags, and several builds share the same nearest tag, so a tag alone cannot tell them apart. Either shape would do the job:
The second may suit you better if you want The practical reason this PR read the revision at build time: we run openvmm builds on test hosts and need to know which binary is actually deployed, and I have the PR reduced to only the clap fix locally and can push that whenever you like, or leave it as it stands if you would rather cherry-pick from it. |
openvmm --versiondid not exist, so a deployed binary could not identify itself. Today the only way to tell which revision a binary came from is to hash it and look that hash up in a record kept somewhere else, which answers "is this the same binary as before" but never "which revision is this one".This wires up clap's version flag and builds the string from the crate version plus the git revision:
The revision comes from the existing
build_rs_git_infohelper, already used by build_info, burette and underhill_init. Unlike those, the error is ignored here rather than unwrapped: they are always built inside a checkout, while openvmm is also built from release tarballs and vendored sources, where a missing repository should degrade the version string rather than fail the build.The command name is set explicitly. clap otherwise takes it from the crate and reports
openvmm_entry, which is neither the binary name nor what the usage line already prints.Every crate in the workspace is at 0.0.0, so the revision currently carries all of the information. The flag gets more useful for free if a real version is ever set.