FEATURE: Git revision code generator
This commit is contained in:
parent
7af951766d
commit
68de383ca6
0
Tools/floatpytools/__init__.py
Normal file
0
Tools/floatpytools/__init__.py
Normal file
30
Tools/floatpytools/gen_git_rev.py
Normal file
30
Tools/floatpytools/gen_git_rev.py
Normal 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()
|
12
Tools/floatpytools/templates/git_revision.h
Normal file
12
Tools/floatpytools/templates/git_revision.h
Normal 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
|
Loading…
Reference in New Issue
Block a user