Skip to content

Commit ab43253

Browse files
committed
version.cmake: switch SOF_MAJOR etc. to a new, static versions.json
As discussed in #6952, relying on `git describe` for defining SOF_MAJOR and friends is very brittle and unreliable. Switch to a static versions.json file instead. Note the full `git describe --tags` output is _still_ present in the binary, this is useful and left unchanged. It's just not used any more to guess SOF_MAJOR, SOF_MINOR and SOF_MICRO. Use JSON because CMake and pretty much every other piece of software has a JSON parser out of the box. This aligns with linux/Makefile, Zephyr/VERSIONS and probably many others. - except we use JSON because we're in 2023 so we don't spend time having fun re-implementing parsers any more. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 9632135 commit ab43253

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

scripts/cmake/version.cmake

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22

33
# Generates header for which version is taken from (in order of precedence):
4-
# 1) .tarball-version file
5-
# 2) git
4+
# 1) .tarball-version file
5+
# 2) sof/versions.json
66
#
77
# Version is checked during configuration step and for every target
88
# that has check_version_h target as dependency
99

10-
cmake_minimum_required(VERSION 3.13)
10+
cmake_minimum_required(VERSION 3.19)
1111

1212
set(VERSION_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/version.cmake)
1313

@@ -74,12 +74,19 @@ endif()
7474

7575
message(STATUS "GIT_TAG / GIT_LOG_HASH : ${GIT_TAG} / ${GIT_LOG_HASH}")
7676

77-
string(REGEX MATCH "^v([0-9]+)[.]([0-9]+)([.]([0-9]+))?" ignored "${GIT_TAG}")
78-
set(SOF_MAJOR ${CMAKE_MATCH_1})
79-
set(SOF_MINOR ${CMAKE_MATCH_2})
80-
set(SOF_MICRO ${CMAKE_MATCH_4})
77+
file(READ "${SOF_ROOT_SOURCE_DIRECTORY}/versions.json" versions_json)
8178

82-
if(NOT SOF_MICRO MATCHES "^[0-9]+$")
79+
message(VERBOSE "${SOF_ROOT_SOURCE_DIRECTORY}/versions.json=${versions_json}")
80+
81+
string(JSON SOF_MAJOR GET "${versions_json}" SOF MAJOR)
82+
string(JSON SOF_MINOR GET "${versions_json}" SOF MINOR)
83+
string(JSON SOF_MICRO ERROR_VARIABLE micro_error
84+
GET "${versions_json}" SOF MICRO)
85+
86+
# Don't confuse "error not found" with "version not found"
87+
if(NOT "${micro_error}" STREQUAL "NOTFOUND")
88+
message(STATUS "versions.json: ${micro_error}, defaulting to 0")
89+
# TODO: default this to .99 on the main, never released branch like zephyr does
8390
set(SOF_MICRO 0)
8491
endif()
8592

versions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"SOF": {
3+
"MAJOR": "2",
4+
"MINOR": "5"
5+
}
6+
}

0 commit comments

Comments
 (0)