Added functionality to apply custom patch files during building
Usefull to patch existing libraries
This commit is contained in:
parent
f5fc52b92f
commit
12d03f06b0
13
patches/esp32c3/EspAsyncWebserver.patch
Normal file
13
patches/esp32c3/EspAsyncWebserver.patch
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
diff --git a/.pio/libdeps/$$$env$$$/ESP Async WebServer/src/AsyncWebSocket.cpp b/.pio/libdeps/$$$env$$$/ESP Async WebServer/src/AsyncWebSocket.cpp
|
||||||
|
index 12be5f8..8505f73 100644
|
||||||
|
--- a/.pio/libdeps/$$$env$$$/ESP Async WebServer/src/AsyncWebSocket.cpp
|
||||||
|
+++ b/.pio/libdeps/$$$env$$$/ESP Async WebServer/src/AsyncWebSocket.cpp
|
||||||
|
@@ -737,7 +737,7 @@ void AsyncWebSocketClient::binary(const __FlashStringHelper *data, size_t len)
|
||||||
|
IPAddress AsyncWebSocketClient::remoteIP() const
|
||||||
|
{
|
||||||
|
if (!_client)
|
||||||
|
- return IPAddress(0U);
|
||||||
|
+ return IPAddress((uint32_t)0);
|
||||||
|
|
||||||
|
return _client->remoteIP();
|
||||||
|
}
|
||||||
78
pio-scripts/patch_apply.py
Normal file
78
pio-scripts/patch_apply.py
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#
|
||||||
|
# Copyright (C) 2023 Thomas Basler and others
|
||||||
|
#
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import re
|
||||||
|
|
||||||
|
Import("env")
|
||||||
|
|
||||||
|
def getPatchPath(env):
|
||||||
|
return os.path.join(env["PROJECT_DIR"], "patches", env.GetProjectOption('custom_patches'))
|
||||||
|
|
||||||
|
def is_tool(name):
|
||||||
|
"""Check whether `name` is on PATH and marked as executable."""
|
||||||
|
|
||||||
|
# from whichcraft import which
|
||||||
|
from shutil import which
|
||||||
|
|
||||||
|
return which(name) is not None
|
||||||
|
|
||||||
|
def replaceInFile(in_file, out_file, text, subs, flags=0):
|
||||||
|
"""
|
||||||
|
Function for replacing content for the given file
|
||||||
|
Taken from https://www.studytonight.com/python-howtos/search-and-replace-a-text-in-a-file-in-python
|
||||||
|
"""
|
||||||
|
if os.path.exists(in_file):
|
||||||
|
with open(in_file, "rb") as infile:
|
||||||
|
with open(out_file, "wb") as outfile:
|
||||||
|
#read the file contents
|
||||||
|
file_contents = infile.read()
|
||||||
|
text_pattern = re.compile(re.escape(text), flags)
|
||||||
|
file_contents = text_pattern.sub(subs, file_contents.decode('utf-8'))
|
||||||
|
outfile.seek(0)
|
||||||
|
outfile.truncate()
|
||||||
|
outfile.write(file_contents.encode())
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if (env.GetProjectOption('custom_patches', '') == ''):
|
||||||
|
print('No custom_patches specified')
|
||||||
|
return
|
||||||
|
|
||||||
|
if (not is_tool('git')):
|
||||||
|
print('Git not found. Will not apply custom patches!')
|
||||||
|
return
|
||||||
|
|
||||||
|
directory = getPatchPath(env)
|
||||||
|
if (not os.path.isdir(directory)):
|
||||||
|
print('Patch directory not found: ' + directory)
|
||||||
|
return
|
||||||
|
|
||||||
|
for file in os.listdir(directory):
|
||||||
|
if (not file.endswith('.patch')):
|
||||||
|
continue
|
||||||
|
|
||||||
|
fullPath = os.path.join(directory, file)
|
||||||
|
preparePath = fullPath + '.prepare'
|
||||||
|
replaceInFile(fullPath, preparePath, '$$$env$$$', env['PIOENV'])
|
||||||
|
print('Working on patch: ' + fullPath + '... ', end='')
|
||||||
|
|
||||||
|
# Check if patch was already applied
|
||||||
|
process = subprocess.run(['git', 'apply', '--reverse', '--check', preparePath], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
if (process.returncode == 0):
|
||||||
|
print('already applied')
|
||||||
|
os.remove(preparePath)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Apply patch
|
||||||
|
process = subprocess.run(['git', 'apply', preparePath])
|
||||||
|
if (process.returncode == 0):
|
||||||
|
print('applied')
|
||||||
|
else:
|
||||||
|
print('failed')
|
||||||
|
|
||||||
|
os.remove(preparePath)
|
||||||
|
|
||||||
|
|
||||||
|
main()
|
||||||
@ -35,6 +35,7 @@ lib_deps =
|
|||||||
|
|
||||||
extra_scripts =
|
extra_scripts =
|
||||||
pre:pio-scripts/auto_firmware_version.py
|
pre:pio-scripts/auto_firmware_version.py
|
||||||
|
pre:pio-scripts/patch_apply.py
|
||||||
|
|
||||||
board_build.partitions = partitions_custom.csv
|
board_build.partitions = partitions_custom.csv
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
@ -58,6 +59,19 @@ build_flags = ${env.build_flags}
|
|||||||
-DHOYMILES_PIN_CS=5
|
-DHOYMILES_PIN_CS=5
|
||||||
|
|
||||||
|
|
||||||
|
[env:generic_esp32c3]
|
||||||
|
board = esp32dev
|
||||||
|
board_build.mcu = esp32c3
|
||||||
|
custom_patches = esp32c3
|
||||||
|
build_flags = ${env.build_flags}
|
||||||
|
-DHOYMILES_PIN_MISO=9
|
||||||
|
-DHOYMILES_PIN_MOSI=10
|
||||||
|
-DHOYMILES_PIN_SCLK=8
|
||||||
|
-DHOYMILES_PIN_IRQ=3
|
||||||
|
-DHOYMILES_PIN_CE=4
|
||||||
|
-DHOYMILES_PIN_CS=5
|
||||||
|
|
||||||
|
|
||||||
[env:olimex_esp32_poe]
|
[env:olimex_esp32_poe]
|
||||||
; https://www.olimex.com/Products/IoT/ESP32/ESP32-POE/open-source-hardware
|
; https://www.olimex.com/Products/IoT/ESP32/ESP32-POE/open-source-hardware
|
||||||
board = esp32-poe
|
board = esp32-poe
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user