mirror of
https://github.com/SasaKaranovic/DIY-Filament-Dryer-v2.git
synced 2026-07-08 18:02:31 +02:00
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
# Sasa Karanovic's Simple script to make `version.h` file from current date-time and git commit
|
|
|
|
import datetime
|
|
import subprocess
|
|
|
|
def get_git_revision_hash() -> str:
|
|
return subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
|
|
|
|
def get_git_revision_short_hash() -> str:
|
|
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip()
|
|
|
|
def write_version_to_file(filepath, contents):
|
|
with open(filepath, "w", encoding="utf-8") as f:
|
|
f.write(contents)
|
|
|
|
def make_version_string():
|
|
now = datetime.datetime.now()
|
|
year = now.strftime('%Y')
|
|
month = now.strftime('%m')
|
|
day = now.strftime('%d')
|
|
git_long_hash = get_git_revision_hash()
|
|
git_short_hash = get_git_revision_short_hash()
|
|
|
|
version_header = \
|
|
f"""#ifndef __DIY_DRYBOX_V2_FW_VERSION_H_INC__
|
|
#define __DIY_DRYBOX_V2_FW_VERSION_H_INC__
|
|
|
|
#define VERSION_MAJOR "{year}"
|
|
#define VERSION_MINOR "{month}"
|
|
#define VERSION_PATCH "{day}"
|
|
#define GITH_LONG_HASH "{git_long_hash}"
|
|
#define GITH_SHORT_HASH "{git_short_hash}"
|
|
|
|
#endif
|
|
"""
|
|
|
|
print(f"New version {year}-{month}-{day}")
|
|
return version_header
|
|
|
|
def make_version():
|
|
print("--- Cutting version ---")
|
|
version = make_version_string()
|
|
write_version_to_file('src/version.h', version)
|
|
|
|
Import("env")
|
|
make_version()
|