FEATURE: automatic git hash injection

This commit is contained in:
Robin Dietzel 2023-01-26 19:42:39 +01:00
parent 0f4cc472a8
commit 856913afe1
6 changed files with 25 additions and 64 deletions

View File

@ -19,14 +19,30 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
# custom options # custom options
execute_process( #execute_process(
COMMAND git log -1 --format=%h # COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} # WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
# OUTPUT_VARIABLE GIT_HASH
# OUTPUT_STRIP_TRAILING_WHITESPACE
#)
#
#add_definitions(-DGIT_HASH=${GIT_HASH})
set(GIT_HASH "undefined")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
OUTPUT_VARIABLE GIT_HASH OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
) ERROR_QUIET
)
endif()
message(STATUS "Burning in git hash: ${GIT_HASH}")
add_definitions("-DGIT_HASH=\"${GIT_HASH}\"")
add_definitions(-DGIT_HASH=${GIT_HASH})
#Uncomment for hardware floating point #Uncomment for hardware floating point
#add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING) #add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)

View File

@ -1,30 +0,0 @@
import os.path
import subprocess
from jinja2 import Environment, PackageLoader, select_autoescape
def shortgitrev() -> str:
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
def gengitrev():
env = Environment(
loader=PackageLoader("gen_git_rev"),
autoescape=select_autoescape()
)
template = env.get_template("git_revision.h")
stream = template.stream(hash=shortgitrev())
# Check if in Project root
print(os.path.abspath("Core/Inc"))
if(os.path.exists(os.path.abspath("Core/Inc"))):
print("Core/Inc dir found, generating file...")
with open(os.path.abspath("Core/Inc/git_rev.h"), 'w') as fp:
stream.dump(fp)
else:
print("ERROR: Run this script from the Project root!")
exit(-1)
if __name__ == "__main__":
gengitrev()

View File

@ -1,12 +0,0 @@
//
// Created by robtor on 15.12.22.
//
#ifndef FLOATPUMP_GIT_REVISION_TEMPLATE_H
#define FLOATPUMP_GIT_REVISION_TEMPLATE_H
// Auto generated header file containing the last git revision
#define GIT_HASH "{{ hash }}"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -1,12 +0,0 @@
//
// Created by robtor on 15.12.22.
//
#ifndef FLOATPUMP_GIT_REVISION_TEMPLATE_H
#define FLOATPUMP_GIT_REVISION_TEMPLATE_H
// Auto generated header file containing the last git revision
#define GIT_HASH "8f1aed9"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -9,7 +9,6 @@
#include "main.h" #include "main.h"
#include "LCD_I2C_Driver.h" #include "LCD_I2C_Driver.h"
#include "git_rev.h"
namespace floatpump { namespace floatpump {