From eb8dc75d3808c93068df232ddb3afda704cc36bb Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sat, 25 Dec 2021 13:02:05 +0100 Subject: rbutil: Create git version information at build time. Change-Id: Iaf701f4d64d6852423f6a28a753b27abc43477e2 --- utils/CMakeLists.txt | 16 ++++++++++++ utils/cmake/gitversion.cmake | 58 +++++++++++++++++++++++++++++++++++++++++++ utils/rbutilqt/CMakeLists.txt | 2 +- utils/rbutilqt/version.h | 6 +++-- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 utils/cmake/gitversion.cmake (limited to 'utils') diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index cb0e683d75..55e2a60407 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -333,5 +333,21 @@ add_library(rbtomcrypt ) target_include_directories(rbtomcrypt PUBLIC ${CMAKE_CURRENT_LIST_DIR}/tomcrypt/src/headers) + +# target will always be build. File is only updated when contents change. +add_custom_target(gitversion.h + COMMENT "Updating gitversion.h" + COMMAND ${CMAKE_COMMAND} + -DOUTFILE=${CMAKE_CURRENT_BINARY_DIR}/gitversion/gitversion.h + -P ${CMAKE_CURRENT_LIST_DIR}/cmake/gitversion.cmake + BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gitversion/gitversion.h) + +# link to get git version header. +add_library(gitversion INTERFACE + ${CMAKE_CURRENT_BINARY_DIR}/gitversion/gitversion.h) + +add_dependencies(gitversion gitversion.h) +target_include_directories(gitversion INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/gitversion) + include(${CMAKE_CURRENT_LIST_DIR}/cmake/deploy.cmake) add_subdirectory(rbutilqt) diff --git a/utils/cmake/gitversion.cmake b/utils/cmake/gitversion.cmake new file mode 100644 index 0000000000..b13dfc0a0f --- /dev/null +++ b/utils/cmake/gitversion.cmake @@ -0,0 +1,58 @@ +# +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# +# All files in this archive are subject to the GNU General Public License. +# See the file COPYING in the source tree root for full license agreement. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# + +find_package(Git QUIET) + +execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --verify --short=10 HEAD + OUTPUT_VARIABLE GIT_HASH + ERROR_QUIET) + +# Check whether we got any revision (which isn't +# always the case, e.g. when someone downloaded a zip +# file from Github instead of a checkout) +if ("${GIT_HASH}" STREQUAL "") + set(GIT_HASH "N/A") +else() + execute_process( + COMMAND git diff --quiet --exit-code + RESULT_VARIABLE GIT_DIFF_EXITCODE) + + string(STRIP "${GIT_HASH}" GIT_HASH) + if (${GIT_DIFF_EXITCODE}) + set(GIT_DIFF "M") + endif() +endif() + +string(TIMESTAMP TODAY "%y%m%d") +set(VERSION " +#ifndef GITVERSION +#define GITVERSION \"${GIT_HASH}${GIT_DIFF}-${TODAY}\" +#define GITHASH \"${GIT_HASH}${GIT_DIFF}\" +#define BUILDDATE \"${TODAY}\" +#endif +") + +if(EXISTS ${OUTFILE}) + file(READ "${OUTFILE}" _version) +else() + set(_version "") +endif() + +if (NOT "${VERSION}" STREQUAL "${_version}") + file(WRITE "${OUTFILE}" "${VERSION}") +endif() + +message("-- Revision: ${GIT_HASH}${GIT_DIFF}") + diff --git a/utils/rbutilqt/CMakeLists.txt b/utils/rbutilqt/CMakeLists.txt index 138d0903cf..da453c3d11 100644 --- a/utils/rbutilqt/CMakeLists.txt +++ b/utils/rbutilqt/CMakeLists.txt @@ -122,7 +122,7 @@ if(APPLE) PROPERTIES MACOSX_PACKAGE_LOCATION Resources) endif() -target_link_libraries(RockboxUtility rbbase cutelogger +target_link_libraries(RockboxUtility rbbase cutelogger gitversion Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia) target_include_directories(RockboxUtility PRIVATE diff --git a/utils/rbutilqt/version.h b/utils/rbutilqt/version.h index b2d24d369b..1a1d78f643 100644 --- a/utils/rbutilqt/version.h +++ b/utils/rbutilqt/version.h @@ -18,6 +18,8 @@ * ****************************************************************************/ +#include "gitversion.h" + // PUREVERSION is needed to be able to just compare versions. It does not // contain a build timestamp because it needs to be the same in different // files @@ -38,7 +40,7 @@ #define VERSIONSTRING(a, b, c) STR(a) "." STR(b) "." STR(c) #define VERSION VERSIONSTRING(VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO) BUILDID // PUREVERSION should identify the build uniquely. Use version string for now. -#define PUREVERSION "$Rev$" +#define PUREVERSION GITHASH -#define FULLVERSION VERSION " (" PUREVERSION "), built " __DATE__ " " __TIME__ +#define FULLVERSION VERSION " (" GITHASH "), built " __DATE__ " " __TIME__ -- cgit v1.2.3