zephyr/cmake/git.cmake

33 lines
1.0 KiB
CMake
Raw Normal View History

# SPDX-License-Identifier: Apache-2.0
#.rst:
# git.cmake
# ---------
# If the user didn't already define BUILD_VERSION then try to initialize
# it with the output of "git describe". Warn but don't error if
# everything fails and leave BUILD_VERSION undefined.
#
# See also: independent and more static ``KERNEL_VERSION_*`` in
# ``version.cmake`` and ``kernel_version.h``
# https://cmake.org/cmake/help/latest/module/FindGit.html
find_package(Git QUIET)
if(NOT BUILD_VERSION AND GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --abbrev=12
WORKING_DIRECTORY ${ZEPHYR_BASE}
OUTPUT_VARIABLE BUILD_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE stderr
RESULT_VARIABLE return_code
)
if(return_code)
git.cmake: print BUILD_VERSION always, simplify and fix error message In an ideal world, good CIs make it very clear what exact git versions are getting built. However: - Zephyr is (re-)used in many projects and they cannot all be expected to have ideal CI. - CI with multiple git repos is complex (#34713) which makes the world an even less ideal place: much more chance for some git versions to be missing. - Many developers don't realize that Github and other CIs do not test pull/12345/head but the moving target pull/12345/merge instead. While not resolving pull/12345/merge completely (maybe another day), this commit provides at least evidence that pull/12345/head is NOT the commit tested. So the addition of the following line in the logs is a very small price to pay that can save enormous amounts of time when trying to understand some obscure build failures. -- BUILD_VERSION=zephyr-v2.5.0-2957-g6230b5bb66bc Note this obviously does not provide any git information when BUILD_VERSION is overriden but it does not hurt either in this case: knowing BUILD_VERSION was overriden is also useful. The "BUILD_VERSION is left undefined" message was just wrong in the (unlikely) case `git describe` printed something while also failing. Remove it; it's so much simpler to just print $BUILD_VERSION and give the direct, unfiltered information. Note this simplification is also a partial revert of 1b80f00f56fb66a which threw the entire git warnings "baby" with some obscure duplicate 1.13.0 "bathwater" that is not relevant any more and that I guess barely anyone noticed even at the time. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2021-05-05 06:43:51 +08:00
message(STATUS "git describe failed: ${stderr}")
elseif(NOT "${stderr}" STREQUAL "")
message(STATUS "git describe warned: ${stderr}")
endif()
git.cmake: print BUILD_VERSION always, simplify and fix error message In an ideal world, good CIs make it very clear what exact git versions are getting built. However: - Zephyr is (re-)used in many projects and they cannot all be expected to have ideal CI. - CI with multiple git repos is complex (#34713) which makes the world an even less ideal place: much more chance for some git versions to be missing. - Many developers don't realize that Github and other CIs do not test pull/12345/head but the moving target pull/12345/merge instead. While not resolving pull/12345/merge completely (maybe another day), this commit provides at least evidence that pull/12345/head is NOT the commit tested. So the addition of the following line in the logs is a very small price to pay that can save enormous amounts of time when trying to understand some obscure build failures. -- BUILD_VERSION=zephyr-v2.5.0-2957-g6230b5bb66bc Note this obviously does not provide any git information when BUILD_VERSION is overriden but it does not hurt either in this case: knowing BUILD_VERSION was overriden is also useful. The "BUILD_VERSION is left undefined" message was just wrong in the (unlikely) case `git describe` printed something while also failing. Remove it; it's so much simpler to just print $BUILD_VERSION and give the direct, unfiltered information. Note this simplification is also a partial revert of 1b80f00f56fb66a which threw the entire git warnings "baby" with some obscure duplicate 1.13.0 "bathwater" that is not relevant any more and that I guess barely anyone noticed even at the time. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2021-05-05 06:43:51 +08:00
message(STATUS "BUILD_VERSION=${BUILD_VERSION}")
endif()