diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index 9d7162f7d6..5b29ae4e5c 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -835,7 +835,7 @@ endfunction() # This section provides a function for revision checking. # Usage: -# board_check_revision(FORMAT +# board_check_revision(FORMAT # [EXACT] # [DEFAULT_REVISION ] # [HIGHEST_REVISION ] @@ -851,8 +851,9 @@ endfunction() # When `EXACT` is not specified, this function will set the Zephyr build system # variable `ACTIVE_BOARD_REVISION` with the selected revision. # -# FORMAT : Specify the revision format. +# FORMAT : Specify the revision format. # LETTER: Revision format is a single letter from A - Z. +# NUMBER: Revision format is a single integer number. # MAJOR.MINOR.PATCH: Revision format is three numbers, separated by `.`, # `x.y.z`. Trailing zeroes may be omitted on the # command line, which means: @@ -905,6 +906,8 @@ function(board_check_revision) if(DEFINED BOARD_REV_HIGHEST_REVISION) if(((BOARD_REV_FORMAT STREQUAL LETTER) AND (BOARD_REVISION STRGREATER BOARD_REV_HIGHEST_REVISION)) OR + ((BOARD_REV_FORMAT STREQUAL NUMBER) AND + (BOARD_REVISION GREATER BOARD_REV_HIGHEST_REVISION)) OR ((BOARD_REV_FORMAT MATCHES "^MAJOR\.MINOR\.PATCH$") AND (BOARD_REVISION VERSION_GREATER BOARD_REV_HIGHEST_REVISION)) ) @@ -916,6 +919,8 @@ function(board_check_revision) if(BOARD_REV_FORMAT STREQUAL LETTER) set(revision_regex "([A-Z])") + elseif(BOARD_REV_FORMAT STREQUAL NUMBER) + set(revision_regex "([0-9]+)") elseif(BOARD_REV_FORMAT MATCHES "^MAJOR\.MINOR\.PATCH$") set(revision_regex "((0|[1-9][0-9]*)(\.[0-9]+)(\.[0-9]+))") # We allow loose @ typing on command line. @@ -932,7 +937,7 @@ function(board_check_revision) endif() else() message(FATAL_ERROR "Invalid format specified for \ - `board_check_revision(FORMAT )`") + `board_check_revision(FORMAT )`") endif() if(NOT (BOARD_REVISION MATCHES "^${revision_regex}$")) @@ -971,6 +976,11 @@ function(board_check_revision) (${TEST_REVISION} STRGREATER "${ACTIVE_BOARD_REVISION}") ) set(ACTIVE_BOARD_REVISION ${TEST_REVISION}) + elseif((BOARD_REV_FORMAT STREQUAL NUMBER) AND + (${BOARD_REVISION} GREATER ${TEST_REVISION}) AND + (${TEST_REVISION} GREATER "${ACTIVE_BOARD_REVISION}") + ) + set(ACTIVE_BOARD_REVISION ${TEST_REVISION}) endif() endforeach() endif() diff --git a/doc/guides/porting/board_porting.rst b/doc/guides/porting/board_porting.rst index 751acf0168..cd6418764d 100644 --- a/doc/guides/porting/board_porting.rst +++ b/doc/guides/porting/board_porting.rst @@ -538,9 +538,10 @@ When the user builds for board ``plank@``: application for the board. Currently, ```` can be either a numeric ``MAJOR.MINOR.PATCH`` style -revision like ``1.5.0``, or single letter like ``A``, ``B``, etc. Zephyr -provides a CMake board extension function, ``board_check_revision()``, to make -it easy to match either style from :file:`revision.cmake`. +revision like ``1.5.0``, an integer number like ``1``, or single letter like +``A``, ``B``, etc. Zephyr provides a CMake board extension function, +``board_check_revision()``, to make it easy to match either style from +:file:`revision.cmake`. Valid board revisions may be specified as arguments to the ``board_check_revision()`` function, like: @@ -560,8 +561,8 @@ Valid board revisions may be specified as arguments to the The following sections describe how to support these styles of revision numbers. -Numeric revisions -================= +MAJOR.MINOR.PATCH revisions +=========================== Let's say you want to add support for revisions ``0.5.0``, ``1.0.0``, and ``1.5.0`` of the ``plank`` board with both Kconfig fragments and devicetree @@ -583,8 +584,8 @@ additional files in the board directory: Notice how the board files have changed periods (".") in the revision number to underscores ("_"). -Fuzzy numeric revision matching -=============================== +Fuzzy revision matching +----------------------- To support "fuzzy" ``MAJOR.MINOR.PATCH`` revision matching for the ``plank`` board, use the following code in :file:`revision.cmake`: @@ -614,8 +615,8 @@ You may use ``0.0.0`` as a minimum revision to build for by creating the file revision lower than ``0.5.0``, for example if the user builds for ``plank@0.1.0``. -Exact numeric revision matching -=============================== +Exact revision matching +----------------------- Alternatively, the ``EXACT`` keyword can be given to ``board_check_revision()`` in :file:`revision.cmake` to allow exact matches only, like this: @@ -655,12 +656,36 @@ And add the following to :file:`revision.cmake`: board_check_revision(FORMAT LETTER) +Number revision matching +======================== + +Let's say instead that you need to support revisions ``1``, ``2``, and ``3`` of +the ``plank`` board. Create the following additional files in the board +directory: + +.. code-block:: none + + boards//plank + ├── plank_1.conf + ├── plank_1.overlay + ├── plank_2.conf + ├── plank_2.overlay + ├── plank_3.conf + ├── plank_3.overlay + └── revision.cmake + +And add the following to :file:`revision.cmake`: + +.. code-block:: cmake + + board_check_revision(FORMAT NUMBER) + board_check_revision() details ============================== .. code-block:: cmake - board_check_revision(FORMAT + board_check_revision(FORMAT [EXACT] [DEFAULT_REVISION ] [HIGHEST_REVISION ] @@ -670,6 +695,7 @@ board_check_revision() details This function supports the following arguments: * ``FORMAT LETTER``: matches single letter revisions from ``A`` to ``Z`` only +* ``FORMAT NUMBER``: matches integer revisions * ``FORMAT MAJOR.MINOR.PATCH``: matches exactly three digits. The command line allows for loose typing, that is ``-DBOARD=@1`` and ``-DBOARD=@1.0`` will be handled as ``-DBOARD=@1.0.0``.