version: cmake: kconfig: introduce extra <type>_VERSION_<x>_STRING

Fixes: #68360

This commit introduces <type>_VERSION_TWEAK_STRING which includes
the tweak field in the string, but without the extra version.
This format is used by MCUboot / imgtool, and thus makes it easier to
align code to the format used by MCUboot.

This commit also introduces <type>_VERSION_EXTENDED_STRING which
includes the tweak field in the string in addition to the extra version
field.

The new defines / variables is available in code, CMake, and Kconfig,
and it defined for KERNEL, APP, and custom types, such as MCUBOOT.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2024-01-26 12:19:29 +01:00 committed by Fabio Baltieri
parent 738999e191
commit a306397818
4 changed files with 123 additions and 83 deletions

View file

@ -133,6 +133,8 @@ set(COMMON_KCONFIG_ENV_SETTINGS
srctree=${ZEPHYR_BASE}
KERNELVERSION=${KERNELVERSION}
APPVERSION=${APP_VERSION_STRING}
APP_VERSION_EXTENDED_STRING=${APP_VERSION_EXTENDED_STRING}
APP_VERSION_TWEAK_STRING=${APP_VERSION_TWEAK_STRING}
CONFIG_=${KCONFIG_NAMESPACE}_
KCONFIG_CONFIG=${DOTCONFIG}
# Set environment variables so that Kconfig can prune Kconfig source

View file

@ -13,6 +13,8 @@
#
# PROJECT_VERSION 1.14.99.07
# KERNEL_VERSION_STRING "1.14.99-extraver"
# KERNEL_VERSION_EXTENDED_STRING "1.14.99-extraver+7"
# KERNEL_VERSION_TWEAK_STRING "1.14.99+7"
#
# KERNEL_VERSION_MAJOR 1
# KERNEL_VERSION_MINOR 14
@ -60,9 +62,9 @@ foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE)
string(REGEX MATCH "EXTRAVERSION = ([a-z0-9]*)" _ ${ver})
set(${type}_VERSION_EXTRA ${CMAKE_MATCH_1})
# Temporary convenience variable
# Temporary convenience variables
set(${type}_VERSION_WITHOUT_TWEAK ${${type}_VERSION_MAJOR}.${${type}_VERSION_MINOR}.${${type}_PATCHLEVEL})
set(${type}_VERSION_WITH_TWEAK ${${type}_VERSION_MAJOR}.${${type}_VERSION_MINOR}.${${type}_PATCHLEVEL}+${${type}_VERSION_TWEAK})
set(MAJOR ${${type}_VERSION_MAJOR}) # Temporary convenience variable
set(MINOR ${${type}_VERSION_MINOR}) # Temporary convenience variable
@ -80,6 +82,8 @@ foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE)
else()
set(${type}_VERSION_STRING "${${type}_VERSION_WITHOUT_TWEAK}")
endif()
set(${type}_VERSION_TWEAK_STRING "${${type}_VERSION_WITH_TWEAK}")
set(${type}_VERSION_EXTENDED_STRING "${${type}_VERSION_STRING}+${${type}_VERSION_TWEAK}")
if(type STREQUAL KERNEL)
set(PROJECT_VERSION_MAJOR ${${type}_VERSION_MAJOR})
@ -116,5 +120,7 @@ foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE)
unset(MAJOR)
unset(MINOR)
unset(PATCH)
unset(TWEAK)
unset(${type}_VERSION_WITHOUT_TWEAK)
unset(${type}_VERSION_WITH_TWEAK)
endforeach()

View file

@ -73,87 +73,120 @@ To use the version information in application code, the version file must be inc
fields can be freely used. The include file name is :file:`app_version.h` (no path is needed), the
following defines are available:
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| Define | Type | Field(s) | Example |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APPVERSION | Numerical | ``VERSION_MAJOR`` (left shifted by 24 bits), |br| | 0x1020304 |
| | | ``VERSION_MINOR`` (left shifted by 16 bits), |br| | |
| | | ``PATCHLEVEL`` (left shifted by 8 bits), |br| | |
| | | ``VERSION_TWEAK`` | |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_VERSION_NUMBER | Numerical | ``VERSION_MAJOR`` (left shifted by 16 bits), |br| | 0x10203 |
| | | ``VERSION_MINOR`` (left shifted by 8 bits), |br| | |
| | | ``PATCHLEVEL`` | |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_VERSION_MAJOR | Numerical | ``VERSION_MAJOR`` | 1 |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_VERSION_MINOR | Numerical | ``VERSION_MINOR`` | 2 |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_PATCHLEVEL | Numerical | ``PATCHLEVEL`` | 3 |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_VERSION_TWEAK | Numerical | ``VERSION_TWEAK`` | 4 |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_VERSION_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3-unstable" |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``EXTRAVERSION`` |br| | |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_VERSION_EXTENDED_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3-unstable+4" |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``EXTRAVERSION`` |br| | |
| | | ``VERSION_TWEAK`` |br| | |
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_VERSION_TWEAK_STRING | String (quoted) | ``VERSION_MAJOR``, |br| | "1.2.3+4" |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``VERSION_TWEAK`` |br| | |
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
| APP_BUILD_VERSION | String (unquoted) | None (value of ``git describe --abbrev=12 --always`` | v3.3.0-18-g2c85d9224fca |
| | | from application repository) | |
+--------------------+-------------------+------------------------------------------------------+-------------------------+
+-----------------------------+-------------------+------------------------------------------------------+-------------------------+
Use in Kconfig
==============
The following variables are available for usage in Kconfig files:
+------------------+-----------+-------------------------+----------------+
+--------------------------------+-----------+--------------------------+------------------+
| Variable | Type | Field(s) | Example |
+------------------+-----------+-------------------------+----------------+
+--------------------------------+-----------+--------------------------+------------------+
| $(VERSION_MAJOR) | Numerical | ``VERSION_MAJOR`` | 1 |
+------------------+-----------+-------------------------+----------------+
+--------------------------------+-----------+--------------------------+------------------+
| $(VERSION_MINOR) | Numerical | ``VERSION_MINOR`` | 2 |
+------------------+-----------+-------------------------+----------------+
+--------------------------------+-----------+--------------------------+------------------+
| $(PATCHLEVEL) | Numerical | ``PATCHLEVEL`` | 3 |
+------------------+-----------+-------------------------+----------------+
+--------------------------------+-----------+--------------------------+------------------+
| $(VERSION_TWEAK) | Numerical | ``VERSION_TWEAK`` | 4 |
+------------------+-----------+-------------------------+----------------+
+--------------------------------+-----------+--------------------------+------------------+
| $(APPVERSION) | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``EXTRAVERSION`` | |
+------------------+-----------+-------------------------+----------------+
+--------------------------------+-----------+--------------------------+------------------+
| $(APP_VERSION_EXTENDED_STRING) | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable+4 |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``EXTRAVERSION``, |br| | |
| | | ``VERSION_TWEAK`` | |
+--------------------------------+-----------+--------------------------+------------------+
| $(APP_VERSION_TWEAK_STRING) | String | ``VERSION_MAJOR``, |br| | 1.2.3+4 |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``VERSION_TWEAK`` | |
+--------------------------------+-----------+--------------------------+------------------+
Use in CMake
============
The following variable are available for usage in CMake files:
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| Variable | Type | Field(s) | Example |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APPVERSION | Numerical (hex) | ``VERSION_MAJOR`` (left shifted by 24 bits), |br| | 0x1020304 |
| | | ``VERSION_MINOR`` (left shifted by 16 bits), |br| | |
| | | ``PATCHLEVEL`` (left shifted by 8 bits), |br| | |
| | | ``VERSION_TWEAK`` | |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_VERSION_NUMBER | Numerical (hex) | ``VERSION_MAJOR`` (left shifted by 16 bits), |br| | 0x10203 |
| | | ``VERSION_MINOR`` (left shifted by 8 bits), |br| | |
| | | ``PATCHLEVEL`` | |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_VERSION_MAJOR | Numerical | ``VERSION_MAJOR`` | 1 |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_VERSION_MINOR | Numerical | ``VERSION_MINOR`` | 2 |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_PATCHLEVEL | Numerical | ``PATCHLEVEL`` | 3 |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_VERSION_TWEAK | Numerical | ``VERSION_TWEAK`` | 4 |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_VERSION_STRING | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``EXTRAVERSION`` | |
+--------------------+-----------------+---------------------------------------------------+----------------+
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_VERSION_EXTENDED_STRING | String | ``VERSION_MAJOR``, |br| | 1.2.3-unstable+4 |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``EXTRAVERSION``, |br| | |
| | | ``VERSION_TWEAK`` | |
+-----------------------------+-----------------+---------------------------------------------------+------------------+
| APP_VERSION_TWEAK_STRING | String | ``VERSION_MAJOR``, |br| | 1.2.3+4 |
| | | ``VERSION_MINOR``, |br| | |
| | | ``PATCHLEVEL``, |br| | |
| | | ``VERSION_TWEAK`` | |
+-----------------------------+-----------------+---------------------------------------------------+------------------+
Use in MCUboot-supported applications
=====================================
@ -161,6 +194,3 @@ Use in MCUboot-supported applications
No additional configuration needs to be done to the target application so long as it is configured
to support MCUboot and a signed image is generated, the version information will be automatically
included in the image data.
The format used for signing is ``VERSION_MAJOR`` . ``VERSION_MINOR`` . ``PATCHLEVEL``, the tweak
version field is not currently used.

View file

@ -16,6 +16,8 @@
#define @VERSION_TYPE@_PATCHLEVEL @@VERSION_TYPE@_PATCHLEVEL@
#define @VERSION_TYPE@_TWEAK @@VERSION_TYPE@_VERSION_TWEAK@
#define @VERSION_TYPE@_VERSION_STRING "@@VERSION_TYPE@_VERSION_STRING@"
#define @VERSION_TYPE@_VERSION_EXTENDED_STRING "@@VERSION_TYPE@_VERSION_EXTENDED_STRING@"
#define @VERSION_TYPE@_VERSION_TWEAK_STRING "@@VERSION_TYPE@_VERSION_TWEAK_STRING@"
#define @BUILD_VERSION_NAME@ @@BUILD_VERSION_NAME@@
@@VERSION_TYPE@_VERSION_CUSTOMIZATION@