FEATURE: automatic git hash injection
This commit is contained in:
parent
0f4cc472a8
commit
856913afe1
@ -19,14 +19,30 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
# custom options
|
||||
execute_process(
|
||||
COMMAND git log -1 --format=%h
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
#execute_process(
|
||||
# COMMAND git log -1 --format=%h
|
||||
# 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_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
|
||||
#add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
|
||||
|
@ -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()
|
@ -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
|
@ -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
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "main.h"
|
||||
#include "LCD_I2C_Driver.h"
|
||||
#include "git_rev.h"
|
||||
|
||||
|
||||
namespace floatpump {
|
||||
|
Loading…
Reference in New Issue
Block a user