From 20ca676e632eb0ee5a8dd0cb7cb8a9216852533f Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 6 May 2025 11:34:32 +0200 Subject: [PATCH] git version at startup --- common/CMakeLists.txt | 4 +++- common/git_version/CMakeLists.txt | 17 +++++++++++++++++ common/git_version/get_version.cmake | 3 +++ common/git_version/git_version.h.in | 4 ++++ mission/mission.c | 13 +++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 common/git_version/CMakeLists.txt create mode 100644 common/git_version/get_version.cmake create mode 100644 common/git_version/git_version.h.in diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ca7b46a..06a623e 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,2 +1,4 @@ # TODO directly referencing bsp is not correct -target_include_directories(bsp PUBLIC include) \ No newline at end of file +target_include_directories(bsp PUBLIC include) + +add_subdirectory(git_version) \ No newline at end of file diff --git a/common/git_version/CMakeLists.txt b/common/git_version/CMakeLists.txt new file mode 100644 index 0000000..4d5bee1 --- /dev/null +++ b/common/git_version/CMakeLists.txt @@ -0,0 +1,17 @@ +find_package(Git) +if(Git_FOUND) + message("Git found: ${GIT_EXECUTABLE}") + + add_custom_target( get_git_version + COMMAND ${CMAKE_COMMAND} + -D GIT_EXECUTABLE=${GIT_EXECUTABLE} + -D INPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/git_version.h.in + -D OUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/git_version.h + -P ${CMAKE_CURRENT_SOURCE_DIR}/get_version.cmake + ) + + add_dependencies(${OBSW_NAME} get_git_version) + target_include_directories(${OBSW_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +else() + message( FATAL_ERROR "Building outside of git is not supported yet") +endif() \ No newline at end of file diff --git a/common/git_version/get_version.cmake b/common/git_version/get_version.cmake new file mode 100644 index 0000000..f8e96db --- /dev/null +++ b/common/git_version/get_version.cmake @@ -0,0 +1,3 @@ +execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty OUTPUT_VARIABLE GIT_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE) +string(TIMESTAMP BUILD_TIME_STRING UTC) +configure_file(${INPUT_FILE} ${OUTPUT_FILE}) \ No newline at end of file diff --git a/common/git_version/git_version.h.in b/common/git_version/git_version.h.in new file mode 100644 index 0000000..f0dbf83 --- /dev/null +++ b/common/git_version/git_version.h.in @@ -0,0 +1,4 @@ +#pragma once + +#cmakedefine GIT_VERSION_STRING "@GIT_VERSION_STRING@" +#cmakedefine BUILD_TIME_STRING "@BUILD_TIME_STRING@" \ No newline at end of file diff --git a/mission/mission.c b/mission/mission.c index 2deb2f9..0354a2d 100644 --- a/mission/mission.c +++ b/mission/mission.c @@ -10,6 +10,8 @@ #include #include +#include + void rust_main(); @@ -41,12 +43,23 @@ void test_hardware() { // to be implemented by bsp (do not return from it!) void done(); + void init_task(void* _) { rust_main(_); } +#define STARTUP_MESSAGE1 "\nROMEO embedded obsw\nRelease: " +#define STARTUP_MESSAGE2 "\nBuild time: " + + void mission(void) { + write(1, STARTUP_MESSAGE1, strlen(STARTUP_MESSAGE1)); + write(1, GIT_VERSION_STRING, strlen(GIT_VERSION_STRING)); + write(1, STARTUP_MESSAGE2, strlen(STARTUP_MESSAGE2)); + write(1, BUILD_TIME_STRING, strlen(BUILD_TIME_STRING)); + write(1, "\n", 1); + test_hardware();