reworked build-Process
This commit is contained in:
@@ -1,8 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
|
|
||||||
revision = (
|
|
||||||
subprocess.check_output(["git", "rev-parse", "--short=10", "HEAD"])
|
|
||||||
.strip()
|
|
||||||
.decode("utf-8")
|
|
||||||
)
|
|
||||||
print("-DGIT_REV='\"%s\"'" % revision)
|
|
@@ -1,9 +1,87 @@
|
|||||||
Import("env") # pylint: disable=undefined-variable
|
# run_pre.py — PlatformIO pre-build script
|
||||||
env.Execute("\"$PYTHONEXE\" -m pip install jinja2")
|
import os
|
||||||
env.Replace(PROGNAME="firmware_pcb_1.%s.fw" % env.GetProjectOption("custom_pcb_revision"))
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
Import("env") # provided by PlatformIO
|
||||||
|
|
||||||
|
# ---- helper ----
|
||||||
|
def parse_ver(s: str):
|
||||||
|
"""
|
||||||
|
Accepts '1.04', '1.4', '1,04' etc. -> returns (major:int, minor:int, norm_str:'1.04')
|
||||||
|
"""
|
||||||
|
s = (s or "").strip().replace(",", ".")
|
||||||
|
if not s:
|
||||||
|
return 0, 0, "0.00"
|
||||||
|
parts = s.split(".")
|
||||||
|
try:
|
||||||
|
major = int(parts[0])
|
||||||
|
minor = int(parts[1]) if len(parts) > 1 else 0
|
||||||
|
except ValueError:
|
||||||
|
major, minor = 0, 0
|
||||||
|
norm_str = f"{major}.{minor:02d}"
|
||||||
|
return major, minor, norm_str
|
||||||
|
|
||||||
|
def read_text_file(p: Path):
|
||||||
|
try:
|
||||||
|
return p.read_text(encoding="utf-8").strip()
|
||||||
|
except Exception:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def git_short_hash():
|
||||||
|
try:
|
||||||
|
out = subprocess.check_output(
|
||||||
|
["git", "rev-parse", "--short", "HEAD"],
|
||||||
|
stderr=subprocess.DEVNULL
|
||||||
|
).decode("utf-8").strip()
|
||||||
|
return out or "nogit"
|
||||||
|
except Exception:
|
||||||
|
return "nogit"
|
||||||
|
|
||||||
|
# ---- ensure jinja present, like before ----
|
||||||
|
env.Execute("\"$PYTHONEXE\" -m pip install jinja2")
|
||||||
|
|
||||||
|
# ---- keep your other pre-steps ----
|
||||||
import struct2json
|
import struct2json
|
||||||
import dtcs
|
import dtcs
|
||||||
|
|
||||||
struct2json.struct2json()
|
struct2json.struct2json()
|
||||||
dtcs.build_dtcs()
|
dtcs.build_dtcs()
|
||||||
|
|
||||||
|
# ---- collect inputs ----
|
||||||
|
proj_dir = Path(env["PROJECT_DIR"])
|
||||||
|
|
||||||
|
# user options from platformio.ini
|
||||||
|
pcb_rev = env.GetProjectOption("custom_pcb_revision", default="")
|
||||||
|
fw_ver_opt = env.GetProjectOption("custom_firmware_version", default="") # new
|
||||||
|
|
||||||
|
# required flash version from data/version
|
||||||
|
req_file = proj_dir / "data" / "version"
|
||||||
|
req_ver_raw = read_text_file(req_file)
|
||||||
|
|
||||||
|
fw_major, fw_minor, fw_norm = parse_ver(fw_ver_opt)
|
||||||
|
req_major, req_minor, req_norm = parse_ver(req_ver_raw)
|
||||||
|
|
||||||
|
githash = git_short_hash()
|
||||||
|
|
||||||
|
# ---- export as preprocessor defines ----
|
||||||
|
# numeric defines
|
||||||
|
env.Append(CPPDEFINES=[
|
||||||
|
("FW_VERSION_MAJOR", fw_major),
|
||||||
|
("FW_VERSION_MINOR", fw_minor),
|
||||||
|
("REQ_FLASH_MAJOR", req_major),
|
||||||
|
("REQ_FLASH_MINOR", req_minor),
|
||||||
|
])
|
||||||
|
|
||||||
|
# useful string defines (if du sie im Code/Logging brauchst)
|
||||||
|
env.Append(CPPDEFINES=[
|
||||||
|
("FW_VERSION_STR", f"\"{fw_norm}\""),
|
||||||
|
("REQ_FLASH_STR", f"\"{req_norm}\""),
|
||||||
|
("GIT_REV", f"\"{githash}\""),
|
||||||
|
])
|
||||||
|
|
||||||
|
# ---- build artifact name ----
|
||||||
|
# bisher: firmware_pcb_1.<pcb>.fw
|
||||||
|
# jetzt: firmware_pcb_<pcb>_v<fw>_<git>.fw (gut identifizierbar)
|
||||||
|
pcb_part = f"{pcb_rev}".strip() or "X"
|
||||||
|
fname = f"firmware_pcb_{pcb_part}_v{fw_norm}_{githash}.fw"
|
||||||
|
env.Replace(PROGNAME=fname)
|
||||||
|
@@ -18,6 +18,31 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#ifndef FW_VERSION_MAJOR
|
||||||
|
#define FW_VERSION_MAJOR 0
|
||||||
|
#endif
|
||||||
|
#ifndef FW_VERSION_MINOR
|
||||||
|
#define FW_VERSION_MINOR 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef REQ_FLASH_MAJOR
|
||||||
|
#define REQ_FLASH_MAJOR 0
|
||||||
|
#endif
|
||||||
|
#ifndef REQ_FLASH_MINOR
|
||||||
|
#define REQ_FLASH_MINOR 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef GIT_REV
|
||||||
|
#define GIT_REV "nogit"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FW_VERSION_STR
|
||||||
|
#define FW_VERSION_STR "0.00"
|
||||||
|
#endif
|
||||||
|
#ifndef REQ_FLASH_STR
|
||||||
|
#define REQ_FLASH_STR "0.00"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct Globals_s
|
typedef struct Globals_s
|
||||||
{
|
{
|
||||||
tSystem_Status systemStatus = sysStat_Startup; /**< Current system status */
|
tSystem_Status systemStatus = sysStat_Startup; /**< Current system status */
|
||||||
@@ -47,9 +72,9 @@ typedef struct Constants_s
|
|||||||
} Constants_t;
|
} Constants_t;
|
||||||
|
|
||||||
const Constants_t constants PROGMEM = {
|
const Constants_t constants PROGMEM = {
|
||||||
1,4, // Firmware_Version
|
FW_VERSION_MAJOR, FW_VERSION_MINOR, // Firmware_Version
|
||||||
1,4, // Required Flash Version
|
REQ_FLASH_MAJOR, REQ_FLASH_MINOR, // Required Flash Version
|
||||||
GIT_REV // Git-Hash-String
|
QUOTE(GIT_REV) // Git-Hash-String
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -19,8 +19,9 @@ board = d1_mini
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|
||||||
|
custom_firmware_version = 1.04
|
||||||
|
|
||||||
build_flags =
|
build_flags =
|
||||||
!python codegen/git_rev_macro.py
|
|
||||||
-DWIFI_SSID_CLIENT=${wifi_cred.wifi_ssid_client}
|
-DWIFI_SSID_CLIENT=${wifi_cred.wifi_ssid_client}
|
||||||
-DWIFI_PASSWORD_CLIENT=${wifi_cred.wifi_password_client}
|
-DWIFI_PASSWORD_CLIENT=${wifi_cred.wifi_password_client}
|
||||||
-DADMIN_PASSWORD=${wifi_cred.admin_password}
|
-DADMIN_PASSWORD=${wifi_cred.admin_password}
|
||||||
|
Reference in New Issue
Block a user