30 lines
872 B
Python
30 lines
872 B
Python
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() |