Allow multiple patch directories per environment

This commit is contained in:
Thomas Basler 2024-01-07 00:47:05 +01:00
parent 2608080708
commit 6556268056
2 changed files with 270 additions and 264 deletions

View File

@ -9,7 +9,10 @@ import re
Import("env")
def getPatchPath(env):
return os.path.join(env["PROJECT_DIR"], "patches", env.GetProjectOption('custom_patches'))
patchList = []
for patch in env.GetProjectOption('custom_patches').split(","):
patchList.append(os.path.join(env["PROJECT_DIR"], "patches", patch))
return patchList
def is_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
@ -44,35 +47,36 @@ def main():
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
directories = getPatchPath(env)
for directory in directories:
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
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='')
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')
# 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()

View File

@ -59,6 +59,8 @@ board_build.embed_files =
webapp_dist/js/app.js.gz
webapp_dist/site.webmanifest
custom_patches =
monitor_filters = esp32_exception_decoder, time, log2file, colorize
monitor_speed = 115200
upload_protocol = esptool
@ -75,13 +77,13 @@ build_flags = ${env.build_flags}
[env:generic_esp32c3]
board = esp32-c3-devkitc-02
custom_patches = esp32c3
custom_patches = ${env.custom_patches},esp32c3
build_flags = ${env.build_flags}
[env:generic_esp32c3_usb]
board = esp32-c3-devkitc-02
custom_patches = esp32c3
custom_patches = ${env.custom_patches},esp32c3
build_flags = ${env.build_flags}
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1