Improve patching

This commit is contained in:
Mikhael Skvortsov 2025-03-28 11:19:50 +03:00
parent 9076a42206
commit 30043d5622
4 changed files with 100 additions and 17 deletions

View File

@ -136,26 +136,41 @@ for lb in env.GetLibBuilders():
############################# Libraries Patching #############################
env.Execute("$PYTHONEXE -m pip install patch")
env.Execute("$PYTHONEXE -m pip install patch pyyaml")
import pathlib
import glob
import os
import patch
import yaml
libsToPatch = {}
for entry in glob.glob("patches/*.patch"):
p = pathlib.Path(entry).stem
libsToPatch[p] = entry
patches = {}
config_path = os.path.join(env["PROJECT_DIR"], "patches/config.yaml")
with open(config_path, "r") as file:
y = yaml.safe_load(file)
for p in y["patches"]:
name = p["name"]
p.pop("name", None)
patches[name] = p
for lb in env.GetLibBuilders():
if lb.name in libsToPatch:
marker_path = os.path.join(pathlib.Path(lb.src_dir), ".patched")
if not os.path.exists(marker_path):
patch_path = libsToPatch[lb.name]
ps = patch.fromfile(patch_path)
if not ps.apply(0, lb.src_dir):
print(f"Failed to apply patch {patch_path}")
continue # XXX
print(f"Patched {lb.name}")
open(marker_path, "w").close()
if not lb.name in patches:
continue
p = patches[lb.name]
if "version" in p and not (lb.version == p["version"]):
print(f"Skipping {lb.name}.patch: version doesn't match")
continue
if "targets" in p and not (env.get("PIOENV") in p["targets"]):
print(f"Skipping {lb.name}.patch: target doesn't match")
continue
marker_path = os.path.join(lb.src_dir, ".patched")
if os.path.exists(marker_path):
print(f"Skipping {lb.name}.patch: already patched")
continue
patch_path = env["PROJECT_DIR"] + "/patches/" + lb.name + ".patch"
ps = patch.fromfile(patch_path)
if not ps.apply(0, lb.src_dir):
print(f"Failed to apply patch {patch_path}")
exit(1)
print(f"Patched {lb.name}")
open(marker_path, "w").close()

View File

@ -0,0 +1,34 @@
Fix compiler warning
diff --git a/OLEDDisplay.cpp b/OLEDDisplay.cpp
index dca2ad1..35eb456 100644
--- a/OLEDDisplay.cpp
+++ b/OLEDDisplay.cpp
@@ -941,15 +941,6 @@ size_t OLEDDisplay::write(uint8_t c) {
return 1;
}
-size_t OLEDDisplay::write(const char* str) {
- if (str == NULL) return 0;
- size_t length = strlen(str);
- for (size_t i = 0; i < length; i++) {
- write(str[i]);
- }
- return length;
-}
-
#ifdef __MBED__
int OLEDDisplay::_putc(int c) {
diff --git a/OLEDDisplay.h b/OLEDDisplay.h
index 23e6845..07cb9a2 100644
--- a/OLEDDisplay.h
+++ b/OLEDDisplay.h
@@ -330,7 +330,6 @@ class OLEDDisplay : public Stream {
// Implement needed function to be compatible with Print class
size_t write(uint8_t c);
- size_t write(const char* s);
// Implement needed function to be compatible with Stream class
#ifdef __MBED__

24
patches/INA3221.patch Normal file
View File

@ -0,0 +1,24 @@
Fix compiler warning
diff --git a/INA3221.h b/INA3221.h
index bf09c8e..3fc7ad7 100644
--- a/INA3221.h
+++ b/INA3221.h
@@ -109,7 +109,7 @@ class INA3221 {
uint16_t ch2_en : 1;
uint16_t ch1_en : 1;
uint16_t reset : 1;
- } __attribute__((packed)) conf_reg_t;
+ } __attribute__((packed, aligned(sizeof(uint16_t)))) conf_reg_t;
// Mask/Enable register
typedef struct {
@@ -129,7 +129,7 @@ class INA3221 {
uint16_t shunt_sum_en_ch2 : 1;
uint16_t shunt_sum_en_ch1 : 1;
uint16_t reserved : 1;
- } __attribute__((packed)) masken_reg_t;
+ } __attribute__((packed, aligned(sizeof(uint16_t)))) masken_reg_t;
// Arduino's I2C library
TwoWire *_i2c;

10
patches/config.yaml Normal file
View File

@ -0,0 +1,10 @@
patches:
- name: ESP8266 and ESP32 OLED driver for SSD1306 displays
- name: ETHClass2
- name: INA3221
- name: LovyanGFX
version: 1.1.16
# targets:
# - seeed-sensecap-indicator-tft
- name: NonBlockingRTTTL
- name: SdFat