Skip to content

Conversation

@nordicjm
Copy link
Contributor

Will throw an error showing what the issue with the VERSION file is if a required field is missing

Will throw an error showing what the issue with the VERSION file
is if a required field is missing

Signed-off-by: Jamie McCrae <[email protected]>
@sonarqubecloud
Copy link

Comment on lines +54 to +57
set(${type}_VERSION_MAJOR_LENGTH 0)
set(${type}_VERSION_MINOR_LENGTH 0)
set(${type}_PATCHLEVEL_LENGTH 0)
set(${type}_VERSION_TWEAK_LENGTH 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

why this complexity (also code below) ?

Suggested change
set(${type}_VERSION_MAJOR_LENGTH 0)
set(${type}_VERSION_MINOR_LENGTH 0)
set(${type}_PATCHLEVEL_LENGTH 0)
set(${type}_VERSION_TWEAK_LENGTH 0)

# Validate all version fields fit in a single byte
if(${type}_VERSION_MAJOR GREATER 255)
message(FATAL_ERROR "VERSION_MAJOR must be in the range 0-255 (Current ${${type}_VERSION_MAJOR})")
if(${type}_VERSION_MAJOR_LENGTH EQUAL 0 OR ${type}_VERSION_MAJOR GREATER 255)
Copy link
Contributor

@tejlmand tejlmand Nov 11, 2025

Choose a reason for hiding this comment

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

If field is not defined, then CMAKE_MATCH_1 will be empty and thus the <type>_VERSION_x is not defined.

So this should be sufficient:

Suggested change
if(${type}_VERSION_MAJOR_LENGTH EQUAL 0 OR ${type}_VERSION_MAJOR GREATER 255)
if(NOT DEFINED ${type}_VERSION_MAJOR OR ${type}_VERSION_MAJOR GREATER 255)

and avoid all the LENGTH handling above.

Comment applies to below code lines also.

Comment on lines +62 to +65
if(DEFINED ${type}_VERSION_MAJOR)
string(LENGTH ${${type}_VERSION_MAJOR} ${type}_VERSION_MAJOR_LENGTH)
endif()

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if(DEFINED ${type}_VERSION_MAJOR)
string(LENGTH ${${type}_VERSION_MAJOR} ${type}_VERSION_MAJOR_LENGTH)
endif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants