From 14f2752d4d0515023f5f649067f0e774b80ad866 Mon Sep 17 00:00:00 2001 From: unlogisch04 <98281608+unlogisch04@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:57:33 +0200 Subject: [PATCH] feat: commit hash (#228) Co-authored-by: DevMiner Co-authored-by: nekomona --- platformio-tools.ini | 9 +++++++-- platformio.ini | 3 ++- scripts/get_git_commit.py | 19 +++++++++++++++++++ src/serial/serialcommands.cpp | 3 +++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 scripts/get_git_commit.py diff --git a/platformio-tools.ini b/platformio-tools.ini index e5a268caa..f3d1bb3d2 100644 --- a/platformio-tools.ini +++ b/platformio-tools.ini @@ -4,8 +4,13 @@ lib_deps= https://github.com/SlimeVR/base64_arduino.git monitor_speed = 115200 framework = arduino -build_flags = -O2 -std=gnu++17 -build_unflags = -Os -std=gnu++11 +build_flags = + !python scripts/get_git_commit.py + -O2 + -std=gnu++17 +build_unflags = + -Os + -std=gnu++11 [env:BOARD_SLIMEVR] platform = espressif8266 @ 4.2.0 diff --git a/platformio.ini b/platformio.ini index 6d4d67407..01e6fdd65 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,7 +21,8 @@ monitor_filters = colorize ;monitor_rts = 0 ;monitor_dtr = 0 framework = arduino -build_flags = +build_flags = + !python scripts/get_git_commit.py ;If you want to set hardcoded WiFi SSID and password, uncomment and edit the lines below ;To uncomment, only remove ";" and leave the two spaces in front of the tags ; '" - quotes are necessary! diff --git a/scripts/get_git_commit.py b/scripts/get_git_commit.py new file mode 100644 index 000000000..ba482183a --- /dev/null +++ b/scripts/get_git_commit.py @@ -0,0 +1,19 @@ +import subprocess +import os + +revision = "" + +env_rev = os.environ.get("GIT_REV") +if not env_rev is None and env_rev != "": + revision = env_rev +else: + try: + revision = ( + subprocess.check_output(["git", "rev-parse", "HEAD"]) + .strip() + .decode("utf-8") + ) + except Exception: + revision = "NOT_GIT" + +print(f"'-DGIT_REV=\"{revision}\"'") diff --git a/src/serial/serialcommands.cpp b/src/serial/serialcommands.cpp index ce2fbadb6..a85469502 100644 --- a/src/serial/serialcommands.cpp +++ b/src/serial/serialcommands.cpp @@ -153,6 +153,9 @@ namespace SerialCommands { if (parser->equalCmdParam(1, "INFO")) { printState(); + + // We don't want to print this on every timed state output + logger.info("Git commit: %s", GIT_REV); } if (parser->equalCmdParam(1, "CONFIG")) {