Fix Git version detection when embedded - #551
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f0e29217d0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The Windows build has been reporting 0.0.0-unknown, for two independent reasons. Both are verified on a real Windows 11 + MSYS2 MINGW64 box. 1. The MSYS2 shell has no git at all. It is not part of base-devel, and the shell does not inherit Git for Windows from the runner PATH (confirmed: no "/Program Files/Git" entry in the MINGW64 PATH). So every git call in CMakeLists.txt failed. Fixed by installing the git package alongside the toolchain. 2. Once git is available, the --show-toplevel guard added in #551 would still reject every Windows build, permanently pinning it to 0.0.0-unknown. MSYS2 git reports POSIX paths while CMake reports Windows ones, and get_filename_component(REALPATH) does not reconcile them: PROJECT_SOURCE_DIR = C:/Users/Denis/hc-vtest/probe/sub git --show-toplevel = /c/Users/Denis/hc-vtest/probe/sub so the STREQUAL can never match. Replaced with --show-prefix, which is empty exactly when the source dir is the root of a work tree. That is a plain string test needing no path normalisation, and it drops both REALPATH calls. Measured on Windows with the same package set as CI: the old guard yields 0.0.0-unknown, the new one yields 4.0.0-11-g00ca695, a vendored copy correctly falls back to 0.0.0-unknown, and build + ctest pass. Both reject paths now explain themselves and point at -DHEADSETCONTROL_VERSION. Also renames the reused GIT_RESULT to GIT_DESCRIBE_RESULT.
What changed
git describefrom the HeadsetControl source directory.git rev-parsefallback from the same directory.Why
When HeadsetControl is included by another project through
add_subdirectory(), the Git commands could execute in the parent repository context. This caused the generated HeadsetControl version to contain the parent project's commit instead of the HeadsetControl revision.Impact
Embedded consumers now receive a version derived from the HeadsetControl repository, while standalone builds keep the existing behavior.
Validation
git diff --checkadd_subdirectory()4.0.0-10-gf0e2921