Skip to content

Commit

Permalink
Embed current branch into building process
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Sep 25, 2024
1 parent 0847f02 commit 155735c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/__compiled_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@


extern const char *__COMPILED_GIT_HASH__;
extern const char *__COMPILED_GIT_BRANCH__;
// extern const char *__COMPILED_DATE_TIME_UTC_STR__;
13 changes: 13 additions & 0 deletions pio-scripts/auto_firmware_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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"))

Expand Down

0 comments on commit 155735c

Please sign in to comment.