From e5498a36ba3fd31dec2dc3fc4969e5b745407a5c Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 10 Apr 2025 10:51:48 +0200 Subject: [PATCH] git commit and depth in version, android now allows upgrading --- CMakeLists.txt | 36 ++++++++++++++++++++++++++++++ android/app/AndroidManifest.xml.in | 4 ++-- src/main.cpp | 9 +++++++- src/version.hpp.in | 3 +++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c74048e..ef14779 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,42 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") endif() endif() +# TODO: move to cmake include (maybe function) +set(TOMATO_GIT_DEPTH 0) +set(TOMATO_GIT_COMMIT "UNK") + +find_package(Git QUIET) +if(NOT Git_FOUND) + find_program(GIT_EXECUTABLE NAMES git git.exe) + if(GIT_EXECUTABLE) + set(Git_FOUND TRUE) + message(STATUS "Found Git: ${GIT_EXECUTABLE}") + endif() +endif() + +if(Git_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_HEAD + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RES + ) + if (RES EQUAL 0) + set(TOMATO_GIT_COMMIT ${GIT_HEAD}) + endif() + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_DEPTH + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RES + ) + if (RES EQUAL 0) + set(TOMATO_GIT_DEPTH ${GIT_DEPTH}) + endif() +endif() + # cmake setup end add_subdirectory(./src) diff --git a/android/app/AndroidManifest.xml.in b/android/app/AndroidManifest.xml.in index fb564d6..5c16b95 100644 --- a/android/app/AndroidManifest.xml.in +++ b/android/app/AndroidManifest.xml.in @@ -4,8 +4,8 @@ --> diff --git a/src/main.cpp b/src/main.cpp index 19fa58f..7422389 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,14 @@ int main(int argc, char** argv) { runSysCheck(); - std::cout << "tomato " TOMATO_VERSION_STR "\n"; + std::cout << "tomato " TOMATO_VERSION_STR; + if (TOMATO_GIT_DEPTH != 0) { + std::cout << "-" << TOMATO_GIT_DEPTH; + } + if (std::string_view{TOMATO_GIT_COMMIT} != "UNK") { + std::cout << "+git." << TOMATO_GIT_COMMIT; + } + std::cout << "\n"; #ifdef TOMATO_BREAKPAD // TODO: maybe run before sys check? diff --git a/src/version.hpp.in b/src/version.hpp.in index 4b4ceb5..7f90f9b 100644 --- a/src/version.hpp.in +++ b/src/version.hpp.in @@ -4,5 +4,8 @@ #define TOMATO_VERSION_MINOR @tomato_VERSION_MINOR@ #define TOMATO_VERSION_PATCH @tomato_VERSION_PATCH@ +#define TOMATO_GIT_COMMIT "@TOMATO_GIT_COMMIT@" +#define TOMATO_GIT_DEPTH @TOMATO_GIT_DEPTH@ + #define TOMATO_VERSION_STR "@tomato_VERSION_MAJOR@.@tomato_VERSION_MINOR@.@tomato_VERSION_PATCH@"