From 155735c8286c52b874f6c6112b6e719f42c2fa21 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Wed, 25 Sep 2024 21:46:38 +0200 Subject: [PATCH] Embed current branch into building process --- include/__compiled_constants.h | 1 + pio-scripts/auto_firmware_version.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/__compiled_constants.h b/include/__compiled_constants.h index ac8991e..a00caf6 100644 --- a/include/__compiled_constants.h +++ b/include/__compiled_constants.h @@ -5,4 +5,5 @@ extern const char *__COMPILED_GIT_HASH__; +extern const char *__COMPILED_GIT_BRANCH__; // extern const char *__COMPILED_DATE_TIME_UTC_STR__; diff --git a/pio-scripts/auto_firmware_version.py b/pio-scripts/auto_firmware_version.py index 26e1bd6..c1fa977 100644 --- a/pio-scripts/auto_firmware_version.py +++ b/pio-scripts/auto_firmware_version.py @@ -36,9 +36,20 @@ def get_build_version(): return build_version +def get_build_branch(): + try: + branch_name = porcelain.active_branch('.').decode('utf-8') # '.' refers to the repository root dir + except Exception as err: + branch_name = "master" + print("Firmware Branch: " + branch_name) + return branch_name + + def get_firmware_specifier_build_flag(): build_version = get_build_version() build_flag = "-D AUTO_GIT_HASH=\\\"" + build_version + "\\\"" + build_branch = get_build_branch() + build_flag += " -D AUTO_GIT_BRANCH=\\\"" + branch_name + "\\\"" return (build_flag) @@ -64,6 +75,8 @@ def do_main(): if 1: # Add the description of the current git revision lines += 'const char *__COMPILED_GIT_HASH__ = "%s";\n' % (get_build_version()) + # ... and git branch + lines += 'const char *__COMPILED_GIT_BRANCH__ = "%s";\n' % (get_build_branch()) updateFileIfChanged(targetfile, bytes(lines, "utf-8"))