From e04c8ee95ea9b5fe444b7a21c0d6557e815571e6 Mon Sep 17 00:00:00 2001 From: Stoian Minaiev Date: Fri, 14 May 2021 01:08:37 +0300 Subject: [PATCH] git: store git short ref hash on build stage to Version.h --- CMakeLists.txt | 12 ++++++++++++ src/Version.h.in | 2 ++ 2 files changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7770136..6c529f39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,10 +55,22 @@ if(BUILD_DFU) set(BUILD_DFU true) endif() +set(PROJECT_GIT_COMMIT_HASH "") + +execute_process(COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE PROJECT_GIT_COMMIT_HASH + RESULT_VARIABLE PROJECT_GIT_COMMIT_HASH_SUCCESS) + +string(STRIP ${PROJECT_GIT_COMMIT_HASH} PROJECT_GIT_COMMIT_HASH) + +message("PROJECT_GIT_COMMIT_HASH_SUCCESS? " ${PROJECT_GIT_COMMIT_HASH_SUCCESS}) + message("BUILD CONFIGURATION") message("-------------------") message(" * Version : " ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) message(" * Toolchain : " ${ARM_NONE_EABI_TOOLCHAIN_PATH}) +message(" * GitRef(S) : " ${PROJECT_GIT_COMMIT_HASH}) message(" * NRF52 SDK : " ${NRF5_SDK_PATH}) set(PROGRAMMER "???") if(USE_JLINK) diff --git a/src/Version.h.in b/src/Version.h.in index 6ff5938e..8cd39c96 100644 --- a/src/Version.h.in +++ b/src/Version.h.in @@ -8,11 +8,13 @@ namespace Pinetime { static constexpr uint32_t Major() {return major;} static constexpr uint32_t Minor() {return minor;} static constexpr uint32_t Patch() {return patch;} + static constexpr const char* GitCommitHash() {return commitHash;} static constexpr const char* VersionString() {return versionString;} private: static constexpr uint32_t major = @PROJECT_VERSION_MAJOR@; static constexpr uint32_t minor = @PROJECT_VERSION_MINOR@; static constexpr uint32_t patch = @PROJECT_VERSION_PATCH@; + static constexpr const char* commitHash = "@PROJECT_GIT_COMMIT_HASH@"; static constexpr const char* versionString = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"; }; } \ No newline at end of file