FEATURE: Git revision code generator

This commit is contained in:
Robin Dietzel 2022-12-15 20:25:15 +01:00
parent 7af951766d
commit 68de383ca6
3 changed files with 42 additions and 0 deletions

View File

View File

@ -0,0 +1,30 @@
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

@ -0,0 +1,12 @@
//
// 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