Commit a3063978 authored by Torsten Rasmussen's avatar Torsten Rasmussen Committed by Fabio Baltieri
Browse files

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: default avatarTorsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: default avatarJamie McCrae <jamie.mccrae@nordicsemi.no>
parent 738999e1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+10 −4
Original line number Diff line number Diff line
@@ -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()
+102 −72
Original line number Diff line number Diff line
@@ -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.
+9 −7
Original line number Diff line number Diff line
@@ -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@