Skip to content

Commit

Permalink
Log debug build info at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbez1 committed Jun 8, 2024
1 parent d00a0d8 commit f74511c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
28 changes: 28 additions & 0 deletions arduino/splitflap/buildscript_build_info_macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import platform
import subprocess
import time

Import("env")

def get_firmware_specifier_build_flag():
ret = subprocess.run(["git", "describe", "--always", "--abbrev=40", "--dirty", "--match=nevermatchanything"], stdout=subprocess.PIPE, text=True)
build_version = ret.stdout.strip()
build_flag = "-D BUILD_GIT_HASH=\\\"" + build_version + "\\\""
print ("Firmware Revision: " + build_version)
return (build_flag)

def get_build_date_flag():
today = time.strftime("%Y-%m-%d")
return "-D BUILD_DATE=\\\"" + today + "\\\""

def get_build_os_flag():
build_os = platform.system()
return "-D BUILD_OS=\\\"" + build_os + "\\\""

env.Append(
BUILD_FLAGS=[
get_firmware_specifier_build_flag(),
get_build_os_flag(),
get_build_date_flag(),
]
)
13 changes: 13 additions & 0 deletions arduino/splitflap/esp32/splitflap/debug_build_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Arduino.h"

#include "debug_build_info.h"

void logDebugBuildInfo(Logger& logger) {
char buf[200];
snprintf(buf, sizeof(buf), "build_git_hash: %s", BUILD_GIT_HASH);
logger.log(buf);
snprintf(buf, sizeof(buf), "build_date: %s", BUILD_DATE);
logger.log(buf);
snprintf(buf, sizeof(buf), "build_os: %s", BUILD_OS);
logger.log(buf);
}
5 changes: 5 additions & 0 deletions arduino/splitflap/esp32/splitflap/debug_build_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "../core/logger.h"

void logDebugBuildInfo(Logger& logger);
3 changes: 3 additions & 0 deletions arduino/splitflap/esp32/splitflap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "../core/configuration.h"
#include "../core/splitflap_task.h"
#include "debug_build_info.h"
#include "display_task.h"
#include "serial_task.h"

Expand Down Expand Up @@ -83,6 +84,8 @@ void setup() {
baseSupervisorTask.begin();
#endif

logDebugBuildInfo(serialTask);

// Delete the default Arduino loopTask to free up Core 1
vTaskDelete(NULL);
}
Expand Down
3 changes: 3 additions & 0 deletions arduino/splitflap/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ monitor_eol = LF
monitor_filters = esp32_exception_decoder
board_build.partitions = default_ffat.csv

extra_scripts =
pre:buildscript_build_info_macros.py

; This would be much cleaner if we didn't need to preserve Arduino IDE compatibility and the splitflap
; module driver could be pulled out to its own library and shared properly... Instead, we remove the
; .ino file (referred to as .ino.cpp during the build) and add additional source.
Expand Down

0 comments on commit f74511c

Please sign in to comment.