diff --git a/Application/CLS b/Application/CLS index 5535393..7dc557c 160000 --- a/Application/CLS +++ b/Application/CLS @@ -1 +1 @@ -Subproject commit 5535393c231d2d85c06942ff17c2b93dc450adca +Subproject commit 7dc557c9a7fa8b96762f166cc34f43bd0652d57c diff --git a/Revision/CMakeLists.txt b/Revision/CMakeLists.txt new file mode 100644 index 0000000..fdee1b6 --- /dev/null +++ b/Revision/CMakeLists.txt @@ -0,0 +1,27 @@ +# Add your source files +set(SOURCES + +) + +# Add your header files +set(HEADERS + version_info.h +) + +# Generate the version_info.c file as a build step +add_custom_command( + OUTPUT version_info.c + COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/generate_version_info.py + DEPENDS generate_version_info.py + COMMENT "Generating version_info.c" +) + +# Add the generated file to the list of sources +list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/version_info.c) + +add_custom_target(generate_version_info DEPENDS version_info.c) + +# Add the target +add_library(Revision STATIC ${SOURCES} ${HEADERS}) +add_dependencies(Revision generate_version_info) +target_include_directories(Revision PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) \ No newline at end of file diff --git a/Revision/generate_version_info.py b/Revision/generate_version_info.py new file mode 100644 index 0000000..7d9a418 --- /dev/null +++ b/Revision/generate_version_info.py @@ -0,0 +1,42 @@ +import subprocess + +def get_git_info(): + try: + # Get the latest tag + latest_tag = subprocess.check_output(['git', 'describe', '--abbrev=0', '--tags']).decode().strip() + # Get the number of commits since the latest tag + commit_count = subprocess.check_output(['git', 'rev-list', f'{latest_tag}..HEAD', '--count']).decode().strip() + # Get the current branch + branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode().strip() + # Get the short hash of the latest commit + commit_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip() + + # Parse the version string + version_parts = latest_tag.split('.') + major, minor, patch = map(int, version_parts) + + return major, minor, patch, int(commit_count), branch, commit_hash + except Exception as e: + print(f"Error: {e}") + return None, None, None, None, None, None + +def generate_c_file(filename, version_info): + version_info_string = f"""\ +// This file is auto-generated by a Python script +// Do not modify manually + +#include "version_info.h" + +__attribute__((section(".version"))) const firmware_version_t VERSION_INFO = {{ {version_info[0]}, {version_info[1]}, {version_info[2]}, {version_info[3]}, "{version_info[4]}", "{version_info[5]}" }}; +""" + + with open(filename, 'w') as f: + f.write(version_info_string) + +if __name__ == "__main__": + version_info = get_git_info() + if version_info: + generate_c_file("version_info.c", version_info) + print("Version information has been written to version_info.c") + else: + print("Failed to retrieve Git information.") diff --git a/Revision/version_info.h b/Revision/version_info.h new file mode 100644 index 0000000..bd0cb47 --- /dev/null +++ b/Revision/version_info.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +typedef struct firmware_version { + uint8_t major; + uint8_t minor; + uint8_t patch; + uint8_t count; + char branch[50]; + char commit_hash[8]; +} firmware_version_t; + + +extern const firmware_version_t VERSION_INFO; \ No newline at end of file