From a22f71649aaa9f1618806f44868d598f2546b37b Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Fri, 31 May 2024 12:47:45 +0200 Subject: [PATCH] updated Buildscripts to have central Versioning --- Software/codegen/prepare_littlefs.py | 13 +++++++------ Software/codegen/run_pre.py | 23 +++++++++++++++++++++-- Software/include/globals.h | 4 ++-- Software/platformio.ini | 3 +++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Software/codegen/prepare_littlefs.py b/Software/codegen/prepare_littlefs.py index 25c71b9..7dc7142 100644 --- a/Software/codegen/prepare_littlefs.py +++ b/Software/codegen/prepare_littlefs.py @@ -1,7 +1,3 @@ -# SCRIPT TO GZIP CRITICAL FILES FOR ACCELERATED WEBSERVING -# see also https://community.platformio.org/t/question-esp32-compress-files-in-data-to-gzip-before-upload-possible-to-spiffs/6274/10 - - import glob import shutil import gzip @@ -167,10 +163,15 @@ def gzip_webfiles(source, target, env): shutil.rmtree(data_temp_dir_path) return - + def gzip_binffiles(source, target, env): + git_revision = popen('git rev-parse --short HEAD').read().strip() + custom_flash_version = env.GetProjectOption("custom_flash_version", "0.99") + + # Format the target file name + target_filename = f"filesystem_{custom_flash_version}_{git_revision}.fs" littlefsbin = target[0].get_abspath() - targetbin = os.path.join(os.path.dirname(littlefsbin), 'filesystem.fs') + targetbin = os.path.join(os.path.dirname(littlefsbin), target_filename) shutil.copyfile(littlefsbin, targetbin) gzip_file(targetbin, os.path.join(str(targetbin) + '.gz')) os.remove(targetbin) diff --git a/Software/codegen/run_pre.py b/Software/codegen/run_pre.py index bfa851e..070fa90 100644 --- a/Software/codegen/run_pre.py +++ b/Software/codegen/run_pre.py @@ -7,8 +7,27 @@ from os import popen git_revision = popen('git rev-parse --short HEAD').read().strip() -env.Replace(PROGNAME="firmware_%s.fw" % git_revision) -env.Append(CPPDEFINES=[('GIT_REV', '\\"{}\\"'.format(git_revision))]) +# Versionsnummern aus platformio.ini holen +custom_firmware_version = env.GetProjectOption("custom_firmware_version", "0.99") +custom_flash_version = env.GetProjectOption("custom_flash_version", "0.99") + +# Versionsnummern aufteilen in Major und Minor +fw_major, fw_minor = custom_firmware_version.split('.') +fl_major, fl_minor = custom_flash_version.split('.') + +# Version in Datei "version" im Ordner "data_src" überschreiben +with open('data_src/version', 'w') as version_file: + version_file.write(custom_flash_version) + +# Build-Flags setzen +env.Replace(PROGNAME="firmware_%s_%s.fw" % (custom_firmware_version, git_revision)) +env.Append(CPPDEFINES=[ + ('GIT_REV', '\\"{}\\"'.format(git_revision)), + ('FW_MAJOR', fw_major), + ('FW_MINOR', fw_minor), + ('FL_MAJOR', fl_major), + ('FL_MINOR', fl_minor) +]) struct2json.struct2json() dtcs.build_dtcs() \ No newline at end of file diff --git a/Software/include/globals.h b/Software/include/globals.h index 6ed85f2..8d25881 100644 --- a/Software/include/globals.h +++ b/Software/include/globals.h @@ -31,8 +31,8 @@ typedef struct Constants_s } Constants_t; const Constants_t constants PROGMEM = { - 1, 5, // Firmware_Version - 1, 5, // Required Flash Version + FW_MAJOR, FW_MINOR, // Firmware_Version + FL_MAJOR, FL_MINOR, // Required Flash Version GIT_REV // Git-Hash-String }; diff --git a/Software/platformio.ini b/Software/platformio.ini index f4890a3..f88f12a 100644 --- a/Software/platformio.ini +++ b/Software/platformio.ini @@ -17,6 +17,9 @@ platform = espressif8266 framework = arduino board = d1_mini +custom_firmware_version = 1.05 +custom_flash_version = 1.05 + upload_protocol = esptool upload_speed = 921600 ;upload_port = 10.0.1.48