Skip to content

fix: cmake version#10

Merged
robert-burger merged 1 commit intorobert-burger:masterfrom
marcfir:master
Aug 11, 2025
Merged

fix: cmake version#10
robert-burger merged 1 commit intorobert-burger:masterfrom
marcfir:master

Conversation

@marcfir
Copy link
Contributor

@marcfir marcfir commented Aug 1, 2025

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @marcfir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the CMake build system to change how the project version is determined. Instead of reading a version from a project.properties file, it now dynamically fetches the version from Git tags, providing a more robust and automated versioning mechanism. This change ensures that the project's version is always up-to-date with the latest Git tag, with a fallback for cases where no tag is found.

Highlights

  • Dynamic Versioning: The project version is now dynamically retrieved using git describe --tags --abbrev=0, which pulls the latest tag as the version, replacing the static read from project.properties.
  • Version Fallback: A fallback mechanism has been added to set the project version to "0.0.0" if git describe does not return a valid version, ensuring a default is always available.
  • Consistent Version Usage: The LIBOSAL_PACKAGE_VERSION and LIBOSAL_VERSION variables are updated to consistently use the newly derived Git version, ensuring all version references are aligned.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the CMake build system to derive the project version from git tags instead of a project.properties file. My review focuses on improving the robustness of this new versioning mechanism. I've identified two high-severity issues. First, the git command execution and version parsing logic is fragile and can fail silently or produce incorrect versions. Second, the raw git output is used to set some version variables, which can be empty on failure, leading to an empty version in the build. I've provided suggestions to handle errors gracefully, use a more accurate regular expression for parsing, and consistently use the sanitized version string which has a proper fallback.

Comment on lines +2 to +11
execute_process(
COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VER
)
string(REGEX MATCH "([0-9]*.[0-9]*.[0-9]*).*" _ ${GIT_VER})
set(PROJECT_VERSION ${CMAKE_MATCH_1})
if("${PROJECT_VERSION}" STREQUAL "")
set(PROJECT_VERSION 0.0.0)
endif()

Choose a reason for hiding this comment

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

high

The current method of getting the version from git is not fully robust.

  1. The execute_process call doesn't check if the git command was successful. This can happen if git is not installed or if this is not a git repository (e.g., a source archive).
  2. The regex ([0-9]*.[0-9]*.[0-9]*).* is incorrect. The . matches any character, not a literal dot, and * allows empty version components. It also doesn't handle common v prefixes in tags.

I suggest a more robust implementation that handles git command failures and uses a more accurate regex. This will also make the fallback to 0.0.0 more explicit.

execute_process(
    COMMAND git describe --tags --abbrev=0
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    OUTPUT_VARIABLE GIT_VER
    RESULT_VARIABLE GIT_RESULT
    ERROR_QUIET
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(GIT_RESULT EQUAL 0)
    string(REGEX MATCH "v?([0-9]+\\.[0-9]+\\.[0-9]+)" _ ${GIT_VER})
    set(PROJECT_VERSION ${CMAKE_MATCH_1})
endif()

if(NOT PROJECT_VERSION)
    set(PROJECT_VERSION 0.0.0)
endif()

Comment on lines +103 to +104
set(LIBOSAL_PACKAGE_VERSION "${GIT_VER}")
set(LIBOSAL_VERSION "${GIT_VER}")

Choose a reason for hiding this comment

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

high

Using ${GIT_VER} directly here is risky because it can be empty if the git describe command fails (e.g., not a git repo, or no tags). This would result in an empty version string for LIBOSAL_PACKAGE_VERSION and LIBOSAL_VERSION.

It's safer to use ${PROJECT_VERSION}, which is guaranteed to have a fallback value (e.g., 0.0.0) from the logic above. If you intend to keep the v prefix from the git tag, a more robust approach should be taken to construct a version variable with a proper fallback.

set(LIBOSAL_PACKAGE_VERSION "${PROJECT_VERSION}")
set(LIBOSAL_VERSION "${PROJECT_VERSION}")

@robert-burger
Copy link
Owner

hi marc,

thanks for the pr. can you just have a look at the proposed changes from the gemini-code-assist? i'm not the cmake expert but i think they make sense.

@taotieren
Copy link
Contributor

There is another simple way to handle the configuration file not found issue

echo "VERSION = ${tagver}" >project.properties

@robert-burger robert-burger merged commit 917203c into robert-burger:master Aug 11, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants