Adds versioning to the robot node
Implements an automatic versioning system for the robot node, utilizing a `version.txt` file and a Python script to increment the patch version. Integrates the version into the CMake build process to ensure the version is displayed in the robot node's output.
This commit is contained in:
parent
957f789faa
commit
b2761dd2db
5 changed files with 70 additions and 6 deletions
|
|
@ -1,7 +1,22 @@
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
# Defines the project name
|
# 1. Define the Version Bumper Target
|
||||||
project(Dixon)
|
# This target is like a "recipe" that isn't cooked until we ask for it.
|
||||||
|
add_custom_target(BumpVersion
|
||||||
|
COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/bump_version.py
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMENT "Bumping version in version.txt..."
|
||||||
|
)
|
||||||
|
|
||||||
|
# 2. Read the version for the Project metadata
|
||||||
|
# This still happens during "Reload" so CMake knows the project version.
|
||||||
|
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" RAW_VERSION)
|
||||||
|
string(STRIP "${RAW_VERSION}" DIXON_VERSION_FROM_FILE)
|
||||||
|
|
||||||
|
message(STATUS "Dixon Version detected from file: ${DIXON_VERSION_FROM_FILE}")
|
||||||
|
|
||||||
|
# Use that variable in your project definition
|
||||||
|
project(Dixon VERSION ${DIXON_VERSION_FROM_FILE} LANGUAGES CXX)
|
||||||
|
|
||||||
# Forces the compiler to use C++20 features
|
# Forces the compiler to use C++20 features
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
@ -16,9 +31,18 @@ add_executable(Dixon
|
||||||
CardioCenter/Heart.cpp
|
CardioCenter/Heart.cpp
|
||||||
CardioCenter/Heart.h)
|
CardioCenter/Heart.h)
|
||||||
|
|
||||||
# Header Path: Use the local v2.1 headers staged in the project
|
# 3. Create the Dependency
|
||||||
target_include_directories(Dixon PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/extern/libgpiod/include")
|
# This tells CMake: "Before you build Dixon, you MUST run BumpVersion."
|
||||||
|
add_dependencies(Dixon BumpVersion)
|
||||||
|
|
||||||
|
# Generate the header from the template
|
||||||
|
configure_file(Version.h.in "${CMAKE_CURRENT_BINARY_DIR}/Version.h")
|
||||||
|
|
||||||
|
# Consolidated Include Paths
|
||||||
|
target_include_directories(Dixon PRIVATE
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}" # For generated Version.h
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/extern/libgpiod/include" # For libgpiod headers
|
||||||
|
)
|
||||||
|
|
||||||
# Link the gpiod libraries
|
# Link the gpiod libraries
|
||||||
target_link_libraries(Dixon PRIVATE
|
target_link_libraries(Dixon PRIVATE
|
||||||
|
|
|
||||||
7
src/RobotNode/Version.h.in
Normal file
7
src/RobotNode/Version.h.in
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
#define VERSION_H
|
||||||
|
|
||||||
|
#define DIXON_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||||
|
#define DIXON_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||||
|
#define DIXON_VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||||
|
#define DIXON_VERSION "@PROJECT_VERSION@"
|
||||||
30
src/RobotNode/bump_version.py
Normal file
30
src/RobotNode/bump_version.py
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
def bump_version():
|
||||||
|
file_path = 'version.txt'
|
||||||
|
|
||||||
|
# Read the current version, default to 1.0.0 if file is missing
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
with open(file_path, 'r') as f:
|
||||||
|
version_str = f.read().strip()
|
||||||
|
else:
|
||||||
|
version_str = "1.0.0"
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Split 1.0.2 into [1, 0, 2]
|
||||||
|
parts = version_str.split('.')
|
||||||
|
major, minor, patch = map(int, parts)
|
||||||
|
|
||||||
|
# Increment the patch
|
||||||
|
new_version = f"{major}.{minor}.{patch + 1}"
|
||||||
|
|
||||||
|
# Write it back to the file
|
||||||
|
with open(file_path, 'w') as f:
|
||||||
|
f.write(new_version)
|
||||||
|
|
||||||
|
print(f"Version bumped to {new_version}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error bumping version: {e}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
bump_version()
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "DixonBrain.h"
|
#include "DixonBrain.h"
|
||||||
#include "DixonNodeState.h"
|
#include "DixonNodeState.h"
|
||||||
|
#include "Version.h" // The generated header
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Starting Dixon...\n";
|
// The "Splash Screen"
|
||||||
|
std::cout << "Starting Dixon v" << DIXON_VERSION << "...\n";
|
||||||
|
|
||||||
// Create the brain controller
|
// Create the brain controller
|
||||||
DixonBrain brain;
|
DixonBrain brain;
|
||||||
|
|
@ -20,4 +22,4 @@ int main()
|
||||||
|
|
||||||
std::cout << "Dixon shut down.\n";
|
std::cout << "Dixon shut down.\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
1
src/RobotNode/version.txt
Normal file
1
src/RobotNode/version.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
1.0.7
|
||||||
Loading…
Reference in a new issue